Skip to content

Commit b5020e5

Browse files
committed
Dump cluster resources if deletion times out
Signed-off-by: Stefan Büringer [email protected]
1 parent eba0375 commit b5020e5

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

test/e2e/cluster_upgrade_runtimesdk.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
312312
// that cluster variable is not set even if the cluster exists, so we are calling DeleteAllClustersAndWait
313313
// instead of DeleteClusterAndWait
314314
framework.DeleteAllClustersAndWait(ctx, framework.DeleteAllClustersAndWaitInput{
315-
Client: input.BootstrapClusterProxy.GetClient(),
316-
Namespace: namespace.Name,
315+
Client: input.BootstrapClusterProxy.GetClient(),
316+
Namespace: namespace.Name,
317+
ArtifactFolder: input.ArtifactFolder,
317318
}, input.E2EConfig.GetIntervals(specName, "wait-delete-cluster")...)
318319

319320
Byf("Deleting namespace used for hosting the %q test spec", specName)

test/e2e/scale.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func deleteClusterAndWaitWorker(ctx context.Context, inputChan <-chan string, re
679679
Cluster: cluster,
680680
})
681681
framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{
682-
Getter: c,
682+
Client: c,
683683
Cluster: cluster,
684684
})
685685

test/framework/cluster_helpers.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package framework
1818

1919
import (
2020
"context"
21+
"path/filepath"
2122

2223
. "github.com/onsi/ginkgo/v2"
2324
. "github.com/onsi/gomega"
@@ -159,21 +160,39 @@ func DeleteCluster(ctx context.Context, input DeleteClusterInput) {
159160

160161
// WaitForClusterDeletedInput is the input for WaitForClusterDeleted.
161162
type WaitForClusterDeletedInput struct {
162-
Getter Getter
163+
Client client.Client
163164
Cluster *clusterv1.Cluster
165+
// ArtifactFolder, if set, clusters will be dumped if deletion times out
166+
ArtifactFolder string
164167
}
165168

166169
// WaitForClusterDeleted waits until the cluster object has been deleted.
167170
func WaitForClusterDeleted(ctx context.Context, input WaitForClusterDeletedInput, intervals ...interface{}) {
168171
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.
169173
Eventually(func() bool {
170174
cluster := &clusterv1.Cluster{}
171175
key := client.ObjectKey{
172176
Namespace: input.Cluster.GetNamespace(),
173177
Name: input.Cluster.GetName(),
174178
}
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"
177196
}
178197

179198
// DiscoveryAndWaitForClusterInput is the input type for DiscoveryAndWaitForCluster.
@@ -214,6 +233,8 @@ func DiscoveryAndWaitForCluster(ctx context.Context, input DiscoveryAndWaitForCl
214233
type DeleteClusterAndWaitInput struct {
215234
Client client.Client
216235
Cluster *clusterv1.Cluster
236+
// ArtifactFolder, if set, clusters will be dumped if deletion times out
237+
ArtifactFolder string
217238
}
218239

219240
// DeleteClusterAndWait deletes a cluster object and waits for it to be gone.
@@ -228,10 +249,7 @@ func DeleteClusterAndWait(ctx context.Context, input DeleteClusterAndWaitInput,
228249
})
229250

230251
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...)
235253

236254
//TODO: consider if to move in another func (what if there are more than one cluster?)
237255
log.Logf("Check for all the Cluster API resources being deleted")
@@ -247,6 +265,8 @@ func DeleteClusterAndWait(ctx context.Context, input DeleteClusterAndWaitInput,
247265
type DeleteAllClustersAndWaitInput struct {
248266
Client client.Client
249267
Namespace string
268+
// ArtifactFolder, if set, clusters will be dumped if deletion times out
269+
ArtifactFolder string
250270
}
251271

252272
// DeleteAllClustersAndWait deletes a cluster object and waits for it to be gone.
@@ -270,8 +290,9 @@ func DeleteAllClustersAndWait(ctx context.Context, input DeleteAllClustersAndWai
270290
for _, c := range clusters {
271291
log.Logf("Waiting for the Cluster %s to be deleted", klog.KObj(c))
272292
WaitForClusterDeleted(ctx, WaitForClusterDeletedInput{
273-
Getter: input.Client,
274-
Cluster: c,
293+
Client: input.Client,
294+
Cluster: c,
295+
ArtifactFolder: input.ArtifactFolder,
275296
}, intervals...)
276297
}
277298
}

test/framework/spec_helpers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ func DumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterPr
106106
// that cluster variable is not set even if the cluster exists, so we are calling DeleteAllClustersAndWait
107107
// instead of DeleteClusterAndWait
108108
DeleteAllClustersAndWait(ctx, DeleteAllClustersAndWaitInput{
109-
Client: clusterProxy.GetClient(),
110-
Namespace: namespace.Name,
109+
Client: clusterProxy.GetClient(),
110+
Namespace: namespace.Name,
111+
ArtifactFolder: artifactFolder,
111112
}, intervalsGetter(specName, "wait-delete-cluster")...)
112113

113114
byf("Deleting namespace used for hosting the %q test spec", specName)

0 commit comments

Comments
 (0)