@@ -18,6 +18,7 @@ package framework
18
18
19
19
import (
20
20
"context"
21
+ "path/filepath"
21
22
22
23
. "github.com/onsi/ginkgo/v2"
23
24
. "github.com/onsi/gomega"
@@ -159,21 +160,39 @@ func DeleteCluster(ctx context.Context, input DeleteClusterInput) {
159
160
160
161
// WaitForClusterDeletedInput is the input for WaitForClusterDeleted.
161
162
type WaitForClusterDeletedInput struct {
162
- Getter Getter
163
+ Client client. Client
163
164
Cluster * clusterv1.Cluster
165
+ // ArtifactFolder, if set, clusters will be dumped if deletion times out
166
+ ArtifactFolder string
164
167
}
165
168
166
169
// WaitForClusterDeleted waits until the cluster object has been deleted.
167
170
func WaitForClusterDeleted (ctx context.Context , input WaitForClusterDeletedInput , intervals ... interface {}) {
168
171
Byf ("Waiting for cluster %s to be deleted" , klog .KObj (input .Cluster ))
172
+ // Note: dumpArtifactsOnDeletionTimeout is passed in as a func so it gets only executed if and after the Eventually failed.
169
173
Eventually (func () bool {
170
174
cluster := & clusterv1.Cluster {}
171
175
key := client.ObjectKey {
172
176
Namespace : input .Cluster .GetNamespace (),
173
177
Name : input .Cluster .GetName (),
174
178
}
175
- return apierrors .IsNotFound (input .Getter .Get (ctx , key , cluster ))
176
- }, intervals ... ).Should (BeTrue ())
179
+ return apierrors .IsNotFound (input .Client .Get (ctx , key , cluster ))
180
+ }, intervals ... ).Should (BeTrue (), func () string {
181
+ return dumpArtifactsOnDeletionTimeout (ctx , input .Client , input .Cluster , input .ArtifactFolder )
182
+ })
183
+ }
184
+
185
+ func dumpArtifactsOnDeletionTimeout (ctx context.Context , client client.Client , cluster * clusterv1.Cluster , artifactFolder string ) string {
186
+ if artifactFolder != "" {
187
+ // Dump all Cluster API related resources to artifacts.
188
+ DumpAllResources (ctx , DumpAllResourcesInput {
189
+ Lister : client ,
190
+ Namespace : cluster .Namespace ,
191
+ LogPath : filepath .Join (artifactFolder , "clusters-afterDeletionTimedOut" , cluster .Name , "resources" ),
192
+ })
193
+ }
194
+
195
+ return "waiting for cluster deletion timed out"
177
196
}
178
197
179
198
// DiscoveryAndWaitForClusterInput is the input type for DiscoveryAndWaitForCluster.
@@ -214,6 +233,8 @@ func DiscoveryAndWaitForCluster(ctx context.Context, input DiscoveryAndWaitForCl
214
233
type DeleteClusterAndWaitInput struct {
215
234
Client client.Client
216
235
Cluster * clusterv1.Cluster
236
+ // ArtifactFolder, if set, clusters will be dumped if deletion times out
237
+ ArtifactFolder string
217
238
}
218
239
219
240
// DeleteClusterAndWait deletes a cluster object and waits for it to be gone.
@@ -228,10 +249,7 @@ func DeleteClusterAndWait(ctx context.Context, input DeleteClusterAndWaitInput,
228
249
})
229
250
230
251
log .Logf ("Waiting for the Cluster object to be deleted" )
231
- WaitForClusterDeleted (ctx , WaitForClusterDeletedInput {
232
- Getter : input .Client ,
233
- Cluster : input .Cluster ,
234
- }, intervals ... )
252
+ WaitForClusterDeleted (ctx , WaitForClusterDeletedInput (input ), intervals ... )
235
253
236
254
//TODO: consider if to move in another func (what if there are more than one cluster?)
237
255
log .Logf ("Check for all the Cluster API resources being deleted" )
@@ -247,6 +265,8 @@ func DeleteClusterAndWait(ctx context.Context, input DeleteClusterAndWaitInput,
247
265
type DeleteAllClustersAndWaitInput struct {
248
266
Client client.Client
249
267
Namespace string
268
+ // ArtifactFolder, if set, clusters will be dumped if deletion times out
269
+ ArtifactFolder string
250
270
}
251
271
252
272
// DeleteAllClustersAndWait deletes a cluster object and waits for it to be gone.
@@ -270,8 +290,9 @@ func DeleteAllClustersAndWait(ctx context.Context, input DeleteAllClustersAndWai
270
290
for _ , c := range clusters {
271
291
log .Logf ("Waiting for the Cluster %s to be deleted" , klog .KObj (c ))
272
292
WaitForClusterDeleted (ctx , WaitForClusterDeletedInput {
273
- Getter : input .Client ,
274
- Cluster : c ,
293
+ Client : input .Client ,
294
+ Cluster : c ,
295
+ ArtifactFolder : input .ArtifactFolder ,
275
296
}, intervals ... )
276
297
}
277
298
}
0 commit comments