@@ -69,7 +69,7 @@ var _ = Describe("Deploying KedaController manifest", func() {
69
69
})
70
70
71
71
AfterEach (func () {
72
- manifest , err = changeAttribute (manifest , "namespace" , namespace , scheme )
72
+ manifest , err = changeAttribute (manifest , "namespace" , namespace , scheme , "" )
73
73
Expect (err ).To (BeNil ())
74
74
75
75
Expect (manifest .Delete ()).Should (Succeed ())
@@ -97,7 +97,7 @@ var _ = Describe("Deploying KedaController manifest", func() {
97
97
98
98
It ("Should not deploy KedaController" , func () {
99
99
100
- manifest , err = changeAttribute (manifest , "namespace" , changedNamespace , scheme )
100
+ manifest , err = changeAttribute (manifest , "namespace" , changedNamespace , scheme , "" )
101
101
Expect (err ).To (BeNil ())
102
102
103
103
Expect (manifest .Apply ()).Should (Succeed ())
@@ -137,10 +137,28 @@ var _ = Describe("Testing functionality", func() {
137
137
)
138
138
139
139
BeforeEach (func () {
140
+ By ("Applying a manifest that defaults operator logLevel back to info" )
140
141
scheme = k8sManager .GetScheme ()
141
142
manifest , err = createManifest (kedaManifestFilepath , k8sClient )
142
143
Expect (err ).To (BeNil ())
144
+ manifest , err = changeAttribute (manifest , "logLevel" , "info" , scheme , "default" )
145
+ Expect (err ).To (BeNil ())
143
146
Expect (manifest .Apply ()).Should (Succeed ())
147
+
148
+ By ("Waiting for the operator deployment to reflect the changes" )
149
+ Eventually (func () error {
150
+ return deploymentHasRolledOut (deploymentName , namespace , "default" )
151
+ }, timeout , interval ).Should (Succeed ())
152
+
153
+ By ("Checking to make sure loglevel is set back to info" )
154
+ u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
155
+ Expect (err ).To (BeNil ())
156
+ err = scheme .Convert (u , dep , nil )
157
+ Expect (err ).To (BeNil ())
158
+
159
+ arg , err = getDepArg (dep , logLevelPrefix , containerName )
160
+ Expect (err ).To (BeNil ())
161
+ Expect (arg ).To (Equal ("info" ))
144
162
})
145
163
146
164
Context ("When changing \" --zap-log-level\" " , func () {
@@ -160,6 +178,8 @@ var _ = Describe("Testing functionality", func() {
160
178
initialLogLevel : "error" ,
161
179
actualLogLevel : "error" ,
162
180
},
181
+ // the default in the sample kedacontroller manifest is "info", so "info" in this list can also mean "make sure it doesn't change",
182
+ // it is supposed to ignore these two cases because the values are invalid.
163
183
{
164
184
initialLogLevel : "" ,
165
185
actualLogLevel : "info" ,
@@ -171,27 +191,33 @@ var _ = Describe("Testing functionality", func() {
171
191
}
172
192
173
193
for _ , variant := range variants {
174
- It (fmt .Sprintf ("Should change it, initialLoglevel='%s', actualLoglevel='%s'" ,
175
- variant .initialLogLevel , variant .actualLogLevel ), func () {
176
-
177
- manifest , err = changeAttribute (manifest , "logLevel" , variant .initialLogLevel , scheme )
178
- _ = manifest .Apply ()
179
-
180
- Eventually (func () error {
181
- _ , err = getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
182
- return err
183
- }, timeout , interval ).Should (Succeed ())
184
-
185
- u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
186
- Expect (err ).To (BeNil ())
187
- err = scheme .Convert (u , dep , nil )
188
- Expect (err ).To (BeNil ())
189
-
190
- arg , err = getDepArg (dep , logLevelPrefix , containerName )
191
- Expect (err ).To (BeNil ())
192
- Expect (arg ).To (Equal (variant .actualLogLevel ))
193
- })
194
+ caseName := fmt .Sprintf ("Should change it, initialLoglevel='%s', actualLoglevel='%s'" , variant .initialLogLevel , variant .actualLogLevel )
195
+ It (caseName ,
196
+ func () {
197
+ By (fmt .Sprintf ("Setting operator loglevel to %s in kedaController manifest" , variant .initialLogLevel ))
198
+ manifest , err = changeAttribute (manifest , "logLevel" , variant .initialLogLevel , scheme , caseName )
199
+ Expect (err ).To (BeNil ())
200
+ err = manifest .Apply ()
201
+ Expect (err ).To (BeNil ())
202
+
203
+ By ("Waiting for the operator deployment to reflect the changes" )
204
+ Eventually (func () error {
205
+ return deploymentHasRolledOut (deploymentName , namespace , caseName )
206
+ }, timeout , interval ).Should (Succeed ())
207
+
208
+ By ("Checking to make sure the log level is " + variant .actualLogLevel )
209
+ u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
210
+ Expect (err ).To (BeNil ())
211
+ err = scheme .Convert (u , dep , nil )
212
+ Expect (err ).To (BeNil ())
213
+
214
+ arg , err = getDepArg (dep , logLevelPrefix , containerName )
215
+ Expect (err ).To (BeNil ())
216
+ Expect (arg ).To (Equal (variant .actualLogLevel ))
217
+
218
+ })
194
219
}
220
+
195
221
})
196
222
})
197
223
@@ -219,10 +245,28 @@ var _ = Describe("Testing functionality", func() {
219
245
)
220
246
221
247
BeforeEach (func () {
248
+ By ("Applying a manifest that defaults operator logLevel back to info" )
222
249
scheme = k8sManager .GetScheme ()
223
250
manifest , err = createManifest (kedaManifestFilepath , k8sClient )
224
251
Expect (err ).To (BeNil ())
252
+ manifest , err = changeAttribute (manifest , "logLevel" , "info" , scheme , "default" )
253
+ Expect (err ).To (BeNil ())
225
254
Expect (manifest .Apply ()).Should (Succeed ())
255
+
256
+ By ("Waiting for the operator deployment to reflect the changes" )
257
+ Eventually (func () error {
258
+ return deploymentHasRolledOut (deploymentName , namespace , "default" )
259
+ }, timeout , interval ).Should (Succeed ())
260
+
261
+ By ("Checking to make sure loglevel is set back to info" )
262
+ u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
263
+ Expect (err ).To (BeNil ())
264
+ err = scheme .Convert (u , dep , nil )
265
+ Expect (err ).To (BeNil ())
266
+
267
+ arg , err = getDepArg (dep , logLevelPrefix , containerName )
268
+ Expect (err ).To (BeNil ())
269
+ Expect (arg ).To (Equal ("info" ))
226
270
})
227
271
228
272
Context ("When changing \" --zap-log-level\" " , func () {
@@ -242,6 +286,8 @@ var _ = Describe("Testing functionality", func() {
242
286
initialLogLevel : "error" ,
243
287
actualLogLevel : "error" ,
244
288
},
289
+ // the default in the sample kedacontroller manifest is "info", so "info" in this list can also mean "make sure it doesn't change",
290
+ // it is supposed to ignore these two cases because the values are invalid.
245
291
{
246
292
initialLogLevel : "" ,
247
293
actualLogLevel : "info" ,
@@ -253,17 +299,21 @@ var _ = Describe("Testing functionality", func() {
253
299
}
254
300
255
301
for _ , variant := range variants {
256
- It (fmt .Sprintf ("Should change it, initialLoglevel='%s', actualLoglevel='%s'" ,
257
- variant .initialLogLevel , variant .actualLogLevel ), func () {
302
+ caseName := fmt .Sprintf ("Should change it, initialLoglevel='%s', actualLoglevel='%s'" , variant .initialLogLevel , variant .actualLogLevel )
258
303
259
- manifest , err = changeAttribute (manifest , "logLevel" , variant .initialLogLevel , scheme )
260
- _ = manifest .Apply ()
304
+ It (caseName , func () {
305
+ By (fmt .Sprintf ("Setting admission loglevel to %s in kedaController manifest" , variant .initialLogLevel ))
306
+ manifest , err = changeAttribute (manifest , "logLevel-admission" , variant .initialLogLevel , scheme , caseName )
307
+ Expect (err ).To (BeNil ())
308
+ err = manifest .Apply ()
309
+ Expect (err ).To (BeNil ())
261
310
311
+ By ("Waiting for the admission deployment to reflect the changes" )
262
312
Eventually (func () error {
263
- _ , err = getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
264
- return err
313
+ return deploymentHasRolledOut (deploymentName , namespace , caseName )
265
314
}, timeout , interval ).Should (Succeed ())
266
315
316
+ By ("Checking to make sure the log level is " + variant .actualLogLevel )
267
317
u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
268
318
Expect (err ).To (BeNil ())
269
319
err = scheme .Convert (u , dep , nil )
@@ -298,6 +348,10 @@ var _ = Describe("Testing audit flags", func() {
298
348
)
299
349
300
350
When ("Manipulating parameters" , func () {
351
+
352
+ // TODO(jkyros): come back to refactor this test, it doesn't proeprly reset between test cases, and
353
+ // if it did, it would be failing, because it's currently impossible to deconfigure audit because of
354
+ // how our manifestival code only operates if the settings are different from default/empty.
301
355
BeforeEach (func () {
302
356
scheme = k8sManager .GetScheme ()
303
357
dep = & appsv1.Deployment {}
@@ -317,7 +371,7 @@ var _ = Describe("Testing audit flags", func() {
317
371
value : "json" ,
318
372
},
319
373
{
320
- argument : "auditMaxAge= " ,
374
+ argument : "auditMaxAge" ,
321
375
prefix : "--audit-log-maxage=" ,
322
376
value : "1" ,
323
377
},
@@ -333,13 +387,15 @@ var _ = Describe("Testing audit flags", func() {
333
387
},
334
388
}
335
389
for _ , variant := range vars {
390
+ caseName := fmt .Sprintf ("adds '%s' with value '%s'" , variant .argument , variant .value )
391
+ It (caseName , func () {
392
+ manifest , err := changeAttribute (manifest , variant .argument , variant .value , scheme , caseName )
393
+ Expect (err ).To (BeNil ())
336
394
337
- It (fmt .Sprintf ("adds '%s' with value '%s'" , variant .argument , variant .value ), func () {
338
- manifest , err := changeAttribute (manifest , variant .argument , variant .value , scheme )
339
395
Expect (manifest .Apply ()).To (Succeed ())
340
396
Eventually (func () error {
341
- _ , err = getObject ( ctx , "Deployment" , metricsServerName , namespace , k8sClient )
342
- return err
397
+ return deploymentHasRolledOut ( metricsServerName , namespace , caseName )
398
+
343
399
}, timeout , interval ).Should (Succeed ())
344
400
u , err := getObject (ctx , "Deployment" , metricsServerName , namespace , k8sClient )
345
401
Expect (err ).To (BeNil ())
@@ -369,18 +425,41 @@ func getDepArg(dep *appsv1.Deployment, prefix string, containerName string) (str
369
425
return "" , errors .New ("Could not find a container: " + containerName )
370
426
}
371
427
372
- func changeAttribute (manifest mf.Manifest , attr string , value string , scheme * runtime.Scheme ) (mf.Manifest , error ) {
428
+ func changeAttribute (manifest mf.Manifest , attr string , value string , scheme * runtime.Scheme , annotation string ) (mf.Manifest , error ) {
373
429
transformer := func (u * unstructured.Unstructured ) error {
374
430
kedaControllerInstance := & kedav1alpha1.KedaController {}
375
431
if err := scheme .Convert (u , kedaControllerInstance , nil ); err != nil {
376
432
return err
377
433
}
378
434
435
+ // Annotations might be nil, so we need to make sure we account for that
436
+ if kedaControllerInstance .Spec .Operator .DeploymentAnnotations == nil {
437
+ kedaControllerInstance .Spec .Operator .DeploymentAnnotations = make (map [string ]string )
438
+ }
439
+
440
+ if kedaControllerInstance .Spec .AdmissionWebhooks .DeploymentAnnotations == nil {
441
+ kedaControllerInstance .Spec .AdmissionWebhooks .DeploymentAnnotations = make (map [string ]string )
442
+ }
443
+ if kedaControllerInstance .Spec .MetricsServer .DeploymentAnnotations == nil {
444
+ kedaControllerInstance .Spec .MetricsServer .DeploymentAnnotations = make (map [string ]string )
445
+ }
446
+ // When we push through an attribute change, we also set an annotation matching the test case
447
+ // so we can be sure the controller reacted to our kedaControllerInstance updates and we have "our"
448
+ // changes, not just some changes that might be from a previous test case
449
+ kedaControllerInstance .Spec .Operator .DeploymentAnnotations ["testCase" ] = annotation
450
+ kedaControllerInstance .Spec .AdmissionWebhooks .DeploymentAnnotations ["testCase" ] = annotation
451
+ kedaControllerInstance .Spec .MetricsServer .DeploymentAnnotations ["testCase" ] = annotation
452
+
379
453
switch attr {
380
454
case "namespace" :
381
455
kedaControllerInstance .Namespace = value
382
456
case "logLevel" :
383
457
kedaControllerInstance .Spec .Operator .LogLevel = value
458
+ // TODO(jkyros): this breaks pattern with the rest of these cases but multiple operands have
459
+ // the same field, but we kind of bolted the admission tests on here without doing a refactor and
460
+ // this makes it work for now
461
+ case "logLevel-admission" :
462
+ kedaControllerInstance .Spec .AdmissionWebhooks .LogLevel = value
384
463
// metricsServer audit arguments
385
464
case "auditLogFormat" :
386
465
kedaControllerInstance .Spec .MetricsServer .AuditConfig .LogFormat = value
@@ -398,3 +477,22 @@ func changeAttribute(manifest mf.Manifest, attr string, value string, scheme *ru
398
477
399
478
return manifest .Transform (transformer )
400
479
}
480
+
481
+ // deploymentHasRolledOut waits for the specified deployment to possess the specified annotation
482
+ //
483
+ //nolint:unparam
484
+ func deploymentHasRolledOut (deploymentName string , namespace string , deploymentAnnotation string ) error {
485
+ u , err := getObject (ctx , "Deployment" , deploymentName , namespace , k8sClient )
486
+ if err != nil {
487
+ return err
488
+ }
489
+ // The default manifest has no annotation, so I'm not checking whether it's present, only the value,
490
+ // because the default case will not have the annotation, and we want that to be okay in the case where we
491
+ // apply the default.
492
+ testcase := u .GetAnnotations ()["testCase" ]
493
+ if deploymentAnnotation == testcase {
494
+ By ("Observing that the test case annotation is now: " + testcase )
495
+ return nil
496
+ }
497
+ return fmt .Errorf ("Deployment has not rolled out, annotation is still '%s'" , testcase )
498
+ }
0 commit comments