@@ -29,7 +29,7 @@ import (
29
29
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
30
30
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
31
31
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
32
- osFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/os"
32
+ osFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/os" // Corrected import path
33
33
subscriptionFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/subscription"
34
34
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
35
35
appsv1 "k8s.io/api/apps/v1"
@@ -40,16 +40,18 @@ import (
40
40
)
41
41
42
42
const (
43
- // E2ETestLabelsKey and E2ETestLabelsValue are added to cluster-scoped resources (e.g. Namespaces) created by E2E tests (where possible). On startup (and before each test for sequential tests), any resources with this label will be deleted.
44
- E2ETestLabelsKey = "app"
45
- E2ETestLabelsValue = "test-argo-app"
43
+ E2ETestLabelsKey = "app"
44
+ E2ETestLabelsValue = "test-argo-app"
45
+ GitOpsOperatorNamespace = "openshift-gitops-operator"
46
+ GitOpsOperatorDeploymentName = "openshift-gitops-operator-controller-manager"
47
+ GitOpsOperatorSubscriptionName = "openshift-gitops-operator"
48
+ HelloWorldPattern = "helloworld-operator"
46
49
)
47
50
48
51
var NamespaceLabels = map [string ]string {E2ETestLabelsKey : E2ETestLabelsValue }
49
52
50
53
func EnsureParallelCleanSlate () {
51
54
52
- // Increase the maximum length of debug output, for when tests fail
53
55
format .MaxLength = 64 * 1024
54
56
SetDefaultEventuallyTimeout (time .Second * 60 )
55
57
SetDefaultEventuallyPollingInterval (time .Second * 3 )
@@ -71,20 +73,12 @@ func EnsureParallelCleanSlate() {
71
73
// Unlike sequential clean slate, parallel clean slate cannot assume that there are no other tests running. This limits our ability to clean up old test artifacts.
72
74
}
73
75
74
- // EnsureSequentialCleanSlate will clean up resources that were created during previous sequential tests
75
- // - Deletes namespaces that were created by previous tests
76
- // - Deletes other cluster-scoped resources that were created
77
- // - Reverts changes made to Subscription CR
78
- // - etc
79
76
func EnsureSequentialCleanSlate () {
80
77
Expect (EnsureSequentialCleanSlateWithError ()).To (Succeed ())
81
78
}
82
79
83
80
func EnsureSequentialCleanSlateWithError () error {
84
81
85
- // With sequential tests, we are always safe to assume that there is no other test running. That allows us to clean up old test artifacts before new test starts.
86
-
87
- // Increase the maximum length of debug output, for when tests fail
88
82
format .MaxLength = 64 * 1024
89
83
SetDefaultEventuallyTimeout (time .Second * 60 )
90
84
SetDefaultEventuallyPollingInterval (time .Second * 3 )
@@ -131,8 +125,8 @@ func EnsureSequentialCleanSlateWithError() error {
131
125
Enabled : true ,
132
126
TLS : nil ,
133
127
// TLS: &routev1.TLSConfig{
134
- // Termination: routev1.TLSTerminationReencrypt,
135
- // InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyRedirect,
128
+ // Termination: routev1.TLSTerminationReencrypt,
129
+ // InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyRedirect,
136
130
// },
137
131
}
138
132
@@ -206,13 +200,12 @@ func EnsureSequentialCleanSlateWithError() error {
206
200
func RemoveDynamicPluginFromCSV (ctx context.Context , k8sClient client.Client ) error {
207
201
208
202
if EnvNonOLM () || EnvLocalRun () {
209
- // Skipping as CSV does exist when not using OLM, nor does it exist when running locally
210
203
return nil
211
204
}
212
205
213
206
var csv * olmv1alpha1.ClusterServiceVersion
214
207
var csvList olmv1alpha1.ClusterServiceVersionList
215
- Expect (k8sClient .List (ctx , & csvList , client .InNamespace ("openshift-gitops-operator" ))).To (Succeed ())
208
+ Expect (k8sClient .List (ctx , & csvList , client .InNamespace (GitOpsOperatorNamespace ))).To (Succeed ())
216
209
217
210
for idx := range csvList .Items {
218
211
idxCSV := csvList .Items [idx ]
@@ -221,7 +214,7 @@ func RemoveDynamicPluginFromCSV(ctx context.Context, k8sClient client.Client) er
221
214
break
222
215
}
223
216
}
224
- Expect (csv ).ToNot (BeNil (), "if you see this, it likely means, either: A) the operator is not installed via OLM (and you meant to install it), OR B) you are running the operator locally via 'make run', and thus should specify LOCAL_RUN=true env var when calling the test" )
217
+ Expect (csv ).ToNot (BeNil (), "if you see this, it likely means, either: A) the operator is not installed via OLM (and you meant to install it), OR B) you are running the operator locally via 'make run', and thus should not specify LOCAL_RUN=true env var when calling the test" )
225
218
226
219
if err := updateWithoutConflict (csv , func (obj client.Object ) {
227
220
@@ -374,7 +367,7 @@ func GetEnvInOperatorSubscriptionOrDeployment(key string) (*string, error) {
374
367
}
375
368
376
369
if EnvNonOLM () {
377
- depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator-controller-manager" , Namespace : "openshift-gitops-operator" }}
370
+ depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorDeploymentName , Namespace : GitOpsOperatorNamespace }}
378
371
379
372
return deploymentFixture .GetEnv (depl , key )
380
373
@@ -394,7 +387,7 @@ func GetEnvInOperatorSubscriptionOrDeployment(key string) (*string, error) {
394
387
395
388
} else {
396
389
397
- sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator" , Namespace : "openshift-gitops-operator" }}
390
+ sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorSubscriptionName , Namespace : GitOpsOperatorNamespace }}
398
391
if err := k8sClient .Get (context .Background (), client .ObjectKeyFromObject (sub ), sub ); err != nil {
399
392
return nil , err
400
393
}
@@ -411,11 +404,11 @@ func SetEnvInOperatorSubscriptionOrDeployment(key string, value string) {
411
404
k8sClient , _ := utils .GetE2ETestKubeClient ()
412
405
413
406
if EnvNonOLM () {
414
- depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator-controller-manager" , Namespace : "openshift-gitops-operator" }}
407
+ depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorDeploymentName , Namespace : GitOpsOperatorNamespace }}
415
408
416
409
deploymentFixture .SetEnv (depl , key , value )
417
410
418
- WaitForAllDeploymentsInTheNamespaceToBeReady ("openshift-gitops-operator" , k8sClient )
411
+ WaitForAllDeploymentsInTheNamespaceToBeReady (GitOpsOperatorNamespace , k8sClient )
419
412
420
413
} else if EnvCI () {
421
414
@@ -429,7 +422,7 @@ func SetEnvInOperatorSubscriptionOrDeployment(key string, value string) {
429
422
430
423
} else {
431
424
432
- sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator" , Namespace : "openshift-gitops-operator" }}
425
+ sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorSubscriptionName , Namespace : GitOpsOperatorNamespace }}
433
426
Expect (k8sClient .Get (context .Background (), client .ObjectKeyFromObject (sub ), sub )).To (Succeed ())
434
427
435
428
subscriptionFixture .SetEnv (sub , key , value )
@@ -448,11 +441,11 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {
448
441
}
449
442
450
443
if EnvNonOLM () {
451
- depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator-controller-manager" , Namespace : "openshift-gitops-operator" }}
444
+ depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorDeploymentName , Namespace : GitOpsOperatorNamespace }}
452
445
453
446
deploymentFixture .RemoveEnv (depl , key )
454
447
455
- WaitForAllDeploymentsInTheNamespaceToBeReady ("openshift-gitops-operator" , k8sClient )
448
+ WaitForAllDeploymentsInTheNamespaceToBeReady (GitOpsOperatorNamespace , k8sClient )
456
449
457
450
} else if EnvCI () {
458
451
@@ -470,7 +463,7 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {
470
463
471
464
} else {
472
465
473
- sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator" , Namespace : "openshift-gitops-operator" }}
466
+ sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorSubscriptionName , Namespace : GitOpsOperatorNamespace }}
474
467
if err := k8sClient .Get (context .Background (), client .ObjectKeyFromObject (sub ), sub ); err != nil {
475
468
return err
476
469
}
@@ -485,9 +478,7 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {
485
478
486
479
func GetSubscriptionInEnvCIEnvironment (k8sClient client.Client ) (* olmv1alpha1.Subscription , error ) {
487
480
subscriptionList := olmv1alpha1.SubscriptionList {}
488
- if err := k8sClient .List (context .Background (), & subscriptionList , client .InNamespace ("openshift-gitops-operator" )); err != nil {
489
- return nil , err
490
- }
481
+ Expect (k8sClient .List (context .Background (), & subscriptionList , client .InNamespace (GitOpsOperatorNamespace ))).To (Succeed ())
491
482
492
483
var sub * olmv1alpha1.Subscription
493
484
@@ -516,7 +507,7 @@ func RestoreSubcriptionToDefault() error {
516
507
517
508
if EnvNonOLM () {
518
509
519
- depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator-controller-manager" , Namespace : "openshift-gitops-operator" }}
510
+ depl := & appsv1.Deployment {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorDeploymentName , Namespace : GitOpsOperatorNamespace }}
520
511
521
512
for _ , envKey := range optionalEnvVarsToRemove {
522
513
deploymentFixture .RemoveEnv (depl , envKey )
@@ -539,30 +530,26 @@ func RestoreSubcriptionToDefault() error {
539
530
subscriptionFixture .RemoveSpecConfig (sub )
540
531
}
541
532
542
- if err := waitForAllEnvVarsToBeRemovedFromDeployments ("openshift-gitops-operator" , optionalEnvVarsToRemove , k8sClient ); err != nil {
533
+ if err := waitForAllEnvVarsToBeRemovedFromDeployments (GitOpsOperatorNamespace , optionalEnvVarsToRemove , k8sClient ); err != nil {
543
534
return err
544
535
}
545
536
546
- WaitForAllDeploymentsInTheNamespaceToBeReady ("openshift-gitops-operator" , k8sClient )
547
-
548
- } else if EnvLocalRun () {
549
- // When running locally, there are no cluster resources to clean up
550
- return nil
537
+ WaitForAllDeploymentsInTheNamespaceToBeReady (GitOpsOperatorNamespace , k8sClient )
551
538
552
539
} else {
553
540
554
- sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : "openshift-gitops-operator" , Namespace : "openshift-gitops-operator" }}
541
+ sub := & olmv1alpha1.Subscription {ObjectMeta : metav1.ObjectMeta {Name : GitOpsOperatorSubscriptionName , Namespace : GitOpsOperatorNamespace }}
555
542
if err := k8sClient .Get (context .Background (), client .ObjectKeyFromObject (sub ), sub ); err != nil {
556
543
return err
557
544
}
558
545
559
546
subscriptionFixture .RemoveSpecConfig (sub )
560
547
561
- if err := waitForAllEnvVarsToBeRemovedFromDeployments ("openshift-gitops-operator" , optionalEnvVarsToRemove , k8sClient ); err != nil {
548
+ if err := waitForAllEnvVarsToBeRemovedFromDeployments (GitOpsOperatorNamespace , optionalEnvVarsToRemove , k8sClient ); err != nil {
562
549
return err
563
550
}
564
551
565
- WaitForAllDeploymentsInTheNamespaceToBeReady ("openshift-gitops-operator" , k8sClient )
552
+ WaitForAllDeploymentsInTheNamespaceToBeReady (GitOpsOperatorNamespace , k8sClient )
566
553
}
567
554
568
555
return nil
@@ -848,15 +835,14 @@ func OutputDebugOnFail(namespaceParams ...any) {
848
835
debugOutput , exists := testReportMap [testName ]
849
836
850
837
if exists && debugOutput .isOutputted {
851
- // Skip output if we have already outputted once for this test
852
838
return
853
839
}
854
840
855
841
testReportMap [testName ] = testReportEntry {
856
842
isOutputted : true ,
857
843
}
858
844
859
- outputPodLog ("openshift-gitops-operator-controller-manager" )
845
+ outputPodLog (GitOpsOperatorDeploymentName )
860
846
861
847
for _ , namespace := range namespaces {
862
848
@@ -911,7 +897,6 @@ func outputPodLog(podSubstring string) {
911
897
}
912
898
913
899
if len (matchingPods ) == 0 {
914
- // This can happen when the operator is not running on the cluster
915
900
GinkgoWriter .Println ("DebugOutputOperatorLogs was called, but no pods were found." )
916
901
return
917
902
}
@@ -922,7 +907,7 @@ func outputPodLog(podSubstring string) {
922
907
}
923
908
924
909
// Extract operator logs
925
- kubectlLogOutput , err := osFixture .ExecCommandWithOutputParam (false , "kubectl" , "logs" , "pod/" + matchingPods [0 ].Name , "manager" , "-n" , matchingPods [ 0 ]. Namespace )
910
+ kubectlLogOutput , err := osFixture .ExecCommandWithOutputParam (false , "kubectl" , "logs" , "pod/" + matchingPods [0 ].Name , "manager" , "-n" , GitOpsOperatorNamespace )
926
911
if err != nil {
927
912
GinkgoWriter .Println ("unable to extract operator logs" , err )
928
913
return
0 commit comments