@@ -45,7 +45,16 @@ func ChainedResourceGenerator(resourceGenerators ...ResourceGenerator) ResourceG
45
45
}
46
46
}
47
47
48
+ var BundleRBACResourceGenerator = ChainedResourceGenerator (
49
+ BundleServiceAccountGenerator ,
50
+ BundlePermissionsGenerator ,
51
+ BundleClusterPermissionsGenerator ,
52
+ )
53
+
48
54
func BundleDeploymentGenerator (rv1 * RegistryV1 , opts Options ) ([]client.Object , error ) {
55
+ if rv1 == nil {
56
+ return nil , fmt .Errorf ("bundle cannot be nil" )
57
+ }
49
58
objs := make ([]client.Object , 0 , len (rv1 .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs ))
50
59
for _ , depSpec := range rv1 .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs {
51
60
annotations := util .MergeMaps (rv1 .CSV .Annotations , depSpec .Spec .Template .Annotations )
@@ -68,13 +77,17 @@ func BundleDeploymentGenerator(rv1 *RegistryV1, opts Options) ([]client.Object,
68
77
}
69
78
70
79
func BundlePermissionsGenerator (rv1 * RegistryV1 , opts Options ) ([]client.Object , error ) {
71
- permissions := rv1 .CSV .Spec .InstallStrategy .StrategySpec .Permissions
80
+ if rv1 == nil {
81
+ return nil , fmt .Errorf ("bundle cannot be nil" )
82
+ }
72
83
73
84
// If we're in AllNamespaces mode permissions will be treated as clusterPermissions
74
85
if len (opts .TargetNamespaces ) == 1 && opts .TargetNamespaces [0 ] == "" {
75
86
return nil , nil
76
87
}
77
88
89
+ permissions := rv1 .CSV .Spec .InstallStrategy .StrategySpec .Permissions
90
+
78
91
objs := make ([]client.Object , 0 , 2 * len (opts .TargetNamespaces )* len (permissions ))
79
92
for _ , ns := range opts .TargetNamespaces {
80
93
for _ , permission := range permissions {
@@ -99,6 +112,9 @@ func BundlePermissionsGenerator(rv1 *RegistryV1, opts Options) ([]client.Object,
99
112
}
100
113
101
114
func BundleClusterPermissionsGenerator (rv1 * RegistryV1 , opts Options ) ([]client.Object , error ) {
115
+ if rv1 == nil {
116
+ return nil , fmt .Errorf ("bundle cannot be nil" )
117
+ }
102
118
clusterPermissions := rv1 .CSV .Spec .InstallStrategy .StrategySpec .ClusterPermissions
103
119
104
120
// If we're in AllNamespaces mode, promote the permissions to clusterPermissions
@@ -133,6 +149,9 @@ func BundleClusterPermissionsGenerator(rv1 *RegistryV1, opts Options) ([]client.
133
149
}
134
150
135
151
func BundleServiceAccountGenerator (rv1 * RegistryV1 , opts Options ) ([]client.Object , error ) {
152
+ if rv1 == nil {
153
+ return nil , fmt .Errorf ("bundle cannot be nil" )
154
+ }
136
155
allPermissions := append (
137
156
rv1 .CSV .Spec .InstallStrategy .StrategySpec .Permissions ,
138
157
rv1 .CSV .Spec .InstallStrategy .StrategySpec .ClusterPermissions ... ,
@@ -154,6 +173,9 @@ func BundleServiceAccountGenerator(rv1 *RegistryV1, opts Options) ([]client.Obje
154
173
}
155
174
156
175
func BundleCRDGenerator (rv1 * RegistryV1 , _ Options ) ([]client.Object , error ) {
176
+ if rv1 == nil {
177
+ return nil , fmt .Errorf ("bundle cannot be nil" )
178
+ }
157
179
objs := make ([]client.Object , 0 , len (rv1 .CRDs ))
158
180
for _ , crd := range rv1 .CRDs {
159
181
objs = append (objs , crd .DeepCopy ())
@@ -162,6 +184,9 @@ func BundleCRDGenerator(rv1 *RegistryV1, _ Options) ([]client.Object, error) {
162
184
}
163
185
164
186
func BundleAdditionalResourcesGenerator (rv1 * RegistryV1 , opts Options ) ([]client.Object , error ) {
187
+ if rv1 == nil {
188
+ return nil , fmt .Errorf ("bundle cannot be nil" )
189
+ }
165
190
objs := make ([]client.Object , 0 , len (rv1 .Others ))
166
191
for _ , res := range rv1 .Others {
167
192
supported , namespaced := registrybundle .IsSupported (res .GetKind ())
0 commit comments