Skip to content

Commit

Permalink
dump all the resource info before clearing it out
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Oct 12, 2023
1 parent 6b8bfc4 commit de5302b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 11 additions & 4 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,23 @@ func setupSpecNamespace(ctx context.Context, specName string, clusterProxy frame
return namespace, cancelWatches
}

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) {
// dumpAllResources dumps all the resources in the spec namespace and the workload cluster.
func dumpAllResources(ctx context.Context, clusterProxy framework.ClusterProxy, artifactFolder string, namespace *corev1.Namespace, cluster *clusterv1.Cluster) {
Byf("Dumping logs from the %q workload cluster", cluster.Name)

// Dump all the logs from the workload cluster before deleting them.
// Dump all the logs from the workload cluster.
clusterProxy.CollectWorkloadClusterLogs(ctx, cluster.Namespace, cluster.Name, filepath.Join(artifactFolder, "clusters", cluster.Name))

Byf("Dumping all the Cluster API resources in the %q namespace", namespace.Name)

// Dump all Cluster API related resources to artifacts before deleting them.
// Dump all Cluster API related resources to artifacts.
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
Lister: clusterProxy.GetClient(),
Namespace: namespace.Name,
LogPath: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName(), "resources"),
})

// If the cluster still exists, dump pods and nodes of the workload cluster before deleting the cluster.
// If the cluster still exists, dump pods and nodes of the workload cluster.
if err := clusterProxy.GetClient().Get(ctx, client.ObjectKeyFromObject(cluster), &clusterv1.Cluster{}); err == nil {
Byf("Dumping Pods and Nodes of Cluster %s", klog.KObj(cluster))
framework.DumpResourcesForCluster(ctx, framework.DumpResourcesForClusterInput{
Expand All @@ -103,6 +104,12 @@ func dumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterPr
},
})
}
}

// dumpSpecResourcesAndCleanup dumps all the resources in the spec namespace and cleans up the spec namespace.
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) {
// Dump all the resources in the spec namespace and the workload cluster.
dumpAllResources(ctx, clusterProxy, artifactFolder, namespace, cluster)

if !skipCleanup {
Byf("Deleting cluster %s", klog.KObj(cluster))
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/self_hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
AfterEach(func() {
if selfHostedNamespace != nil {
// Dump all Cluster API related resources to artifacts before pivoting back.
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
Lister: selfHostedClusterProxy.GetClient(),
Namespace: namespace.Name,
LogPath: filepath.Join(input.ArtifactFolder, "clusters", clusterResources.Cluster.Name, "resources"),
})
dumpAllResources(ctx, selfHostedClusterProxy, input.ArtifactFolder, namespace, clusterResources.Cluster)
}
if selfHostedCluster != nil {
By("Ensure API servers are stable before doing move")
Expand Down

0 comments on commit de5302b

Please sign in to comment.