@@ -13,6 +13,7 @@ import (
1313	appsv1 "k8s.io/api/apps/v1" 
1414	corev1 "k8s.io/api/core/v1" 
1515	rbacv1 "k8s.io/api/rbac/v1" 
16+ 	apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 
1617	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
1718	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 
1819	"k8s.io/apimachinery/pkg/runtime" 
@@ -32,6 +33,7 @@ import (
3233type  RegistryV1  struct  {
3334	PackageName  string 
3435	CSV          v1alpha1.ClusterServiceVersion 
36+ 	CRDs         []apiextensionsv1.CustomResourceDefinition 
3537	Others       []unstructured.Unstructured 
3638}
3739
@@ -45,7 +47,7 @@ func RegistryV1ToHelmChart(rv1 fs.FS, installNamespace string, watchNamespace st
4547		return  nil , err 
4648	}
4749
48- 	plain , err  :=  Convert (reg , installNamespace , []string {watchNamespace })
50+ 	plain , err  :=  PlainConverter . Convert (reg , installNamespace , []string {watchNamespace })
4951	if  err  !=  nil  {
5052		return  nil , err 
5153	}
@@ -121,6 +123,12 @@ func ParseFS(rv1 fs.FS) (RegistryV1, error) {
121123				}
122124				reg .CSV  =  csv 
123125				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 )
124132			default :
125133				reg .Others  =  append (reg .Others , * info .Object .(* unstructured.Unstructured ))
126134			}
@@ -222,15 +230,23 @@ func saNameOrDefault(saName string) string {
222230	return  saName 
223231}
224232
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+ 
226242	if  installNamespace  ==  ""  {
227- 		installNamespace  =  in .CSV .Annotations ["operatorframework.io/suggested-namespace" ]
243+ 		installNamespace  =  rv1 .CSV .Annotations ["operatorframework.io/suggested-namespace" ]
228244	}
229245	if  installNamespace  ==  ""  {
230- 		installNamespace  =  fmt .Sprintf ("%s-system" , in .PackageName )
246+ 		installNamespace  =  fmt .Sprintf ("%s-system" , rv1 .PackageName )
231247	}
232248	supportedInstallModes  :=  sets .New [string ]()
233- 	for  _ , im  :=  range  in .CSV .Spec .InstallModes  {
249+ 	for  _ , im  :=  range  rv1 .CSV .Spec .InstallModes  {
234250		if  im .Supported  {
235251			supportedInstallModes .Insert (string (im .Type ))
236252		}
@@ -247,18 +263,18 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
247263		return  nil , err 
248264	}
249265
250- 	if  len (in .CSV .Spec .APIServiceDefinitions .Owned ) >  0  {
266+ 	if  len (rv1 .CSV .Spec .APIServiceDefinitions .Owned ) >  0  {
251267		return  nil , fmt .Errorf ("apiServiceDefintions are not supported" )
252268	}
253269
254- 	if  len (in .CSV .Spec .WebhookDefinitions ) >  0  {
270+ 	if  len (rv1 .CSV .Spec .WebhookDefinitions ) >  0  {
255271		return  nil , fmt .Errorf ("webhookDefinitions are not supported" )
256272	}
257273
258274	deployments  :=  []appsv1.Deployment {}
259275	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 )
262278		annotations ["olm.targetNamespaces" ] =  strings .Join (targetNamespaces , "," )
263279		depSpec .Spec .Template .Annotations  =  annotations 
264280		deployments  =  append (deployments , appsv1.Deployment {
@@ -292,8 +308,8 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
292308	clusterRoles  :=  []rbacv1.ClusterRole {}
293309	clusterRoleBindings  :=  []rbacv1.ClusterRoleBinding {}
294310
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 
297313	allPermissions  :=  append (permissions , clusterPermissions ... )
298314
299315	// Create all the service accounts 
@@ -320,7 +336,7 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
320336	for  _ , ns  :=  range  targetNamespaces  {
321337		for  _ , permission  :=  range  permissions  {
322338			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 )
324340			if  err  !=  nil  {
325341				return  nil , err 
326342			}
@@ -331,7 +347,7 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
331347
332348	for  _ , permission  :=  range  clusterPermissions  {
333349		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 )
335351		if  err  !=  nil  {
336352			return  nil , err 
337353		}
@@ -362,7 +378,10 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
362378		obj  :=  obj 
363379		objs  =  append (objs , & obj )
364380	}
365- 	for  _ , obj  :=  range  in .Others  {
381+ 	for  _ , obj  :=  range  rv1 .CRDs  {
382+ 		objs  =  append (objs , & obj )
383+ 	}
384+ 	for  _ , obj  :=  range  rv1 .Others  {
366385		obj  :=  obj 
367386		supported , namespaced  :=  registrybundle .IsSupported (obj .GetKind ())
368387		if  ! supported  {
@@ -380,6 +399,10 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
380399	return  & Plain {Objects : objs }, nil 
381400}
382401
402+ var  PlainConverter  =  Converter {
403+ 	BundleValidator : RegistryV1BundleValidator ,
404+ }
405+ 
383406const  maxNameLength  =  63 
384407
385408func  generateName (base  string , o  interface {}) (string , error ) {
0 commit comments