From 50ae30f8c88a50c6d87121a249c52dc45dc930a2 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Mon, 30 Oct 2023 13:47:24 +0000 Subject: [PATCH] Improve logging for self-hosted e2e test Signed-off-by: killianmuldoon --- test/e2e/clusterctl_upgrade.go | 10 ++-------- test/e2e/self_hosted.go | 2 +- test/framework/cluster_proxy.go | 15 ++++++++++----- test/framework/machine_helpers.go | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index ad29bb2b3663..252a710547ec 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -271,7 +271,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg } // Get a ClusterProxy so we can interact with the workload cluster - managementClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name) + managementClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name, framework.WithMachineLogCollector(framework.DockerLogCollector{})) // Download the older clusterctl version to be used for setting up the management cluster to be upgraded log.Logf("Downloading clusterctl binary from %s", initClusterctlBinaryURL) @@ -543,13 +543,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg AfterEach(func() { if testNamespace != nil { // Dump all the logs from the workload cluster before deleting them. - managementClusterProxy.CollectWorkloadClusterLogs(ctx, testNamespace.Name, managementClusterName, filepath.Join(input.ArtifactFolder, "clusters", managementClusterName, "machines")) - - framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{ - Lister: managementClusterProxy.GetClient(), - Namespace: testNamespace.Name, - LogPath: filepath.Join(input.ArtifactFolder, "clusters", managementClusterResources.Cluster.Name, "resources"), - }) + dumpAllResources(ctx, managementClusterProxy, input.ArtifactFolder, testNamespace, managementClusterResources.Cluster) if !input.SkipCleanup { switch { diff --git a/test/e2e/self_hosted.go b/test/e2e/self_hosted.go index 1934d76a2008..c0be2ca0a43c 100644 --- a/test/e2e/self_hosted.go +++ b/test/e2e/self_hosted.go @@ -187,7 +187,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput) cluster := clusterResources.Cluster // Get a ClusterBroker so we can interact with the workload cluster - selfHostedClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name) + selfHostedClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name, framework.WithMachineLogCollector(framework.DockerLogCollector{})) Byf("Creating a namespace for hosting the %s test spec", specName) selfHostedNamespace, selfHostedCancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{ diff --git a/test/framework/cluster_proxy.go b/test/framework/cluster_proxy.go index 1b840723037d..6de289af4ca0 100644 --- a/test/framework/cluster_proxy.go +++ b/test/framework/cluster_proxy.go @@ -91,7 +91,7 @@ type ClusterProxy interface { Apply(ctx context.Context, resources []byte, args ...string) error // GetWorkloadCluster returns a proxy to a workload cluster defined in the Kubernetes cluster. - GetWorkloadCluster(ctx context.Context, namespace, name string) ClusterProxy + GetWorkloadCluster(ctx context.Context, namespace, name string, options ...Option) ClusterProxy // CollectWorkloadClusterLogs collects machines and infrastructure logs from the workload cluster. CollectWorkloadClusterLogs(ctx context.Context, namespace, name, outputPath string) @@ -156,7 +156,7 @@ func NewClusterProxy(name string, kubeconfigPath string, scheme *runtime.Scheme, } // newFromAPIConfig returns a clusterProxy given a api.Config and the scheme defining the types hosted in the cluster. -func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme) ClusterProxy { +func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme, options ...Option) ClusterProxy { // NB. the ClusterProvider is responsible for the cleanup of this file f, err := os.CreateTemp("", "e2e-kubeconfig") Expect(err).ToNot(HaveOccurred(), "Failed to create kubeconfig file for the kind cluster %q") @@ -165,12 +165,16 @@ func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme) C err = clientcmd.WriteToFile(*config, kubeconfigPath) Expect(err).ToNot(HaveOccurred(), "Failed to write kubeconfig for the kind cluster to a file %q") - return &clusterProxy{ + proxy := &clusterProxy{ name: name, kubeconfigPath: kubeconfigPath, scheme: scheme, shouldCleanupKubeconfig: true, } + for _, o := range options { + o(proxy) + } + return proxy } // GetName returns the name of the cluster. @@ -265,7 +269,7 @@ func (p *clusterProxy) GetLogCollector() ClusterLogCollector { } // GetWorkloadCluster returns ClusterProxy for the workload cluster. -func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name string) ClusterProxy { +func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name string, options ...Option) ClusterProxy { Expect(ctx).NotTo(BeNil(), "ctx is required for GetWorkloadCluster") Expect(namespace).NotTo(BeEmpty(), "namespace is required for GetWorkloadCluster") Expect(name).NotTo(BeEmpty(), "name is required for GetWorkloadCluster") @@ -279,12 +283,13 @@ func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name s p.fixConfig(ctx, name, config) } - return newFromAPIConfig(name, config, p.scheme) + return newFromAPIConfig(name, config, p.scheme, options...) } // CollectWorkloadClusterLogs collects machines and infrastructure logs and from the workload cluster. func (p *clusterProxy) CollectWorkloadClusterLogs(ctx context.Context, namespace, name, outputPath string) { if p.logCollector == nil { + fmt.Printf("Unable to get logs for workload Cluster %s: log collector is nil.\n", klog.KRef(namespace, name)) return } diff --git a/test/framework/machine_helpers.go b/test/framework/machine_helpers.go index c7938c837fa0..8ff8b1480178 100644 --- a/test/framework/machine_helpers.go +++ b/test/framework/machine_helpers.go @@ -169,7 +169,7 @@ func WaitForControlPlaneMachinesToBeUpgraded(ctx context.Context, input WaitForC } } if len(machines) > upgraded { - return 0, errors.New("old nodes remain") + return 0, errors.New("old Machines remain") } return upgraded, nil }, intervals...).Should(Equal(input.MachineCount), "Timed out waiting for all control-plane machines in Cluster %s to be upgraded to kubernetes version %s", klog.KObj(input.Cluster), input.KubernetesUpgradeVersion) @@ -209,7 +209,7 @@ func WaitForMachineDeploymentMachinesToBeUpgraded(ctx context.Context, input Wai } } if len(machines) > upgraded { - return 0, errors.New("old nodes remain") + return 0, errors.New("old Machines remain") } return upgraded, nil }, intervals...).Should(Equal(input.MachineCount), "Timed out waiting for all MachineDeployment %s Machines to be upgraded to kubernetes version %s", klog.KObj(&input.MachineDeployment), input.KubernetesUpgradeVersion)