@@ -26,7 +26,7 @@ const (
26
26
webhookName = "webhook.test.com"
27
27
)
28
28
29
- var _ = Describe ("CSVs with a Webhook" , func () {
29
+ var _ = FDescribe ("CSVs with a Webhook" , func () {
30
30
var c operatorclient.ClientInterface
31
31
var crc versioned.Interface
32
32
var namespace * corev1.Namespace
@@ -97,7 +97,7 @@ var _ = Describe("CSVs with a Webhook", func() {
97
97
_ , err = fetchCSV (GinkgoT (), crc , csv .Name , namespace .Name , csvSucceededChecker )
98
98
Expect (err ).Should (BeNil ())
99
99
100
- actualWebhook , err := getWebhookWithGenName (c , webhook )
100
+ actualWebhook , err := getWebhookWithGenerateName (c , webhook . GenerateName )
101
101
Expect (err ).Should (BeNil ())
102
102
103
103
Expect (actualWebhook .Webhooks [0 ].NamespaceSelector ).Should (Equal (ogSelector ))
@@ -136,7 +136,7 @@ var _ = Describe("CSVs with a Webhook", func() {
136
136
_ , err = fetchCSV (GinkgoT (), crc , csv .Name , namespace .Name , csvSucceededChecker )
137
137
Expect (err ).Should (BeNil ())
138
138
139
- actualWebhook , err := getWebhookWithGenName (c , webhook )
139
+ actualWebhook , err := getWebhookWithGenerateName (c , webhook . GenerateName )
140
140
Expect (err ).Should (BeNil ())
141
141
142
142
ogLabel , err := getOGLabelKey (og )
@@ -147,6 +147,34 @@ var _ = Describe("CSVs with a Webhook", func() {
147
147
MatchExpressions : []metav1.LabelSelectorRequirement (nil ),
148
148
}
149
149
Expect (actualWebhook .Webhooks [0 ].NamespaceSelector ).Should (Equal (expected ))
150
+
151
+ // Ensure that changes to the WebhookDescription within the CSV trigger an update to on cluster resources
152
+ changedGenerateName := webhookName + "-changed"
153
+ Eventually (func () error {
154
+ existingCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (namespace .Name ).Get (context .TODO (), csv .GetName (), metav1.GetOptions {})
155
+ if err != nil {
156
+ return err
157
+ }
158
+ existingCSV .Spec .WebhookDefinitions [0 ].GenerateName = changedGenerateName
159
+
160
+ existingCSV , err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (namespace .Name ).Update (context .TODO (), existingCSV , metav1.UpdateOptions {})
161
+ return err
162
+ }, time .Minute , 5 * time .Second ).Should (Succeed ())
163
+ Eventually (func () bool {
164
+ // Previous Webhook should be deleted
165
+ _ , err = getWebhookWithGenerateName (c , webhookName )
166
+ if err != nil && err .Error () != "NotFound" {
167
+ return false
168
+ }
169
+
170
+ // Current Webhook should exist
171
+ _ , err = getWebhookWithGenerateName (c , changedGenerateName )
172
+ if err != nil {
173
+ return false
174
+ }
175
+
176
+ return true
177
+ }, time .Minute , 5 * time .Second ).Should (BeTrue ())
150
178
})
151
179
It ("Fails to install a CSV if multiple Webhooks share the same name" , func () {
152
180
sideEffect := admissionregistrationv1 .SideEffectClassNone
@@ -325,7 +353,7 @@ var _ = Describe("CSVs with a Webhook", func() {
325
353
_ , err = fetchCSV (GinkgoT (), crc , csv .Name , namespace .Name , csvSucceededChecker )
326
354
Expect (err ).Should (BeNil ())
327
355
328
- _ , err = getWebhookWithGenName (c , webhook )
356
+ _ , err = getWebhookWithGenerateName (c , webhook . GenerateName )
329
357
Expect (err ).Should (BeNil ())
330
358
331
359
// Update the CSV so it it replaces the existing CSV
@@ -340,7 +368,7 @@ var _ = Describe("CSVs with a Webhook", func() {
340
368
_ , err = fetchCSV (GinkgoT (), crc , csv .GetName (), namespace .Name , csvSucceededChecker )
341
369
Expect (err ).Should (BeNil ())
342
370
343
- _ , err = getWebhookWithGenName (c , webhook )
371
+ _ , err = getWebhookWithGenerateName (c , webhook . GenerateName )
344
372
Expect (err ).Should (BeNil ())
345
373
346
374
// Make sure old resources are cleaned up.
@@ -373,7 +401,7 @@ var _ = Describe("CSVs with a Webhook", func() {
373
401
fetchedCSV , err := fetchCSV (GinkgoT (), crc , csv .Name , namespace .Name , csvSucceededChecker )
374
402
Expect (err ).Should (BeNil ())
375
403
376
- actualWebhook , err := getWebhookWithGenName (c , webhook )
404
+ actualWebhook , err := getWebhookWithGenerateName (c , webhook . GenerateName )
377
405
Expect (err ).Should (BeNil ())
378
406
379
407
oldWebhookCABundle := actualWebhook .Webhooks [0 ].ClientConfig .CABundle
@@ -411,7 +439,7 @@ var _ = Describe("CSVs with a Webhook", func() {
411
439
Expect (err ).Should (BeNil ())
412
440
413
441
// get new webhook
414
- actualWebhook , err = getWebhookWithGenName (c , webhook )
442
+ actualWebhook , err = getWebhookWithGenerateName (c , webhook . GenerateName )
415
443
Expect (err ).Should (BeNil ())
416
444
417
445
newWebhookCABundle := actualWebhook .Webhooks [0 ].ClientConfig .CABundle
@@ -449,7 +477,7 @@ var _ = Describe("CSVs with a Webhook", func() {
449
477
450
478
_ , err = fetchCSV (GinkgoT (), crc , csv .Name , namespace .Name , csvSucceededChecker )
451
479
Expect (err ).Should (BeNil ())
452
- actualWebhook , err := getWebhookWithGenName (c , webhook )
480
+ actualWebhook , err := getWebhookWithGenerateName (c , webhook . GenerateName )
453
481
Expect (err ).Should (BeNil ())
454
482
455
483
expected := & metav1.LabelSelector {
@@ -515,8 +543,8 @@ var _ = Describe("CSVs with a Webhook", func() {
515
543
})
516
544
})
517
545
518
- func getWebhookWithGenName (c operatorclient.ClientInterface , desc v1alpha1. WebhookDescription ) (* admissionregistrationv1.ValidatingWebhookConfiguration , error ) {
519
- webhookSelector := labels .SelectorFromSet (map [string ]string {install .WebhookDescKey : desc . GenerateName }).String ()
546
+ func getWebhookWithGenerateName (c operatorclient.ClientInterface , generateName string ) (* admissionregistrationv1.ValidatingWebhookConfiguration , error ) {
547
+ webhookSelector := labels .SelectorFromSet (map [string ]string {install .WebhookDescKey : generateName }).String ()
520
548
existingWebhooks , err := c .KubernetesInterface ().AdmissionregistrationV1 ().ValidatingWebhookConfigurations ().List (context .TODO (), metav1.ListOptions {LabelSelector : webhookSelector })
521
549
if err != nil {
522
550
return nil , err
@@ -525,7 +553,7 @@ func getWebhookWithGenName(c operatorclient.ClientInterface, desc v1alpha1.Webho
525
553
if len (existingWebhooks .Items ) > 0 {
526
554
return & existingWebhooks .Items [0 ], nil
527
555
}
528
- return nil , fmt .Errorf ("Could not find Webhook " )
556
+ return nil , fmt .Errorf ("NotFound " )
529
557
}
530
558
531
559
func createCSVWithWebhook (namespace string , webhookDesc v1alpha1.WebhookDescription ) v1alpha1.ClusterServiceVersion {
0 commit comments