Skip to content

Commit 57ad73d

Browse files
Improve logging in e2e tests
Signed-off-by: Muhammad Adil Ghaffar <[email protected]>
1 parent 69c9cae commit 57ad73d

File tree

5 files changed

+52
-93
lines changed

5 files changed

+52
-93
lines changed

scripts/fetch_manifests.sh

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/e2e/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func DumpSpecResourcesAndCleanup(ctx context.Context, specName string, bootstrap
142142
bootstrapClusterProxy.CollectWorkloadClusterLogs(ctx, namespace, clusterName, artifactFolder)
143143

144144
By("Fetch logs from target cluster")
145-
err := FetchClusterLogs(targetClusterProxy, clusterLogCollectionBasePath)
145+
err := FetchClusterLogs(targetClusterProxy, filepath.Join(artifactFolder, workloadClusterLogCollectionBasePath, targetClusterProxy.GetName(), "final-logs"))
146146
if err != nil {
147147
Logf("Error: %v", err)
148148
}

test/e2e/logcollector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func FetchManifests(clusterProxy framework.ClusterProxy, outputPath string) erro
159159
"m3data",
160160
"m3dataclaim",
161161
"m3datatemplate",
162+
"ironic",
162163
}
163164
client := clusterProxy.GetClient()
164165

test/e2e/pivoting.go

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
. "github.com/onsi/gomega"
1717
corev1 "k8s.io/api/core/v1"
1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19-
"k8s.io/apimachinery/pkg/runtime"
2019
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2120
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
2221
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
@@ -26,17 +25,18 @@ import (
2625
)
2726

2827
const (
29-
bmoPath = "BMOPATH"
30-
ironicTLSSetup = "IRONIC_TLS_SETUP"
31-
ironicBasicAuth = "IRONIC_BASIC_AUTH"
32-
ironicKeepalived = "IRONIC_KEEPALIVED"
33-
ironicMariadb = "IRONIC_USE_MARIADB"
34-
Kind = "kind"
35-
NamePrefix = "NAMEPREFIX"
36-
restartContainerCertUpdate = "RESTART_CONTAINER_CERTIFICATE_UPDATED"
37-
ironicNamespace = "IRONIC_NAMESPACE"
38-
clusterLogCollectionBasePath = "/tmp/target_cluster_logs"
39-
Metal3ipamProviderName = "metal3"
28+
bmoPath = "BMOPATH"
29+
ironicTLSSetup = "IRONIC_TLS_SETUP"
30+
ironicBasicAuth = "IRONIC_BASIC_AUTH"
31+
ironicKeepalived = "IRONIC_KEEPALIVED"
32+
ironicMariadb = "IRONIC_USE_MARIADB"
33+
Kind = "kind"
34+
NamePrefix = "NAMEPREFIX"
35+
restartContainerCertUpdate = "RESTART_CONTAINER_CERTIFICATE_UPDATED"
36+
ironicNamespace = "IRONIC_NAMESPACE"
37+
workloadClusterLogCollectionBasePath = "workload_cluster_logs"
38+
bootstrapClusterLogCollectionBasePath = "bootstrap_cluster_logs"
39+
Metal3ipamProviderName = "metal3"
4040
)
4141

4242
type PivotingInput struct {
@@ -64,7 +64,13 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
6464
ListNodes(ctx, input.TargetCluster.GetClient())
6565

6666
By("Fetch logs from target cluster before pivot")
67-
err := FetchClusterLogs(input.TargetCluster, filepath.Join(clusterLogCollectionBasePath, "beforePivot"))
67+
err := FetchClusterLogs(input.TargetCluster, filepath.Join(input.ArtifactFolder, workloadClusterLogCollectionBasePath, input.TargetCluster.GetName(), "beforePivot"))
68+
if err != nil {
69+
Logf("Error: %v", err)
70+
}
71+
72+
By("Fetch logs from bootstrap cluster before pivot")
73+
err = FetchClusterLogs(input.BootstrapClusterProxy, filepath.Join(input.ArtifactFolder, bootstrapClusterLogCollectionBasePath, "beforePivot"))
6874
if err != nil {
6975
Logf("Error: %v", err)
7076
}
@@ -83,17 +89,20 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
8389
}
8490

8591
By("Fetch container logs")
86-
bootstrapCluster := os.Getenv("BOOTSTRAP_CLUSTER")
8792
fetchContainerLogs(&generalContainers, input.ArtifactFolder, input.E2EConfig.MustGetVariable("CONTAINER_RUNTIME"))
88-
if bootstrapCluster == Kind {
93+
if input.BootstrapClusterProxy.GetName() == Kind {
8994
fetchContainerLogs(&ironicContainers, input.ArtifactFolder, input.E2EConfig.MustGetVariable("CONTAINER_RUNTIME"))
9095
}
9196

9297
By("Fetch manifest for bootstrap cluster before pivot")
93-
err = FetchManifests(input.BootstrapClusterProxy, "/tmp/manifests/")
98+
err = FetchManifests(input.BootstrapClusterProxy, filepath.Join(input.ArtifactFolder, bootstrapClusterLogCollectionBasePath, "beforePivot", "manifests"))
9499
if err != nil {
95100
Logf("Error fetching manifests for bootstrap cluster before pivot: %v", err)
96101
}
102+
err = FetchManifests(input.TargetCluster, filepath.Join(input.ArtifactFolder, workloadClusterLogCollectionBasePath, input.TargetCluster.GetName(), "beforePivot", "manifests"))
103+
if err != nil {
104+
Logf("Error fetching manifests for Target cluster before pivot: %v", err)
105+
}
97106
By("Fetch target cluster kubeconfig for target cluster log collection")
98107
kconfigPathWorkload := input.TargetCluster.GetKubeconfigPath()
99108
os.Setenv("KUBECONFIG_WORKLOAD", kconfigPathWorkload)
@@ -109,7 +118,7 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
109118

110119
By("Remove Ironic containers from the source cluster")
111120
ironicDeploymentType := IronicDeploymentTypeBMO
112-
if bootstrapCluster == Kind {
121+
if input.BootstrapClusterProxy.GetName() == Kind {
113122
ironicDeploymentType = IronicDeploymentTypeLocal
114123
} else if GetBoolVariable(input.E2EConfig, "USE_IRSO") {
115124
ironicDeploymentType = IronicDeploymentTypeIrSO
@@ -368,18 +377,25 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
368377
numberOfAllBmh := numberOfWorkers + numberOfControlplane
369378

370379
By("Fetch logs from target cluster after pivot")
371-
err := FetchClusterLogs(input.TargetCluster, filepath.Join(clusterLogCollectionBasePath, "afterPivot"))
380+
err := FetchClusterLogs(input.TargetCluster, filepath.Join(input.ArtifactFolder, workloadClusterLogCollectionBasePath, input.TargetCluster.GetName(), "afterPivot"))
381+
if err != nil {
382+
Logf("Error: %v", err)
383+
}
384+
By("Fetch logs from bootstrap cluster after pivot")
385+
err = FetchClusterLogs(input.BootstrapClusterProxy, filepath.Join(input.ArtifactFolder, bootstrapClusterLogCollectionBasePath, "afterPivot"))
372386
if err != nil {
373387
Logf("Error: %v", err)
374388
}
375389

376390
By("Fetch manifest for workload cluster after pivot")
377-
workloadClusterProxy := framework.NewClusterProxy("workload-cluster-after-pivot", os.Getenv("KUBECONFIG"), runtime.NewScheme())
378-
err = FetchManifests(workloadClusterProxy, "/tmp/manifests/")
391+
err = FetchManifests(input.TargetCluster, filepath.Join(input.ArtifactFolder, workloadClusterLogCollectionBasePath, input.TargetCluster.GetName(), "afterPivot", "manifests"))
379392
if err != nil {
380393
Logf("Error fetching manifests for workload cluster after pivot: %v", err)
381394
}
382-
os.Unsetenv("KUBECONFIG_WORKLOAD")
395+
err = FetchManifests(input.BootstrapClusterProxy, filepath.Join(input.ArtifactFolder, bootstrapClusterLogCollectionBasePath, "afterPivot", "manifests"))
396+
if err != nil {
397+
Logf("Error fetching manifests for bootstrap cluster before pivot: %v", err)
398+
}
383399

384400
By("Remove Ironic deployment from target cluster")
385401
ironicDeploymentType := IronicDeploymentTypeBMO
@@ -497,7 +513,11 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
497513
})
498514

499515
By("Fetch manifest for bootstrap cluster after re-pivot")
500-
err = FetchManifests(input.BootstrapClusterProxy, "/tmp/manifests/")
516+
err = FetchManifests(input.TargetCluster, filepath.Join(input.ArtifactFolder, workloadClusterLogCollectionBasePath, input.TargetCluster.GetName(), "afterRePivot", "manifests"))
517+
if err != nil {
518+
Logf("Error fetching manifests for workload cluster after pivot: %v", err)
519+
}
520+
err = FetchManifests(input.BootstrapClusterProxy, filepath.Join(input.ArtifactFolder, bootstrapClusterLogCollectionBasePath, "afterRePivot", "manifests"))
501521
if err != nil {
502522
Logf("Error fetching manifests for bootstrap cluster before pivot: %v", err)
503523
}

test/e2e/upgrade_clusterctl_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ func preInitFunc(clusterProxy framework.ClusterProxy, bmoRelease string, ironicR
297297
Expect(clusterProxy.GetClientSet().CoreV1().Namespaces().Delete(ctx, "test", metav1.DeleteOptions{})).To(Succeed())
298298
}
299299

300-
By("Fetch manifest for bootstrap cluster")
301-
err := FetchManifests(clusterProxy, "/tmp/manifests/")
300+
err := FetchManifests(clusterProxy, filepath.Join(artifactFolder, bootstrapClusterLogCollectionBasePath, clusterProxy.GetName(), "manifests"))
302301
if err != nil {
303-
Logf("Error fetching manifests for bootstrap cluster: %v", err)
302+
Logf("Error fetching manifests from cluster: %s error: %v", clusterProxy.GetName(), err)
304303
}
305304

306305
By("Fetch target cluster kubeconfig for target cluster log collection")
@@ -333,7 +332,7 @@ func preInitFunc(clusterProxy framework.ClusterProxy, bmoRelease string, ironicR
333332
bmoIronicNamespace := e2eConfig.MustGetVariable(ironicNamespace)
334333
// install ironic
335334
By("Install Ironic in the target cluster")
336-
ironicDeployLogFolder := filepath.Join(clusterLogCollectionBasePath, clusterProxy.GetName(), "ironic-deploy-logs")
335+
ironicDeployLogFolder := filepath.Join(workloadClusterLogCollectionBasePath, clusterProxy.GetName(), "ironic-deploy-logs")
337336
ironicKustomizePath := "IRONIC_RELEASE_" + ironicRelease
338337
initIronicKustomization := e2eConfig.MustGetVariable(ironicKustomizePath)
339338
By(fmt.Sprintf("Installing Ironic from kustomization %s on the upgrade cluster", initIronicKustomization))
@@ -351,7 +350,7 @@ func preInitFunc(clusterProxy framework.ClusterProxy, bmoRelease string, ironicR
351350

352351
// install bmo
353352
By("Install BMO in the target cluster")
354-
bmoDeployLogFolder := filepath.Join(clusterLogCollectionBasePath, clusterProxy.GetName(), "bmo-deploy-logs")
353+
bmoDeployLogFolder := filepath.Join(workloadClusterLogCollectionBasePath, clusterProxy.GetName(), "bmo-deploy-logs")
355354
bmoKustomizePath := "BMO_RELEASE_" + bmoRelease
356355
initBMOKustomization := e2eConfig.MustGetVariable(bmoKustomizePath)
357356
By(fmt.Sprintf("Installing BMO from kustomization %s on the upgrade cluster", initBMOKustomization))
@@ -396,7 +395,7 @@ func preUpgrade(clusterProxy framework.ClusterProxy, bmoUpgradeToRelease string,
396395

397396
bmoIronicNamespace := e2eConfig.MustGetVariable(ironicNamespace)
398397
By("Upgrade Ironic in the target cluster")
399-
ironicDeployLogFolder := filepath.Join(clusterLogCollectionBasePath, clusterProxy.GetName(), "ironic-deploy-logs")
398+
ironicDeployLogFolder := filepath.Join(workloadClusterLogCollectionBasePath, clusterProxy.GetName(), "ironic-deploy-logs")
400399
ironicKustomizePath := "IRONIC_RELEASE_" + ironicTag
401400
initIronicKustomization := e2eConfig.MustGetVariable(ironicKustomizePath)
402401
By(fmt.Sprintf("Upgrading Ironic from kustomization %s on the upgrade cluster", initIronicKustomization))
@@ -414,7 +413,7 @@ func preUpgrade(clusterProxy framework.ClusterProxy, bmoUpgradeToRelease string,
414413

415414
// install bmo
416415
By("Upgrade BMO in the target cluster")
417-
bmoDeployLogFolder := filepath.Join(clusterLogCollectionBasePath, clusterProxy.GetName(), "bmo-deploy-logs")
416+
bmoDeployLogFolder := filepath.Join(workloadClusterLogCollectionBasePath, clusterProxy.GetName(), "bmo-deploy-logs")
418417
bmoKustomizePath := "BMO_RELEASE_" + bmoTag
419418
initBMOKustomization := e2eConfig.MustGetVariable(bmoKustomizePath)
420419
By(fmt.Sprintf("Upgrading BMO from kustomization %s on the upgrade cluster", initBMOKustomization))
@@ -435,7 +434,7 @@ func preUpgrade(clusterProxy framework.ClusterProxy, bmoUpgradeToRelease string,
435434
// when upgrading from CAPM3 bundled IPAM.
436435
func postUpgrade(managementClusterProxy framework.ClusterProxy, _ string, _ string) {
437436
By("Installing Metal3 IPAM provider")
438-
ipamDeployLogFolder := filepath.Join(clusterLogCollectionBasePath, managementClusterProxy.GetName(), "ipam-deploy-logs")
437+
ipamDeployLogFolder := filepath.Join(workloadClusterLogCollectionBasePath, managementClusterProxy.GetName(), "ipam-deploy-logs")
439438
ipamVersions := e2eConfig.GetProviderLatestVersionsByContract(capm3Contract, e2eConfig.IPAMProviders()...)
440439
Expect(ipamVersions).To(HaveLen(1), "Failed to get the latest version for the IPAM provider")
441440
input := clusterctl.InitInput{
@@ -451,7 +450,7 @@ func postUpgrade(managementClusterProxy framework.ClusterProxy, _ string, _ stri
451450
// it moves back Ironic to the bootstrap cluster.
452451
func preCleanupManagementCluster(clusterProxy framework.ClusterProxy, ironicRelease string) {
453452
By("Fetch logs from target cluster")
454-
err := FetchClusterLogs(clusterProxy, clusterLogCollectionBasePath)
453+
err := FetchClusterLogs(clusterProxy, filepath.Join(artifactFolder, workloadClusterLogCollectionBasePath, clusterProxy.GetName()))
455454
if err != nil {
456455
Logf("Error: %v", err)
457456
}

0 commit comments

Comments
 (0)