@@ -23,26 +23,7 @@ func ConvertModelBundleToAPIBundle(b model.Bundle) (*Bundle, error) {
23
23
24
24
csvJSON := b .CsvJSON
25
25
if csvJSON == "" && len (props .CSVMetadatas ) == 1 {
26
- var icons []v1alpha1.Icon
27
- if b .Package .Icon != nil {
28
- icons = []v1alpha1.Icon {{
29
- Data : base64 .StdEncoding .EncodeToString (b .Package .Icon .Data ),
30
- MediaType : b .Package .Icon .MediaType ,
31
- }}
32
- }
33
- csv := csvMetadataToCsv (props .CSVMetadatas [0 ])
34
- csv .Name = b .Name
35
- csv .Spec .Icon = icons
36
- csv .Spec .InstallStrategy = v1alpha1.NamedInstallStrategy {
37
- // This stub is required to avoid a panic in OLM's package server that results in
38
- // attemptint to write to a nil map.
39
- StrategyName : "deployment" ,
40
- }
41
- csv .Spec .Version = version.OperatorVersion {Version : b .Version }
42
- csv .Spec .RelatedImages = convertModelRelatedImagesToCSVRelatedImages (b .RelatedImages )
43
- if csv .Spec .Description == "" {
44
- csv .Spec .Description = b .Package .Description
45
- }
26
+ csv := newSyntheticCSV (b )
46
27
csvData , err := json .Marshal (csv )
47
28
if err != nil {
48
29
return nil , err
@@ -101,29 +82,74 @@ func parseProperties(in []property.Property) (*property.Properties, error) {
101
82
return props , nil
102
83
}
103
84
104
- func csvMetadataToCsv (m property.CSVMetadata ) v1alpha1.ClusterServiceVersion {
85
+ func newSyntheticCSV (b model.Bundle ) v1alpha1.ClusterServiceVersion {
86
+ pkg := b .Package
87
+ csvMetadata := b .PropertiesP .CSVMetadatas [0 ]
88
+
89
+ var icons []v1alpha1.Icon
90
+ if pkg .Icon != nil {
91
+ icons = []v1alpha1.Icon {{
92
+ Data : base64 .StdEncoding .EncodeToString (pkg .Icon .Data ),
93
+ MediaType : pkg .Icon .MediaType ,
94
+ }}
95
+ }
96
+
97
+ // Copy package-level metadata into CSV if fields are unset in CSV
98
+ if csvMetadata .DisplayName == "" {
99
+ csvMetadata .DisplayName = pkg .DisplayName
100
+ }
101
+ if _ , ok := csvMetadata .Annotations ["description" ]; ! ok {
102
+ csvMetadata .Annotations ["description" ] = pkg .ShortDescription
103
+ }
104
+ if csvMetadata .Description == "" {
105
+ csvMetadata .Description = pkg .Description
106
+ }
107
+ if csvMetadata .Provider .Name == "" && csvMetadata .Provider .URL == "" && pkg .Provider != nil {
108
+ csvMetadata .Provider = * pkg .Provider
109
+ }
110
+ if csvMetadata .Maintainers == nil {
111
+ csvMetadata .Maintainers = pkg .Maintainers
112
+ }
113
+ if csvMetadata .Links == nil {
114
+ csvMetadata .Links = pkg .Links
115
+ }
116
+ if csvMetadata .Keywords == nil {
117
+ csvMetadata .Keywords = pkg .Keywords
118
+ }
119
+
120
+ // Return syntheticly generated CSV
105
121
return v1alpha1.ClusterServiceVersion {
106
122
TypeMeta : metav1.TypeMeta {
107
123
Kind : operators .ClusterServiceVersionKind ,
108
124
APIVersion : v1alpha1 .ClusterServiceVersionAPIVersion ,
109
125
},
110
126
ObjectMeta : metav1.ObjectMeta {
111
- Annotations : m .Annotations ,
112
- Labels : m .Labels ,
127
+ Name : b .Name ,
128
+ Annotations : csvMetadata .Annotations ,
129
+ Labels : csvMetadata .Labels ,
113
130
},
114
131
Spec : v1alpha1.ClusterServiceVersionSpec {
115
- APIServiceDefinitions : m .APIServiceDefinitions ,
116
- CustomResourceDefinitions : m .CustomResourceDefinitions ,
117
- Description : m .Description ,
118
- DisplayName : m .DisplayName ,
119
- InstallModes : m .InstallModes ,
120
- Keywords : m .Keywords ,
121
- Links : m .Links ,
122
- Maintainers : m .Maintainers ,
123
- Maturity : m .Maturity ,
124
- MinKubeVersion : m .MinKubeVersion ,
125
- NativeAPIs : m .NativeAPIs ,
126
- Provider : m .Provider ,
132
+ APIServiceDefinitions : csvMetadata .APIServiceDefinitions ,
133
+ CustomResourceDefinitions : csvMetadata .CustomResourceDefinitions ,
134
+ Description : csvMetadata .Description ,
135
+ DisplayName : csvMetadata .DisplayName ,
136
+ InstallModes : csvMetadata .InstallModes ,
137
+ Keywords : csvMetadata .Keywords ,
138
+ Links : csvMetadata .Links ,
139
+ Maintainers : csvMetadata .Maintainers ,
140
+ Maturity : csvMetadata .Maturity ,
141
+ MinKubeVersion : csvMetadata .MinKubeVersion ,
142
+ NativeAPIs : csvMetadata .NativeAPIs ,
143
+ Provider : csvMetadata .Provider ,
144
+
145
+ Icon : icons ,
146
+ InstallStrategy : v1alpha1.NamedInstallStrategy {
147
+ // This stub is required to avoid a panic in OLM's package server that results in
148
+ // attemptint to write to a nil map.
149
+ StrategyName : "deployment" ,
150
+ },
151
+ Version : version.OperatorVersion {Version : b .Version },
152
+ RelatedImages : convertModelRelatedImagesToCSVRelatedImages (b .RelatedImages ),
127
153
},
128
154
}
129
155
}
0 commit comments