Skip to content

Commit cc449de

Browse files
(feat) dump csv annotations into chart metadata (#1095)
1 parent 39c893c commit cc449de

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

internal/rukpak/convert/registryv1.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,17 @@ func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace stri
101101
return nil, err
102102
}
103103

104-
plain, err := Convert(reg, installNamespace, watchNamespaces)
104+
return toChart(reg, installNamespace, watchNamespaces)
105+
}
106+
107+
func toChart(in RegistryV1, installNamespace string, watchNamespaces []string) (*chart.Chart, error) {
108+
plain, err := Convert(in, installNamespace, watchNamespaces)
105109
if err != nil {
106110
return nil, err
107111
}
108112

109113
chrt := &chart.Chart{Metadata: &chart.Metadata{}}
114+
chrt.Metadata.Annotations = in.CSV.GetAnnotations()
110115
for _, obj := range plain.Objects {
111116
jsonData, err := json.Marshal(obj)
112117
if err != nil {

internal/rukpak/convert/registryv1_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package convert
22

33
import (
4+
"fmt"
45
"testing"
56

67
. "github.com/onsi/ginkgo/v2"
@@ -16,6 +17,7 @@ import (
1617
"sigs.k8s.io/controller-runtime/pkg/client"
1718

1819
"github.com/operator-framework/api/pkg/operators/v1alpha1"
20+
"github.com/operator-framework/operator-registry/alpha/property"
1921
)
2022

2123
func TestRegistryV1Converter(t *testing.T) {
@@ -173,6 +175,9 @@ var _ = Describe("RegistryV1 Suite", func() {
173175
csv = v1alpha1.ClusterServiceVersion{
174176
ObjectMeta: metav1.ObjectMeta{
175177
Name: "testCSV",
178+
Annotations: map[string]string{
179+
"olm.properties": fmt.Sprintf("[{\"type\": %s, \"value\": \"%s\"}]", property.TypeConstraint, "value"),
180+
},
176181
},
177182
Spec: v1alpha1.ClusterServiceVersionSpec{
178183
InstallModes: []v1alpha1.InstallMode{{Type: v1alpha1.InstallModeTypeMultiNamespace, Supported: true}},
@@ -380,6 +385,22 @@ var _ = Describe("RegistryV1 Suite", func() {
380385
Expect(err).To(HaveOccurred())
381386
Expect(plainBundle).To(BeNil())
382387
})
388+
389+
It("should propagate csv annotations to chart metadata annotation", func() {
390+
By("creating a registry v1 bundle")
391+
watchNamespaces = []string{"testWatchNs1", "testWatchNs2"}
392+
unstructuredSvc := convertToUnstructured(svc)
393+
registryv1Bundle = RegistryV1{
394+
PackageName: "testPkg",
395+
CSV: csv,
396+
Others: []unstructured.Unstructured{unstructuredSvc},
397+
}
398+
399+
By("converting to helm")
400+
chrt, err := toChart(registryv1Bundle, installNamespace, watchNamespaces)
401+
Expect(err).NotTo(HaveOccurred())
402+
Expect(chrt.Metadata.Annotations["olm.properties"]).NotTo(BeNil())
403+
})
383404
})
384405

385406
Context("Should enforce limitations", func() {

0 commit comments

Comments
 (0)