Skip to content

Commit 99a0489

Browse files
authored
Merge pull request #1057 from mboersma/always-never-always-do-the-right-thing
💚 check for cluster == nil before dumping logs and deleting
2 parents 9a0a059 + 3004a5e commit 99a0489

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

test/e2e/common.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ func setupSpecNamespace(ctx context.Context, specName string, clusterProxy frame
7171
}
7272

7373
func dumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterProxy framework.ClusterProxy, artifactFolder string, namespace *corev1.Namespace, cancelWatches context.CancelFunc, cluster *clusterv1.Cluster, intervalsGetter func(spec, key string) []interface{}, skipCleanup bool) {
74-
Byf("Dumping logs from the %q workload cluster", cluster.Name)
75-
clusterProxy.CollectWorkloadClusterLogs(ctx, cluster.Namespace, cluster.Name, filepath.Join(artifactFolder, "clusters", cluster.Name, "machines"))
74+
defer func() {
75+
cancelWatches()
76+
redactLogs()
77+
}()
78+
79+
if cluster == nil {
80+
By("Unable to dump workload cluster logs as the cluster is nil")
81+
} else {
82+
Byf("Dumping logs from the %q workload cluster", cluster.Name)
83+
clusterProxy.CollectWorkloadClusterLogs(ctx, cluster.Namespace, cluster.Name, filepath.Join(artifactFolder, "clusters", cluster.Name, "machines"))
84+
}
7685

7786
Byf("Dumping all the Cluster API resources in the %q namespace", namespace.Name)
7887
// Dump all Cluster API related resources to artifacts before deleting them.
@@ -82,24 +91,24 @@ func dumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterPr
8291
LogPath: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName(), "resources"),
8392
})
8493

85-
if !skipCleanup {
86-
Byf("Deleting cluster %s/%s", cluster.Namespace, cluster.Name)
87-
// While https://github.com/kubernetes-sigs/cluster-api/issues/2955 is addressed in future iterations, there is a chance
88-
// that cluster variable is not set even if the cluster exists, so we are calling DeleteAllClustersAndWait
89-
// instead of DeleteClusterAndWait
90-
framework.DeleteAllClustersAndWait(ctx, framework.DeleteAllClustersAndWaitInput{
91-
Client: clusterProxy.GetClient(),
92-
Namespace: namespace.Name,
93-
}, intervalsGetter(specName, "wait-delete-cluster")...)
94-
95-
Byf("Deleting namespace used for hosting the %q test spec", specName)
96-
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
97-
Deleter: clusterProxy.GetClient(),
98-
Name: namespace.Name,
99-
})
94+
if skipCleanup {
95+
return
10096
}
101-
cancelWatches()
102-
redactLogs()
97+
98+
Byf("Deleting all clusters in the %s namespace", namespace.Name)
99+
// While https://github.com/kubernetes-sigs/cluster-api/issues/2955 is addressed in future iterations, there is a chance
100+
// that cluster variable is not set even if the cluster exists, so we are calling DeleteAllClustersAndWait
101+
// instead of DeleteClusterAndWait
102+
framework.DeleteAllClustersAndWait(ctx, framework.DeleteAllClustersAndWaitInput{
103+
Client: clusterProxy.GetClient(),
104+
Namespace: namespace.Name,
105+
}, intervalsGetter(specName, "wait-delete-cluster")...)
106+
107+
Byf("Deleting namespace used for hosting the %q test spec", specName)
108+
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
109+
Deleter: clusterProxy.GetClient(),
110+
Name: namespace.Name,
111+
})
103112
}
104113

105114
func redactLogs() {

0 commit comments

Comments
 (0)