@@ -278,66 +278,47 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool)
278
278
279
279
// curlMetrics curl's the /metrics endpoint, returning all logs once a 200 status is returned.
280
280
func curlMetrics (kbc * utils.TestContext , hasMetrics bool ) string {
281
- By ("validating that the controller-manager service is available" )
282
- _ , err := kbc .Kubectl .Get (
283
- true ,
284
- "service" , fmt .Sprintf ("e2e-%s-controller-manager-metrics-service" , kbc .TestSuffix ),
285
- )
286
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred (), "Controller-manager service should exist" )
287
-
288
- By ("validating that the controller-manager deployment is ready" )
289
- verifyDeploymentReady := func () error {
290
- output , err := kbc .Kubectl .Get (
281
+ var metricsOutput string
282
+ if hasMetrics {
283
+ By ("validating that the controller-manager service is available" )
284
+ _ , err := kbc .Kubectl .Get (
291
285
true ,
292
- "deployment" , fmt .Sprintf ("e2e-%s-controller-manager" , kbc .TestSuffix ),
293
- "-o" , "jsonpath={.status.readyReplicas}" ,
286
+ "service" , fmt .Sprintf ("e2e-%s-controller-manager-metrics-service" , kbc .TestSuffix ),
294
287
)
295
- if err != nil {
296
- return err
297
- }
298
- readyReplicas , _ := strconv .Atoi (output )
299
- if readyReplicas < 1 {
300
- return fmt .Errorf ("expected at least 1 ready replica, got %d" , readyReplicas )
301
- }
302
- return nil
303
- }
304
- EventuallyWithOffset (2 , verifyDeploymentReady , 240 * time .Second , time .Second ).Should (Succeed (),
305
- "Deployment is not ready" )
288
+ ExpectWithOffset (2 , err ).NotTo (HaveOccurred (), "Controller-manager service should exist" )
306
289
307
- By ("ensuring the service endpoint is ready" )
308
- eventuallyCheckServiceEndpoint := func () error {
309
- output , err := kbc .Kubectl .Get (
310
- true ,
311
- "endpoints" , fmt .Sprintf ("e2e-%s-controller-manager-metrics-service" , kbc .TestSuffix ),
312
- "-o" , "jsonpath={.subsets[*].addresses[*].ip}" ,
313
- )
314
- if err != nil {
315
- return err
290
+ By ("ensuring the service endpoint is ready" )
291
+ eventuallyCheckServiceEndpoint := func () error {
292
+ output , err := kbc .Kubectl .Get (
293
+ true ,
294
+ "endpoints" , fmt .Sprintf ("e2e-%s-controller-manager-metrics-service" , kbc .TestSuffix ),
295
+ "-o" , "jsonpath={.subsets[*].addresses[*].ip}" ,
296
+ )
297
+ if err != nil {
298
+ return err
299
+ }
300
+ if output == "" {
301
+ return fmt .Errorf ("no endpoints found" )
302
+ }
303
+ return nil
316
304
}
317
- if output == "" {
318
- return fmt .Errorf ("no endpoints found" )
305
+ EventuallyWithOffset (2 , eventuallyCheckServiceEndpoint , 2 * time .Minute , time .Second ).Should (Succeed (),
306
+ "Service endpoint should be ready" )
307
+
308
+ By ("creating a curl pod to access the metrics endpoint" )
309
+ // nolint:lll
310
+ cmdOpts := []string {
311
+ "run" , "curl" ,
312
+ "--restart=Never" ,
313
+ "--namespace" , kbc .Kubectl .Namespace ,
314
+ "--image=curlimages/curl:7.78.0" ,
315
+ "--" ,
316
+ "/bin/sh" , "-c" , fmt .Sprintf ("curl -v -k http://e2e-%s-controller-manager-metrics-service.%s.svc.cluster.local:8080/metrics" ,
317
+ kbc .TestSuffix , kbc .Kubectl .Namespace ),
319
318
}
320
- return nil
321
- }
322
- EventuallyWithOffset (2 , eventuallyCheckServiceEndpoint , 2 * time .Minute , time .Second ).Should (Succeed (),
323
- "Service endpoint should be ready" )
324
-
325
- By ("creating a curl pod to access the metrics endpoint" )
326
- // nolint:lll
327
- cmdOpts := []string {
328
- "run" , "curl" ,
329
- "--restart=Never" ,
330
- "--namespace" , kbc .Kubectl .Namespace ,
331
- "--image=curlimages/curl:7.78.0" ,
332
- "--" ,
333
- "/bin/sh" , "-c" , fmt .Sprintf ("curl -v -k http://e2e-%s-controller-manager-metrics-service.%s.svc.cluster.local:8080/metrics" ,
334
- kbc .TestSuffix , kbc .Kubectl .Namespace ),
335
- }
336
- _ , err = kbc .Kubectl .CommandInNamespace (cmdOpts ... )
337
- ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
319
+ _ , err = kbc .Kubectl .CommandInNamespace (cmdOpts ... )
320
+ ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
338
321
339
- var metricsOutput string
340
- if hasMetrics {
341
322
By ("validating that the curl pod is running as expected" )
342
323
verifyCurlUp := func () error {
343
324
status , err := kbc .Kubectl .Get (
@@ -359,6 +340,20 @@ func curlMetrics(kbc *utils.TestContext, hasMetrics bool) string {
359
340
}
360
341
EventuallyWithOffset (2 , getCurlLogs , 10 * time .Second , time .Second ).Should (ContainSubstring ("< HTTP/1.1 200 OK" ))
361
342
} else {
343
+ By ("creating a curl pod to access the metrics endpoint" )
344
+ // nolint:lll
345
+ cmdOpts := []string {
346
+ "run" , "curl" ,
347
+ "--restart=Never" ,
348
+ "--namespace" , kbc .Kubectl .Namespace ,
349
+ "--image=curlimages/curl:7.78.0" ,
350
+ "--" ,
351
+ "/bin/sh" , "-c" , fmt .Sprintf ("curl -v -k http://e2e-%s-controller-manager-metrics-service.%s.svc.cluster.local:8080/metrics" ,
352
+ kbc .TestSuffix , kbc .Kubectl .Namespace ),
353
+ }
354
+ _ , err := kbc .Kubectl .CommandInNamespace (cmdOpts ... )
355
+ ExpectWithOffset (2 , err ).NotTo (HaveOccurred ())
356
+
362
357
By ("validating that the curl pod fail as expected" )
363
358
verifyCurlUp := func () error {
364
359
status , err := kbc .Kubectl .Get (
@@ -375,14 +370,14 @@ func curlMetrics(kbc *utils.TestContext, hasMetrics bool) string {
375
370
376
371
By ("validating that the metrics endpoint is not working as expected" )
377
372
getCurlLogs := func () string {
378
- metricsOutput , err = kbc .Kubectl .Logs ("curl" )
373
+ metricsOutput , err : = kbc .Kubectl .Logs ("curl" )
379
374
ExpectWithOffset (3 , err ).NotTo (HaveOccurred ())
380
375
return metricsOutput
381
376
}
382
- EventuallyWithOffset (2 , getCurlLogs , 10 * time .Second , time .Second ).Should (ContainSubstring ("Connection refused " ))
377
+ EventuallyWithOffset (2 , getCurlLogs , 10 * time .Second , time .Second ).Should (ContainSubstring ("Could not resolve host " ))
383
378
}
384
379
By ("cleaning up the curl pod" )
385
- _ , err = kbc .Kubectl .Delete (true , "pods/curl" )
380
+ _ , err : = kbc .Kubectl .Delete (true , "pods/curl" )
386
381
ExpectWithOffset (3 , err ).NotTo (HaveOccurred ())
387
382
388
383
return metricsOutput
0 commit comments