@@ -13,6 +13,7 @@ import (
13
13
appsv1 "k8s.io/api/apps/v1"
14
14
corev1 "k8s.io/api/core/v1"
15
15
rbacv1 "k8s.io/api/rbac/v1"
16
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
16
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
18
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
18
19
"k8s.io/apimachinery/pkg/runtime"
@@ -32,6 +33,7 @@ import (
32
33
type RegistryV1 struct {
33
34
PackageName string
34
35
CSV v1alpha1.ClusterServiceVersion
36
+ CRDs []apiextensionsv1.CustomResourceDefinition
35
37
Others []unstructured.Unstructured
36
38
}
37
39
@@ -45,7 +47,7 @@ func RegistryV1ToHelmChart(rv1 fs.FS, installNamespace string, watchNamespace st
45
47
return nil , err
46
48
}
47
49
48
- plain , err := Convert (reg , installNamespace , []string {watchNamespace })
50
+ plain , err := PlainConverter . Convert (reg , installNamespace , []string {watchNamespace })
49
51
if err != nil {
50
52
return nil , err
51
53
}
@@ -121,6 +123,12 @@ func ParseFS(rv1 fs.FS) (RegistryV1, error) {
121
123
}
122
124
reg .CSV = csv
123
125
foundCSV = true
126
+ case "CustomResourceDefinition" :
127
+ crd := apiextensionsv1.CustomResourceDefinition {}
128
+ if err := runtime .DefaultUnstructuredConverter .FromUnstructured (info .Object .(* unstructured.Unstructured ).Object , & crd ); err != nil {
129
+ return err
130
+ }
131
+ reg .CRDs = append (reg .CRDs , crd )
124
132
default :
125
133
reg .Others = append (reg .Others , * info .Object .(* unstructured.Unstructured ))
126
134
}
@@ -222,15 +230,23 @@ func saNameOrDefault(saName string) string {
222
230
return saName
223
231
}
224
232
225
- func Convert (in RegistryV1 , installNamespace string , targetNamespaces []string ) (* Plain , error ) {
233
+ type Converter struct {
234
+ BundleValidator BundleValidator
235
+ }
236
+
237
+ func (c Converter ) Convert (rv1 RegistryV1 , installNamespace string , targetNamespaces []string ) (* Plain , error ) {
238
+ if err := c .BundleValidator .Validate (& rv1 ); err != nil {
239
+ return nil , err
240
+ }
241
+
226
242
if installNamespace == "" {
227
- installNamespace = in .CSV .Annotations ["operatorframework.io/suggested-namespace" ]
243
+ installNamespace = rv1 .CSV .Annotations ["operatorframework.io/suggested-namespace" ]
228
244
}
229
245
if installNamespace == "" {
230
- installNamespace = fmt .Sprintf ("%s-system" , in .PackageName )
246
+ installNamespace = fmt .Sprintf ("%s-system" , rv1 .PackageName )
231
247
}
232
248
supportedInstallModes := sets .New [string ]()
233
- for _ , im := range in .CSV .Spec .InstallModes {
249
+ for _ , im := range rv1 .CSV .Spec .InstallModes {
234
250
if im .Supported {
235
251
supportedInstallModes .Insert (string (im .Type ))
236
252
}
@@ -247,18 +263,18 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
247
263
return nil , err
248
264
}
249
265
250
- if len (in .CSV .Spec .APIServiceDefinitions .Owned ) > 0 {
266
+ if len (rv1 .CSV .Spec .APIServiceDefinitions .Owned ) > 0 {
251
267
return nil , fmt .Errorf ("apiServiceDefintions are not supported" )
252
268
}
253
269
254
- if len (in .CSV .Spec .WebhookDefinitions ) > 0 {
270
+ if len (rv1 .CSV .Spec .WebhookDefinitions ) > 0 {
255
271
return nil , fmt .Errorf ("webhookDefinitions are not supported" )
256
272
}
257
273
258
274
deployments := []appsv1.Deployment {}
259
275
serviceAccounts := map [string ]corev1.ServiceAccount {}
260
- for _ , depSpec := range in .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs {
261
- annotations := util .MergeMaps (in .CSV .Annotations , depSpec .Spec .Template .Annotations )
276
+ for _ , depSpec := range rv1 .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs {
277
+ annotations := util .MergeMaps (rv1 .CSV .Annotations , depSpec .Spec .Template .Annotations )
262
278
annotations ["olm.targetNamespaces" ] = strings .Join (targetNamespaces , "," )
263
279
depSpec .Spec .Template .Annotations = annotations
264
280
deployments = append (deployments , appsv1.Deployment {
@@ -292,8 +308,8 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
292
308
clusterRoles := []rbacv1.ClusterRole {}
293
309
clusterRoleBindings := []rbacv1.ClusterRoleBinding {}
294
310
295
- permissions := in .CSV .Spec .InstallStrategy .StrategySpec .Permissions
296
- clusterPermissions := in .CSV .Spec .InstallStrategy .StrategySpec .ClusterPermissions
311
+ permissions := rv1 .CSV .Spec .InstallStrategy .StrategySpec .Permissions
312
+ clusterPermissions := rv1 .CSV .Spec .InstallStrategy .StrategySpec .ClusterPermissions
297
313
allPermissions := append (permissions , clusterPermissions ... )
298
314
299
315
// Create all the service accounts
@@ -320,7 +336,7 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
320
336
for _ , ns := range targetNamespaces {
321
337
for _ , permission := range permissions {
322
338
saName := saNameOrDefault (permission .ServiceAccountName )
323
- name , err := generateName (fmt .Sprintf ("%s-%s" , in .CSV .Name , saName ), permission )
339
+ name , err := generateName (fmt .Sprintf ("%s-%s" , rv1 .CSV .Name , saName ), permission )
324
340
if err != nil {
325
341
return nil , err
326
342
}
@@ -331,7 +347,7 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
331
347
332
348
for _ , permission := range clusterPermissions {
333
349
saName := saNameOrDefault (permission .ServiceAccountName )
334
- name , err := generateName (fmt .Sprintf ("%s-%s" , in .CSV .Name , saName ), permission )
350
+ name , err := generateName (fmt .Sprintf ("%s-%s" , rv1 .CSV .Name , saName ), permission )
335
351
if err != nil {
336
352
return nil , err
337
353
}
@@ -362,7 +378,10 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
362
378
obj := obj
363
379
objs = append (objs , & obj )
364
380
}
365
- for _ , obj := range in .Others {
381
+ for _ , obj := range rv1 .CRDs {
382
+ objs = append (objs , & obj )
383
+ }
384
+ for _ , obj := range rv1 .Others {
366
385
obj := obj
367
386
supported , namespaced := registrybundle .IsSupported (obj .GetKind ())
368
387
if ! supported {
@@ -380,6 +399,10 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
380
399
return & Plain {Objects : objs }, nil
381
400
}
382
401
402
+ var PlainConverter = Converter {
403
+ BundleValidator : RegistryV1BundleValidator ,
404
+ }
405
+
383
406
const maxNameLength = 63
384
407
385
408
func generateName (base string , o interface {}) (string , error ) {
0 commit comments