@@ -71,8 +71,17 @@ func setupSpecNamespace(ctx context.Context, specName string, clusterProxy frame
7171}
7272
7373func 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
105114func redactLogs () {
0 commit comments