@@ -20,6 +20,7 @@ package e2e
20
20
21
21
import (
22
22
"flag"
23
+ "fmt"
23
24
"os"
24
25
"path/filepath"
25
26
"strings"
@@ -29,7 +30,9 @@ import (
29
30
. "github.com/onsi/gomega"
30
31
ctrl "sigs.k8s.io/controller-runtime"
31
32
33
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
34
"k8s.io/apimachinery/pkg/runtime"
35
+ clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
33
36
"sigs.k8s.io/cluster-api/test/framework"
34
37
"sigs.k8s.io/cluster-api/test/framework/bootstrap"
35
38
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
@@ -142,6 +145,9 @@ var _ = SynchronizedAfterSuite(func() {
142
145
}, func () {
143
146
// After all ParallelNodes.
144
147
148
+ By ("Dumping logs from the bootstrap cluster" )
149
+ dumpBootstrapClusterLogs (bootstrapClusterProxy )
150
+
145
151
By ("Tearing down the management cluster" )
146
152
if ! skipCleanup {
147
153
tearDown (bootstrapClusterProvider , bootstrapClusterProxy )
@@ -210,6 +216,43 @@ func initBootstrapCluster(bootstrapClusterProxy framework.ClusterProxy, config *
210
216
}, config .GetIntervals (bootstrapClusterProxy .GetName (), "wait-controllers" )... )
211
217
}
212
218
219
+ func dumpBootstrapClusterLogs (bootstrapClusterProxy framework.ClusterProxy ) {
220
+ if bootstrapClusterProxy == nil {
221
+ return
222
+ }
223
+
224
+ clusterLogCollector := bootstrapClusterProxy .GetLogCollector ()
225
+ if clusterLogCollector == nil {
226
+ return
227
+ }
228
+
229
+ nodes , err := bootstrapClusterProxy .GetClientSet ().CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
230
+ if err != nil {
231
+ fmt .Printf ("Failed to get nodes for the bootstrap cluster: %v\n " , err )
232
+ return
233
+ }
234
+
235
+ for i := range nodes .Items {
236
+ nodeName := nodes .Items [i ].GetName ()
237
+ err = clusterLogCollector .CollectMachineLog (
238
+ ctx ,
239
+ bootstrapClusterProxy .GetClient (),
240
+ // The bootstrap cluster is not expected to be a CAPI cluster, so in order to re-use the logCollector,
241
+ // we create a fake machine that wraps the node.
242
+ // NOTE: This assumes a naming convention between machines and nodes, which e.g. applies to the bootstrap clusters generated with kind.
243
+ // This might not work if you are using an existing bootstrap cluster provided by other means.
244
+ & clusterv1.Machine {
245
+ Spec : clusterv1.MachineSpec {ClusterName : nodeName },
246
+ ObjectMeta : metav1.ObjectMeta {Name : nodeName },
247
+ },
248
+ filepath .Join (artifactFolder , "clusters" , bootstrapClusterProxy .GetName (), "machines" , nodeName ),
249
+ )
250
+ if err != nil {
251
+ fmt .Printf ("Failed to get logs for the bootstrap cluster node %s: %v\n " , nodeName , err )
252
+ }
253
+ }
254
+ }
255
+
213
256
func tearDown (bootstrapClusterProvider bootstrap.ClusterProvider , bootstrapClusterProxy framework.ClusterProxy ) {
214
257
if bootstrapClusterProxy != nil {
215
258
bootstrapClusterProxy .Dispose (ctx )
0 commit comments