Skip to content

Commit dc52c20

Browse files
Add clusterctl describe to E2E artifacts
1 parent e3da33b commit dc52c20

18 files changed

+118
-16
lines changed

test/e2e/autoscaler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,6 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
372372

373373
AfterEach(func() {
374374
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
375-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
375+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
376376
})
377377
}

test/e2e/cluster_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,6 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust
281281

282282
AfterEach(func() {
283283
// Dumps all the resources in the spec Namespace, then cleanups the cluster object and the spec Namespace itself.
284-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
284+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
285285
})
286286
}

test/e2e/clusterclass_changes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas
281281

282282
AfterEach(func() {
283283
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
284-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
284+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
285285

286286
if !input.SkipCleanup {
287287
Byf("Deleting namespace used for hosting the %q test spec ClusterClass", specName)

test/e2e/clusterclass_rollout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
308308

309309
AfterEach(func() {
310310
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
311-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
311+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
312312
})
313313
}
314314

test/e2e/clusterctl_upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
767767
managementClusterProvider.Dispose(ctx)
768768
}
769769
} else {
770-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, managementClusterNamespace, managementClusterCancelWatches, managementClusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
770+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, managementClusterNamespace, managementClusterCancelWatches, managementClusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
771771
}
772772
})
773773
}

test/e2e/k8s_conformance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ func K8SConformanceSpec(ctx context.Context, inputGetter func() K8SConformanceSp
158158

159159
AfterEach(func() {
160160
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
161-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
161+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
162162
})
163163
}

test/e2e/kcp_adoption.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,6 @@ func KCPAdoptionSpec(ctx context.Context, inputGetter func() KCPAdoptionSpecInpu
252252

253253
AfterEach(func() {
254254
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
255-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
255+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
256256
})
257257
}

test/e2e/kcp_remediations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func KCPRemediationSpec(ctx context.Context, inputGetter func() KCPRemediationSp
418418

419419
AfterEach(func() {
420420
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
421-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
421+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
422422
})
423423
}
424424

test/e2e/machine_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ func MachinePoolSpec(ctx context.Context, inputGetter func() MachinePoolInput) {
144144

145145
AfterEach(func() {
146146
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
147-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
147+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
148148
})
149149
}

test/e2e/md_remediations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ func MachineDeploymentRemediationSpec(ctx context.Context, inputGetter func() Ma
125125

126126
AfterEach(func() {
127127
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
128-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
128+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
129129
})
130130
}

test/e2e/md_rollout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ func MachineDeploymentRolloutSpec(ctx context.Context, inputGetter func() Machin
125125

126126
AfterEach(func() {
127127
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
128-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
128+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
129129
})
130130
}

test/e2e/md_scale.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ func MachineDeploymentScaleSpec(ctx context.Context, inputGetter func() MachineD
140140

141141
AfterEach(func() {
142142
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
143-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
143+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
144144
})
145145
}

test/e2e/node_drain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
613613

614614
AfterEach(func() {
615615
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
616-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
616+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
617617
})
618618
}
619619

test/e2e/quick_start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
185185

186186
AfterEach(func() {
187187
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
188-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
188+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
189189
if input.DeployClusterClassInSeparateNamespace && !input.SkipCleanup {
190190
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
191191
Deleter: input.BootstrapClusterProxy.GetClient(),

test/e2e/self_hosted.go

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

463463
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
464-
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
464+
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ClusterctlConfigPath, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
465465
})
466466
}
467467

test/framework/spec_helpers.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ limitations under the License.
1717
package framework
1818

1919
import (
20+
"bufio"
2021
"context"
2122
"fmt"
23+
"os"
2224
"path/filepath"
2325

2426
. "github.com/onsi/ginkgo/v2"
27+
. "github.com/onsi/gomega"
2528
corev1 "k8s.io/api/core/v1"
2629
"k8s.io/apimachinery/pkg/runtime/schema"
2730
"k8s.io/klog/v2"
2831
"sigs.k8s.io/controller-runtime/pkg/client"
2932

3033
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
34+
clusterctlclient "sigs.k8s.io/cluster-api/cmd/clusterctl/client"
35+
cmdtree "sigs.k8s.io/cluster-api/internal/util/tree"
3136
"sigs.k8s.io/cluster-api/test/framework/internal/log"
3237
"sigs.k8s.io/cluster-api/util"
3338
)
@@ -95,8 +100,86 @@ func DumpAllResourcesAndLogs(ctx context.Context, clusterProxy ClusterProxy, art
95100
}
96101
}
97102

103+
type DescribeClusterInput struct {
104+
ClusterctlConfigPath string
105+
LogFolder string
106+
KubeConfigPath string
107+
Namespace string
108+
Name string
109+
}
110+
111+
func DescribeCluster(ctx context.Context, input DescribeClusterInput) {
112+
log.Logf("clusterctl describe cluster %s --show-conditions=all --show-machinesets=true --grouping=false --echo=true --v1beta2", input.Name)
113+
114+
clusterctlClient, err := clusterctlclient.New(ctx, input.ClusterctlConfigPath)
115+
Expect(err).ToNot(HaveOccurred(), "Failed to create the clusterctl client library")
116+
117+
tree, err := clusterctlClient.DescribeCluster(ctx, clusterctlclient.DescribeClusterOptions{
118+
Kubeconfig: clusterctlclient.Kubeconfig{
119+
Path: input.KubeConfigPath,
120+
Context: "",
121+
},
122+
Namespace: input.Namespace,
123+
ClusterName: input.Name,
124+
ShowOtherConditions: "all",
125+
ShowClusterResourceSets: false,
126+
ShowTemplates: false,
127+
ShowMachineSets: true,
128+
AddTemplateVirtualNode: true,
129+
Echo: true,
130+
Grouping: false,
131+
V1Beta2: true,
132+
})
133+
Expect(err).ToNot(HaveOccurred(), "Failed to run clusterctl describe")
134+
135+
Expect(os.MkdirAll(input.LogFolder, 0750)).To(Succeed(), "Failed to create log folder %s", input.LogFolder)
136+
137+
f, err := os.Create(filepath.Join(input.LogFolder, fmt.Sprintf("clusterctl-describe-%s.txt", input.Name)))
138+
Expect(err).ToNot(HaveOccurred(), "Failed to create a file for saving clusterctl describe output")
139+
140+
defer f.Close()
141+
142+
w := bufio.NewWriter(f)
143+
cmdtree.PrintObjectTreeV1Beta2(tree, w)
144+
Expect(w.Flush()).To(Succeed(), "Failed to save clusterctl describe output")
145+
}
146+
147+
type DescribeAllClusterInput struct {
148+
Client client.Client
149+
KubeConfigPath string
150+
ClusterctlConfigPath string
151+
ArtifactFolder string
152+
Namespace string
153+
}
154+
155+
func DescribeAllCluster(ctx context.Context, input DescribeAllClusterInput) {
156+
clusters := &clusterv1.ClusterList{}
157+
Eventually(func() error {
158+
return input.Client.List(ctx, clusters, client.InNamespace(input.Namespace))
159+
}, retryableOperationTimeout, retryableOperationInterval).Should(Succeed(), "Failed to list clusters in namespace %s", input.Namespace)
160+
161+
for _, c := range clusters.Items {
162+
DescribeCluster(ctx, DescribeClusterInput{
163+
ClusterctlConfigPath: input.ClusterctlConfigPath,
164+
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", c.Name),
165+
KubeConfigPath: input.KubeConfigPath,
166+
Namespace: c.Namespace,
167+
Name: c.Name,
168+
})
169+
}
170+
}
171+
98172
// DumpSpecResourcesAndCleanup dumps all the resources in the spec namespace and cleans up the spec namespace.
99-
func DumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterProxy ClusterProxy, artifactFolder string, namespace *corev1.Namespace, cancelWatches context.CancelFunc, cluster *clusterv1.Cluster, intervalsGetter func(spec, key string) []interface{}, skipCleanup bool) {
173+
func DumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterProxy ClusterProxy, clusterctlConfigPath, artifactFolder string, namespace *corev1.Namespace, cancelWatches context.CancelFunc, cluster *clusterv1.Cluster, intervalsGetter func(spec, key string) []interface{}, skipCleanup bool) {
174+
// Describe all clusters
175+
DescribeAllCluster(ctx, DescribeAllClusterInput{
176+
Client: clusterProxy.GetClient(),
177+
KubeConfigPath: clusterProxy.GetKubeconfigPath(),
178+
ClusterctlConfigPath: clusterctlConfigPath,
179+
ArtifactFolder: artifactFolder,
180+
Namespace: namespace.Name,
181+
})
182+
100183
// Dump all the resources in the spec namespace and the workload cluster.
101184
DumpAllResourcesAndLogs(ctx, clusterProxy, artifactFolder, namespace, cluster)
102185

test/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ require (
6565
github.com/distribution/reference v0.6.0 // indirect
6666
github.com/docker/go-units v0.4.0 // indirect
6767
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
68+
github.com/fatih/color v1.18.0 // indirect
6869
github.com/felixge/httpsnoop v1.0.4 // indirect
6970
github.com/fsnotify/fsnotify v1.7.0 // indirect
7071
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -96,7 +97,9 @@ require (
9697
github.com/json-iterator/go v1.1.12 // indirect
9798
github.com/magiconair/properties v1.8.7 // indirect
9899
github.com/mailru/easyjson v0.7.7 // indirect
100+
github.com/mattn/go-colorable v0.1.13 // indirect
99101
github.com/mattn/go-isatty v0.0.20 // indirect
102+
github.com/mattn/go-runewidth v0.0.14 // indirect
100103
github.com/mitchellh/copystructure v1.2.0 // indirect
101104
github.com/mitchellh/mapstructure v1.5.0 // indirect
102105
github.com/mitchellh/reflectwalk v1.0.2 // indirect
@@ -107,12 +110,14 @@ require (
107110
github.com/morikuni/aec v1.0.0 // indirect
108111
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
109112
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
113+
github.com/olekukonko/tablewriter v0.0.5 // indirect
110114
github.com/opencontainers/go-digest v1.0.0 // indirect
111115
github.com/opencontainers/image-spec v1.0.2 // indirect
112116
github.com/pelletier/go-toml v1.9.5 // indirect
113117
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
114118
github.com/prometheus/client_model v0.6.1 // indirect
115119
github.com/prometheus/procfs v0.15.1 // indirect
120+
github.com/rivo/uniseg v0.4.2 // indirect
116121
github.com/sagikazarmark/locafero v0.4.0 // indirect
117122
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
118123
github.com/shopspring/decimal v1.4.0 // indirect

0 commit comments

Comments
 (0)