Skip to content

Commit 7f6d6e6

Browse files
authored
test(e2e): Restore idempotency of e2e tests (#557)
Signed-off-by: jannfis <[email protected]>
1 parent f1c6429 commit 7f6d6e6

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

test/e2e/fixture/argoclient.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func (c *ArgoRestClient) ListApplications() (*v1alpha1.ApplicationList, error) {
432432
func (c *ArgoRestClient) DeleteApplication(name string) error {
433433
reqURL := c.url()
434434
reqURL.Path = fmt.Sprintf("/api/v1/applications/%s", name)
435+
reqURL.RawQuery = "cascade=false"
435436

436437
req, err := http.NewRequest(http.MethodDelete, reqURL.String(), nil)
437438
if err != nil {

test/e2e/fixture/fixture.go

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ func (suite *BaseSuite) SetupTest() {
9090
project := &argoapp.AppProject{}
9191
key := types.NamespacedName{Name: "agent-autonomous-default", Namespace: "argocd"}
9292
err := suite.PrincipalClient.Get(suite.Ctx, key, project, metav1.GetOptions{})
93-
if err != nil {
94-
suite.T().Log(err)
95-
}
9693
return err == nil && len(project.Annotations) > 0 && project.Annotations["created"] == now
9794
}, 30*time.Second, 1*time.Second)
9895

@@ -107,19 +104,19 @@ func (suite *BaseSuite) TearDownTest() {
107104

108105
// EnsureDeletion will issue a delete for a namespace-scoped K8s resource, then wait for it to no longer exist
109106
func EnsureDeletion(ctx context.Context, kclient KubeClient, obj KubeObject) error {
110-
err := kclient.Delete(ctx, obj, metav1.DeleteOptions{})
111-
if errors.IsNotFound(err) {
112-
// object is already deleted
113-
return nil
114-
} else if err != nil {
115-
return err
116-
}
117-
118107
// Wait for the object to be deleted for 60 seconds
119108
// - Primarily this will be waiting for the finalizer to be removed, so that the object is deleted
120109
key := types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}
121110
for count := 0; count < 60; count++ {
122-
err := kclient.Get(ctx, key, obj, metav1.GetOptions{})
111+
err := kclient.Delete(ctx, obj, metav1.DeleteOptions{})
112+
if errors.IsNotFound(err) {
113+
// object is already deleted
114+
return nil
115+
} else if err != nil {
116+
return err
117+
}
118+
119+
err = kclient.Get(ctx, key, obj, metav1.GetOptions{})
123120
if errors.IsNotFound(err) {
124121
return nil
125122
} else if err == nil {
@@ -161,27 +158,27 @@ func CleanUp(ctx context.Context, principalClient KubeClient, managedAgentClient
161158
// Remove any previously configured env variables from the config file
162159
os.Remove(EnvVariablesFromE2EFile)
163160

164-
// Delete all managed applications from the principal
161+
// Delete all applications from the autonomous agent
165162
list = argoapp.ApplicationList{}
166-
err = principalClient.List(ctx, "agent-managed", &list, metav1.ListOptions{})
163+
err = autonomousAgentClient.List(ctx, "argocd", &list, metav1.ListOptions{})
167164
if err != nil {
168165
return err
169166
}
170167
for _, app := range list.Items {
171-
err = EnsureDeletion(ctx, principalClient, &app)
168+
err = EnsureDeletion(ctx, autonomousAgentClient, &app)
172169
if err != nil {
173170
return err
174171
}
175172
}
176173

177-
// Delete all applications from the autonomous agent
174+
// Delete all managed applications from the principal
178175
list = argoapp.ApplicationList{}
179-
err = autonomousAgentClient.List(ctx, "argocd", &list, metav1.ListOptions{})
176+
err = principalClient.List(ctx, "agent-managed", &list, metav1.ListOptions{})
180177
if err != nil {
181178
return err
182179
}
183180
for _, app := range list.Items {
184-
err = EnsureDeletion(ctx, autonomousAgentClient, &app)
181+
err = EnsureDeletion(ctx, principalClient, &app)
185182
if err != nil {
186183
return err
187184
}
@@ -213,33 +210,33 @@ func CleanUp(ctx context.Context, principalClient KubeClient, managedAgentClient
213210
}
214211
}
215212

216-
// Delete all appProjects from the principal
213+
// Delete all appProjects from the autonomous agent
217214
appProjectList := argoapp.AppProjectList{}
218-
err = principalClient.List(ctx, "argocd", &appProjectList, metav1.ListOptions{})
215+
err = autonomousAgentClient.List(ctx, "argocd", &appProjectList, metav1.ListOptions{})
219216
if err != nil {
220217
return err
221218
}
222219
for _, appProject := range appProjectList.Items {
223220
if appProject.Name == appproject.DefaultAppProjectName {
224221
continue
225222
}
226-
err = EnsureDeletion(ctx, principalClient, &appProject)
223+
err = EnsureDeletion(ctx, autonomousAgentClient, &appProject)
227224
if err != nil {
228225
return err
229226
}
230227
}
231228

232-
// Delete all appProjects from the autonomous agent
229+
// Delete all appProjects from the principal
233230
appProjectList = argoapp.AppProjectList{}
234-
err = autonomousAgentClient.List(ctx, "argocd", &appProjectList, metav1.ListOptions{})
231+
err = principalClient.List(ctx, "argocd", &appProjectList, metav1.ListOptions{})
235232
if err != nil {
236233
return err
237234
}
238235
for _, appProject := range appProjectList.Items {
239236
if appProject.Name == appproject.DefaultAppProjectName {
240237
continue
241238
}
242-
err = EnsureDeletion(ctx, autonomousAgentClient, &appProject)
239+
err = EnsureDeletion(ctx, principalClient, &appProject)
243240
if err != nil {
244241
return err
245242
}

0 commit comments

Comments
 (0)