@@ -90,9 +90,6 @@ func (suite *BaseSuite) SetupTest() {
90
90
project := & argoapp.AppProject {}
91
91
key := types.NamespacedName {Name : "agent-autonomous-default" , Namespace : "argocd" }
92
92
err := suite .PrincipalClient .Get (suite .Ctx , key , project , metav1.GetOptions {})
93
- if err != nil {
94
- suite .T ().Log (err )
95
- }
96
93
return err == nil && len (project .Annotations ) > 0 && project .Annotations ["created" ] == now
97
94
}, 30 * time .Second , 1 * time .Second )
98
95
@@ -107,19 +104,19 @@ func (suite *BaseSuite) TearDownTest() {
107
104
108
105
// EnsureDeletion will issue a delete for a namespace-scoped K8s resource, then wait for it to no longer exist
109
106
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
-
118
107
// Wait for the object to be deleted for 60 seconds
119
108
// - Primarily this will be waiting for the finalizer to be removed, so that the object is deleted
120
109
key := types.NamespacedName {Name : obj .GetName (), Namespace : obj .GetNamespace ()}
121
110
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 {})
123
120
if errors .IsNotFound (err ) {
124
121
return nil
125
122
} else if err == nil {
@@ -161,27 +158,27 @@ func CleanUp(ctx context.Context, principalClient KubeClient, managedAgentClient
161
158
// Remove any previously configured env variables from the config file
162
159
os .Remove (EnvVariablesFromE2EFile )
163
160
164
- // Delete all managed applications from the principal
161
+ // Delete all applications from the autonomous agent
165
162
list = argoapp.ApplicationList {}
166
- err = principalClient .List (ctx , "agent-managed " , & list , metav1.ListOptions {})
163
+ err = autonomousAgentClient .List (ctx , "argocd " , & list , metav1.ListOptions {})
167
164
if err != nil {
168
165
return err
169
166
}
170
167
for _ , app := range list .Items {
171
- err = EnsureDeletion (ctx , principalClient , & app )
168
+ err = EnsureDeletion (ctx , autonomousAgentClient , & app )
172
169
if err != nil {
173
170
return err
174
171
}
175
172
}
176
173
177
- // Delete all applications from the autonomous agent
174
+ // Delete all managed applications from the principal
178
175
list = argoapp.ApplicationList {}
179
- err = autonomousAgentClient .List (ctx , "argocd " , & list , metav1.ListOptions {})
176
+ err = principalClient .List (ctx , "agent-managed " , & list , metav1.ListOptions {})
180
177
if err != nil {
181
178
return err
182
179
}
183
180
for _ , app := range list .Items {
184
- err = EnsureDeletion (ctx , autonomousAgentClient , & app )
181
+ err = EnsureDeletion (ctx , principalClient , & app )
185
182
if err != nil {
186
183
return err
187
184
}
@@ -213,33 +210,33 @@ func CleanUp(ctx context.Context, principalClient KubeClient, managedAgentClient
213
210
}
214
211
}
215
212
216
- // Delete all appProjects from the principal
213
+ // Delete all appProjects from the autonomous agent
217
214
appProjectList := argoapp.AppProjectList {}
218
- err = principalClient .List (ctx , "argocd" , & appProjectList , metav1.ListOptions {})
215
+ err = autonomousAgentClient .List (ctx , "argocd" , & appProjectList , metav1.ListOptions {})
219
216
if err != nil {
220
217
return err
221
218
}
222
219
for _ , appProject := range appProjectList .Items {
223
220
if appProject .Name == appproject .DefaultAppProjectName {
224
221
continue
225
222
}
226
- err = EnsureDeletion (ctx , principalClient , & appProject )
223
+ err = EnsureDeletion (ctx , autonomousAgentClient , & appProject )
227
224
if err != nil {
228
225
return err
229
226
}
230
227
}
231
228
232
- // Delete all appProjects from the autonomous agent
229
+ // Delete all appProjects from the principal
233
230
appProjectList = argoapp.AppProjectList {}
234
- err = autonomousAgentClient .List (ctx , "argocd" , & appProjectList , metav1.ListOptions {})
231
+ err = principalClient .List (ctx , "argocd" , & appProjectList , metav1.ListOptions {})
235
232
if err != nil {
236
233
return err
237
234
}
238
235
for _ , appProject := range appProjectList .Items {
239
236
if appProject .Name == appproject .DefaultAppProjectName {
240
237
continue
241
238
}
242
- err = EnsureDeletion (ctx , autonomousAgentClient , & appProject )
239
+ err = EnsureDeletion (ctx , principalClient , & appProject )
243
240
if err != nil {
244
241
return err
245
242
}
0 commit comments