@@ -23,6 +23,7 @@ import (
23
23
"os"
24
24
"path"
25
25
goruntime "runtime"
26
+ expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha4"
26
27
"strings"
27
28
28
29
. "github.com/onsi/gomega"
@@ -81,6 +82,7 @@ type ClusterLogCollector interface {
81
82
// CollectMachineLog collects log from a machine.
82
83
// TODO: describe output folder struct
83
84
CollectMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine , outputPath string ) error
85
+ CollectMachinePoolLog (ctx context.Context , managementClusterClient client.Client , m * expv1.MachinePool , outputPath string ) error
84
86
}
85
87
86
88
// Option is a configuration option supplied to NewClusterProxy.
@@ -226,12 +228,24 @@ func (p *clusterProxy) CollectWorkloadClusterLogs(ctx context.Context, namespace
226
228
227
229
for i := range machines .Items {
228
230
m := & machines .Items [i ]
229
- err := p .logCollector .CollectMachineLog (ctx , p .GetClient (), m , path .Join (outputPath , m .GetName ()))
231
+ err := p .logCollector .CollectMachineLog (ctx , p .GetClient (), m , path .Join (outputPath , "machines" , m .GetName ()))
230
232
if err != nil {
231
233
// NB. we are treating failures in collecting logs as a non blocking operation (best effort)
232
234
fmt .Printf ("Failed to get logs for machine %s, cluster %s/%s: %v\n " , m .GetName (), namespace , name , err )
233
235
}
234
236
}
237
+
238
+ machinePools , err := getMachinePoolsInCluster (ctx , p .GetClient (), namespace , name )
239
+ Expect (err ).ToNot (HaveOccurred (), "Failed to get machine pools for the %s/%s cluster" , namespace , name )
240
+
241
+ for i := range machinePools .Items {
242
+ mp := & machinePools .Items [i ]
243
+ err := p .logCollector .CollectMachinePoolLog (ctx , p .GetClient (), mp , path .Join (outputPath , "machine-pools" , mp .GetName ()))
244
+ if err != nil {
245
+ // NB. we are treating failures in collecting logs as a non blocking operation (best effort)
246
+ fmt .Printf ("Failed to get logs for machine pool %s, cluster %s/%s: %v\n " , mp .GetName (), namespace , name , err )
247
+ }
248
+ }
235
249
}
236
250
237
251
func getMachinesInCluster (ctx context.Context , c client.Client , namespace , name string ) (* clusterv1.MachineList , error ) {
@@ -249,6 +263,21 @@ func getMachinesInCluster(ctx context.Context, c client.Client, namespace, name
249
263
return machineList , nil
250
264
}
251
265
266
+ func getMachinePoolsInCluster (ctx context.Context , c client.Client , namespace , name string ) (* expv1.MachinePoolList , error ) {
267
+ if name == "" {
268
+ return nil , nil
269
+ }
270
+
271
+ machinePoolList := & expv1.MachinePoolList {}
272
+ labels := map [string ]string {clusterv1 .ClusterLabelName : name }
273
+
274
+ if err := c .List (ctx , machinePoolList , client .InNamespace (namespace ), client .MatchingLabels (labels )); err != nil {
275
+ return nil , err
276
+ }
277
+
278
+ return machinePoolList , nil
279
+ }
280
+
252
281
func (p * clusterProxy ) getKubeconfig (ctx context.Context , namespace string , name string ) * api.Config {
253
282
cl := p .GetClient ()
254
283
0 commit comments