Skip to content

Commit 2caa534

Browse files
Improve logging for self-hosted e2e test
Signed-off-by: killianmuldoon <[email protected]>
1 parent 2427c0c commit 2caa534

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

test/e2e/clusterctl_upgrade.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
271271
}
272272

273273
// Get a ClusterProxy so we can interact with the workload cluster
274-
managementClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name)
274+
managementClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name, framework.WithMachineLogCollector(input.BootstrapClusterProxy.GetLogCollector()))
275275

276276
// Download the older clusterctl version to be used for setting up the management cluster to be upgraded
277277
log.Logf("Downloading clusterctl binary from %s", initClusterctlBinaryURL)
@@ -543,13 +543,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
543543
AfterEach(func() {
544544
if testNamespace != nil {
545545
// Dump all the logs from the workload cluster before deleting them.
546-
managementClusterProxy.CollectWorkloadClusterLogs(ctx, testNamespace.Name, managementClusterName, filepath.Join(input.ArtifactFolder, "clusters", managementClusterName, "machines"))
547-
548-
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
549-
Lister: managementClusterProxy.GetClient(),
550-
Namespace: testNamespace.Name,
551-
LogPath: filepath.Join(input.ArtifactFolder, "clusters", managementClusterResources.Cluster.Name, "resources"),
552-
})
546+
dumpAllResources(ctx, managementClusterProxy, input.ArtifactFolder, testNamespace, managementClusterResources.Cluster)
553547

554548
if !input.SkipCleanup {
555549
switch {

test/e2e/self_hosted.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
187187

188188
cluster := clusterResources.Cluster
189189
// Get a ClusterBroker so we can interact with the workload cluster
190-
selfHostedClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name)
190+
selfHostedClusterProxy = input.BootstrapClusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name, framework.WithMachineLogCollector(input.BootstrapClusterProxy.GetLogCollector()))
191191

192192
Byf("Creating a namespace for hosting the %s test spec", specName)
193193
selfHostedNamespace, selfHostedCancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{

test/framework/cluster_proxy.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type ClusterProxy interface {
9191
Apply(ctx context.Context, resources []byte, args ...string) error
9292

9393
// GetWorkloadCluster returns a proxy to a workload cluster defined in the Kubernetes cluster.
94-
GetWorkloadCluster(ctx context.Context, namespace, name string) ClusterProxy
94+
GetWorkloadCluster(ctx context.Context, namespace, name string, options ...Option) ClusterProxy
9595

9696
// CollectWorkloadClusterLogs collects machines and infrastructure logs from the workload cluster.
9797
CollectWorkloadClusterLogs(ctx context.Context, namespace, name, outputPath string)
@@ -156,7 +156,7 @@ func NewClusterProxy(name string, kubeconfigPath string, scheme *runtime.Scheme,
156156
}
157157

158158
// newFromAPIConfig returns a clusterProxy given a api.Config and the scheme defining the types hosted in the cluster.
159-
func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme) ClusterProxy {
159+
func newFromAPIConfig(name string, config *api.Config, scheme *runtime.Scheme, options ...Option) ClusterProxy {
160160
// NB. the ClusterProvider is responsible for the cleanup of this file
161161
f, err := os.CreateTemp("", "e2e-kubeconfig")
162162
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
165165
err = clientcmd.WriteToFile(*config, kubeconfigPath)
166166
Expect(err).ToNot(HaveOccurred(), "Failed to write kubeconfig for the kind cluster to a file %q")
167167

168-
return &clusterProxy{
168+
proxy := &clusterProxy{
169169
name: name,
170170
kubeconfigPath: kubeconfigPath,
171171
scheme: scheme,
172172
shouldCleanupKubeconfig: true,
173173
}
174+
for _, o := range options {
175+
o(proxy)
176+
}
177+
return proxy
174178
}
175179

176180
// GetName returns the name of the cluster.
@@ -265,7 +269,7 @@ func (p *clusterProxy) GetLogCollector() ClusterLogCollector {
265269
}
266270

267271
// GetWorkloadCluster returns ClusterProxy for the workload cluster.
268-
func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name string) ClusterProxy {
272+
func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name string, options ...Option) ClusterProxy {
269273
Expect(ctx).NotTo(BeNil(), "ctx is required for GetWorkloadCluster")
270274
Expect(namespace).NotTo(BeEmpty(), "namespace is required for GetWorkloadCluster")
271275
Expect(name).NotTo(BeEmpty(), "name is required for GetWorkloadCluster")
@@ -279,12 +283,13 @@ func (p *clusterProxy) GetWorkloadCluster(ctx context.Context, namespace, name s
279283
p.fixConfig(ctx, name, config)
280284
}
281285

282-
return newFromAPIConfig(name, config, p.scheme)
286+
return newFromAPIConfig(name, config, p.scheme, options...)
283287
}
284288

285289
// CollectWorkloadClusterLogs collects machines and infrastructure logs and from the workload cluster.
286290
func (p *clusterProxy) CollectWorkloadClusterLogs(ctx context.Context, namespace, name, outputPath string) {
287291
if p.logCollector == nil {
292+
fmt.Printf("Unable to get logs for workload Cluster %s: log collector is nil.\n", klog.KRef(namespace, name))
288293
return
289294
}
290295

test/framework/machine_helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func WaitForControlPlaneMachinesToBeUpgraded(ctx context.Context, input WaitForC
169169
}
170170
}
171171
if len(machines) > upgraded {
172-
return 0, errors.New("old nodes remain")
172+
return 0, errors.New("old Machines remain")
173173
}
174174
return upgraded, nil
175175
}, 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
209209
}
210210
}
211211
if len(machines) > upgraded {
212-
return 0, errors.New("old nodes remain")
212+
return 0, errors.New("old Machines remain")
213213
}
214214
return upgraded, nil
215215
}, 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)

0 commit comments

Comments
 (0)