@@ -29,39 +29,49 @@ func DeploymentComplete(deployment *appsv1.Deployment, newStatus *appsv1.Deploym
29
29
}
30
30
31
31
// Currently this function only modifies the watchedNamespace in the container command
32
- func patchOlmDeployment (t * testing.T , c operatorclient.ClientInterface , newNamespace string ) [] string {
32
+ func patchOlmDeployment (t * testing.T , c operatorclient.ClientInterface , newNamespace string ) ( cleanupFunc func () error ) {
33
33
runningDeploy , err := c .GetDeployment (testNamespace , "olm-operator" )
34
34
require .NoError (t , err )
35
35
36
- command := runningDeploy .Spec .Template .Spec .Containers [0 ].Command
36
+ oldCommand := runningDeploy .Spec .Template .Spec .Containers [0 ].Command
37
37
re , err := regexp .Compile (`-watchedNamespaces\W(\S+)` )
38
38
require .NoError (t , err )
39
- newCommand := re .ReplaceAllString (strings .Join (command , " " ), "$0" + "," + newNamespace )
40
- t .Logf ("original=%#v newCommand=%#v" , command , newCommand )
39
+ newCommand := re .ReplaceAllString (strings .Join (oldCommand , " " ), "$0" + "," + newNamespace )
40
+ t .Logf ("original=%#v newCommand=%#v" , oldCommand , newCommand )
41
41
finalNewCommand := strings .Split (newCommand , " " )
42
42
runningDeploy .Spec .Template .Spec .Containers [0 ].Command = make ([]string , len (finalNewCommand ))
43
43
copy (runningDeploy .Spec .Template .Spec .Containers [0 ].Command , finalNewCommand )
44
44
45
- newDeployment , updated , err := c .UpdateDeployment (runningDeploy )
45
+ olmDeployment , updated , err := c .UpdateDeployment (runningDeploy )
46
46
if err != nil || updated == false {
47
47
t .Fatalf ("Deployment update failed: (updated %v) %v\n " , updated , err )
48
48
}
49
49
require .NoError (t , err )
50
50
51
51
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
52
52
t .Log ("Polling for OLM deployment update..." )
53
- fetchedDeployment , err := c .GetDeployment (newDeployment .Namespace , newDeployment .Name )
53
+ fetchedDeployment , err := c .GetDeployment (olmDeployment .Namespace , olmDeployment .Name )
54
54
if err != nil {
55
55
return false , err
56
56
}
57
- if DeploymentComplete (newDeployment , & fetchedDeployment .Status ) {
57
+ if DeploymentComplete (olmDeployment , & fetchedDeployment .Status ) {
58
58
return true , nil
59
59
}
60
60
return false , nil
61
61
})
62
-
63
62
require .NoError (t , err )
64
- return command
63
+
64
+ return func () error {
65
+ olmDeployment .Spec .Template .Spec .Containers [0 ].Command = oldCommand
66
+ _ , updated , err := c .UpdateDeployment (olmDeployment )
67
+ if err != nil || updated == false {
68
+ t .Fatalf ("Deployment update failed: (updated %v) %v\n " , updated , err )
69
+ }
70
+ if err != nil {
71
+ return err
72
+ }
73
+ return nil
74
+ }
65
75
}
66
76
67
77
func checkOperatorGroupAnnotations (obj metav1.Object , op * v1alpha2.OperatorGroup , targetNamespaces string ) error {
@@ -104,7 +114,7 @@ func TestOperatorGroup(t *testing.T) {
104
114
createdOtherNamespace , err := c .KubernetesInterface ().CoreV1 ().Namespaces ().Create (& otherNamespace )
105
115
require .NoError (t , err )
106
116
107
- oldCommand := patchOlmDeployment (t , c , otherNamespaceName )
117
+ cleanupOlmDeployment := patchOlmDeployment (t , c , otherNamespaceName )
108
118
109
119
t .Log ("Creating CRD" )
110
120
mainCRDPlural := genName ("ins" )
@@ -231,27 +241,14 @@ func TestOperatorGroup(t *testing.T) {
231
241
require .NoError (t , err )
232
242
233
243
t .Log ("Waiting for orphaned CSV to be deleted" )
234
- err = wait . Poll ( pollInterval , pollDuration , func () ( bool , error ) {
244
+ err = waitForDelete ( func () error {
235
245
_ , err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
236
- if err != nil {
237
- if errors .IsNotFound (err ) {
238
- return true , nil
239
- }
240
- return false , err
241
- }
242
- return false , nil
246
+ return err
243
247
})
244
248
require .NoError (t , err )
245
249
246
250
// clean up
247
- // TODO: unpatch function
248
- runningDeploy , err := c .GetDeployment (testNamespace , "olm-operator" )
249
- require .NoError (t , err )
250
- runningDeploy .Spec .Template .Spec .Containers [0 ].Command = oldCommand
251
- _ , updated , err := c .UpdateDeployment (runningDeploy )
252
- if err != nil || updated == false {
253
- t .Fatalf ("Deployment update failed: (updated %v) %v\n " , updated , err )
254
- }
251
+ err = cleanupOlmDeployment ()
255
252
require .NoError (t , err )
256
253
257
254
cleanupCRD ()
0 commit comments