@@ -247,57 +247,62 @@ func (a *Operator) areAPIServicesAvailable(csv *v1alpha1.ClusterServiceVersion)
247
247
return true , nil
248
248
}
249
249
250
- // getCABundle returns the CA associated with a deployment
251
- func (a * Operator ) getCABundle (csv * v1alpha1.ClusterServiceVersion ) ([]byte , error ) {
252
- for _ , desc := range csv .GetOwnedAPIServiceDescriptions () {
253
- apiServiceName := desc .GetName ()
254
- apiService , err := a .lister .APIRegistrationV1 ().APIServiceLister ().Get (apiServiceName )
250
+ // getAPIServiceCABundle returns the CA associated with an API service
251
+ func (a * Operator ) getAPIServiceCABundle (csv * v1alpha1.ClusterServiceVersion , desc * v1alpha1.APIServiceDescription ) ([]byte , error ) {
252
+ apiServiceName := desc .GetName ()
253
+ apiService , err := a .lister .APIRegistrationV1 ().APIServiceLister ().Get (apiServiceName )
254
+
255
+ if err != nil {
256
+ return nil , fmt .Errorf ("could not retrieve generated APIService: %v" , err )
257
+ }
258
+
259
+ if len (apiService .Spec .CABundle ) > 0 {
260
+ return apiService .Spec .CABundle , nil
261
+ }
262
+
263
+ return nil , fmt .Errorf ("Unable to find ca" )
264
+ }
265
+
266
+ // getWebhookCABundle returns the CA associated with a webhook
267
+ func (a * Operator ) getWebhookCABundle (csv * v1alpha1.ClusterServiceVersion , desc * v1alpha1.WebhookDescription ) ([]byte , error ) {
268
+ webhookLabels := ownerutil .OwnerLabel (csv , v1alpha1 .ClusterServiceVersionKind )
269
+ webhookLabels [install .WebhookDescKey ] = desc .GenerateName
270
+ webhookSelector := labels .SelectorFromSet (webhookLabels ).String ()
271
+
272
+ switch desc .Type {
273
+ case v1alpha1 .MutatingAdmissionWebhook :
274
+ existingWebhooks , err := a .opClient .KubernetesInterface ().AdmissionregistrationV1 ().MutatingWebhookConfigurations ().List (context .TODO (), metav1.ListOptions {LabelSelector : webhookSelector })
255
275
if err != nil {
256
- return nil , fmt .Errorf ("could not retrieve generated APIService: %v" , err )
257
- }
258
- if len (apiService .Spec .CABundle ) > 0 {
259
- return apiService .Spec .CABundle , nil
276
+ return nil , fmt .Errorf ("could not retrieve generated MutatingWebhookConfiguration: %v" , err )
260
277
}
261
- }
262
278
263
- for _ , desc := range csv .Spec .WebhookDefinitions {
264
- webhookLabels := ownerutil .OwnerLabel (csv , v1alpha1 .ClusterServiceVersionKind )
265
- webhookLabels [install .WebhookDescKey ] = desc .GenerateName
266
- webhookSelector := labels .SelectorFromSet (webhookLabels ).String ()
279
+ if len (existingWebhooks .Items ) > 0 {
280
+ return existingWebhooks .Items [0 ].Webhooks [0 ].ClientConfig .CABundle , nil
281
+ }
282
+ case v1alpha1 .ValidatingAdmissionWebhook :
283
+ existingWebhooks , err := a .opClient .KubernetesInterface ().AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().List (context .TODO (), metav1.ListOptions {LabelSelector : webhookSelector })
284
+ if err != nil {
285
+ return nil , fmt .Errorf ("could not retrieve generated ValidatingWebhookConfiguration: %v" , err )
286
+ }
267
287
268
- switch desc .Type {
269
- case v1alpha1 .MutatingAdmissionWebhook :
270
- existingWebhooks , err := a .opClient .KubernetesInterface ().AdmissionregistrationV1 ().MutatingWebhookConfigurations ().List (context .TODO (), metav1.ListOptions {LabelSelector : webhookSelector })
288
+ if len (existingWebhooks .Items ) > 0 {
289
+ return existingWebhooks .Items [0 ].Webhooks [0 ].ClientConfig .CABundle , nil
290
+ }
291
+ case v1alpha1 .ConversionWebhook :
292
+ for _ , conversionCRD := range desc .ConversionCRDs {
293
+ // check if CRD exists on cluster
294
+ crd , err := a .opClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), conversionCRD , metav1.GetOptions {})
271
295
if err != nil {
272
- return nil , fmt .Errorf ("could not retrieve generated MutatingWebhookConfiguration: %v" , err )
273
- }
274
-
275
- if len (existingWebhooks .Items ) > 0 {
276
- return existingWebhooks .Items [0 ].Webhooks [0 ].ClientConfig .CABundle , nil
296
+ continue
277
297
}
278
- case v1alpha1 .ValidatingAdmissionWebhook :
279
- existingWebhooks , err := a .opClient .KubernetesInterface ().AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().List (context .TODO (), metav1.ListOptions {LabelSelector : webhookSelector })
280
- if err != nil {
281
- return nil , fmt .Errorf ("could not retrieve generated ValidatingWebhookConfiguration: %v" , err )
298
+ if crd .Spec .Conversion == nil || crd .Spec .Conversion .Webhook == nil || crd .Spec .Conversion .Webhook .ClientConfig == nil && crd .Spec .Conversion .Webhook .ClientConfig .CABundle == nil {
299
+ continue
282
300
}
283
301
284
- if len (existingWebhooks .Items ) > 0 {
285
- return existingWebhooks .Items [0 ].Webhooks [0 ].ClientConfig .CABundle , nil
286
- }
287
- case v1alpha1 .ConversionWebhook :
288
- for _ , conversionCRD := range desc .ConversionCRDs {
289
- // check if CRD exists on cluster
290
- crd , err := a .opClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Get (context .TODO (), conversionCRD , metav1.GetOptions {})
291
- if err != nil {
292
- continue
293
- }
294
- if crd .Spec .Conversion == nil || crd .Spec .Conversion .Webhook == nil || crd .Spec .Conversion .Webhook .ClientConfig == nil && crd .Spec .Conversion .Webhook .ClientConfig .CABundle == nil {
295
- continue
296
- }
297
- return crd .Spec .Conversion .Webhook .ClientConfig .CABundle , nil
298
- }
302
+ return crd .Spec .Conversion .Webhook .ClientConfig .CABundle , nil
299
303
}
300
304
}
305
+
301
306
return nil , fmt .Errorf ("Unable to find ca" )
302
307
}
303
308
@@ -321,13 +326,13 @@ func (a *Operator) updateDeploymentSpecsWithApiServiceData(csv *v1alpha1.Cluster
321
326
depSpecs [sddSpec .Name ] = sddSpec .Spec
322
327
}
323
328
324
- caBundle , err := a .getCABundle (csv )
325
- if err != nil {
326
- return nil , fmt .Errorf ("could not retrieve caBundle: %v" , err )
327
- }
328
- caHash := certs .PEMSHA256 (caBundle )
329
-
330
329
for _ , desc := range csv .Spec .APIServiceDefinitions .Owned {
330
+ caBundle , err := a .getAPIServiceCABundle (csv , & desc )
331
+ if err != nil {
332
+ return nil , fmt .Errorf ("could not retrieve caBundle for owned APIServices %s: %v" , fmt .Sprintf ("%s.%s" , desc .Version , desc .Group ), err )
333
+ }
334
+ caHash := certs .PEMSHA256 (caBundle )
335
+
331
336
depSpec , ok := depSpecs [desc .DeploymentName ]
332
337
if ! ok {
333
338
return nil , fmt .Errorf ("StrategyDetailsDeployment missing deployment %s for owned APIServices %s" , desc .DeploymentName , fmt .Sprintf ("%s.%s" , desc .Version , desc .Group ))
@@ -349,6 +354,10 @@ func (a *Operator) updateDeploymentSpecsWithApiServiceData(csv *v1alpha1.Cluster
349
354
}
350
355
351
356
for _ , desc := range csv .Spec .WebhookDefinitions {
357
+ caBundle , err := a .getWebhookCABundle (csv , & desc )
358
+ if err != nil {
359
+ return nil , fmt .Errorf ("could not retrieve caBundle for WebhookDescription %s: %v" , desc .GenerateName , err )
360
+ }
352
361
caHash := certs .PEMSHA256 (caBundle )
353
362
354
363
depSpec , ok := depSpecs [desc .DeploymentName ]
0 commit comments