Skip to content

Commit f233a1a

Browse files
author
Jeff Peeler
committed
fix(olm): create cleanup function for olm deploy mod
also use waitForDelete instead of writing out more polling code
1 parent d5e2649 commit f233a1a

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

test/e2e/operator_groups_e2e_test.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,49 @@ func DeploymentComplete(deployment *appsv1.Deployment, newStatus *appsv1.Deploym
2929
}
3030

3131
// 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) {
3333
runningDeploy, err := c.GetDeployment(testNamespace, "olm-operator")
3434
require.NoError(t, err)
3535

36-
command := runningDeploy.Spec.Template.Spec.Containers[0].Command
36+
oldCommand := runningDeploy.Spec.Template.Spec.Containers[0].Command
3737
re, err := regexp.Compile(`-watchedNamespaces\W(\S+)`)
3838
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)
4141
finalNewCommand := strings.Split(newCommand, " ")
4242
runningDeploy.Spec.Template.Spec.Containers[0].Command = make([]string, len(finalNewCommand))
4343
copy(runningDeploy.Spec.Template.Spec.Containers[0].Command, finalNewCommand)
4444

45-
newDeployment, updated, err := c.UpdateDeployment(runningDeploy)
45+
olmDeployment, updated, err := c.UpdateDeployment(runningDeploy)
4646
if err != nil || updated == false {
4747
t.Fatalf("Deployment update failed: (updated %v) %v\n", updated, err)
4848
}
4949
require.NoError(t, err)
5050

5151
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
5252
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)
5454
if err != nil {
5555
return false, err
5656
}
57-
if DeploymentComplete(newDeployment, &fetchedDeployment.Status) {
57+
if DeploymentComplete(olmDeployment, &fetchedDeployment.Status) {
5858
return true, nil
5959
}
6060
return false, nil
6161
})
62-
6362
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+
}
6575
}
6676

6777
func checkOperatorGroupAnnotations(obj metav1.Object, op *v1alpha2.OperatorGroup, targetNamespaces string) error {
@@ -104,7 +114,7 @@ func TestOperatorGroup(t *testing.T) {
104114
createdOtherNamespace, err := c.KubernetesInterface().CoreV1().Namespaces().Create(&otherNamespace)
105115
require.NoError(t, err)
106116

107-
oldCommand := patchOlmDeployment(t, c, otherNamespaceName)
117+
cleanupOlmDeployment := patchOlmDeployment(t, c, otherNamespaceName)
108118

109119
t.Log("Creating CRD")
110120
mainCRDPlural := genName("ins")
@@ -231,27 +241,14 @@ func TestOperatorGroup(t *testing.T) {
231241
require.NoError(t, err)
232242

233243
t.Log("Waiting for orphaned CSV to be deleted")
234-
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
244+
err = waitForDelete(func() error {
235245
_, 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
243247
})
244248
require.NoError(t, err)
245249

246250
// 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()
255252
require.NoError(t, err)
256253

257254
cleanupCRD()

0 commit comments

Comments
 (0)