@@ -45,11 +45,16 @@ type AzureLogCollector struct{}
45
45
func (k AzureLogCollector ) CollectMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine , outputPath string ) error {
46
46
var errors []error
47
47
48
- if err := collectLogsFromNode (ctx , managementClusterClient , m , outputPath ); err != nil {
48
+ am , err := getAzureMachine (ctx , managementClusterClient , m )
49
+ if err != nil {
50
+ return err
51
+ }
52
+
53
+ if err := collectLogsFromNode (ctx , managementClusterClient , m , am , outputPath ); err != nil {
49
54
errors = append (errors , err )
50
55
}
51
56
52
- if err := collectBootLog (ctx , m , outputPath ); err != nil {
57
+ if err := collectBootLog (ctx , am , outputPath ); err != nil {
53
58
errors = append (errors , err )
54
59
}
55
60
@@ -58,17 +63,14 @@ func (k AzureLogCollector) CollectMachineLog(ctx context.Context, managementClus
58
63
}
59
64
60
65
// collectLogsFromNode collects logs from various sources by ssh'ing into the node
61
- func collectLogsFromNode (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine , outputPath string ) error {
66
+ func collectLogsFromNode (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine , am * v1alpha4. AzureMachine , outputPath string ) error {
62
67
cluster , err := util .GetClusterFromMetadata (ctx , managementClusterClient , m .ObjectMeta )
63
68
if err != nil {
64
69
return err
65
70
}
66
71
67
72
Logf ("INFO: Collecting logs for machine %s in cluster %s in namespace %s\n " , m .GetName (), cluster .Name , cluster .Namespace )
68
- isWindows , err := isNodeWindows (ctx , managementClusterClient , m )
69
- if err != nil {
70
- return err
71
- }
73
+ isWindows := isNodeWindows (am )
72
74
73
75
controlPlaneEndpoint := cluster .Spec .ControlPlaneEndpoint .Host
74
76
hostname := m .Spec .InfrastructureRef .Name
@@ -108,18 +110,19 @@ func collectLogsFromNode(ctx context.Context, managementClusterClient client.Cli
108
110
return kinderrors .AggregateConcurrent (linuxLogs (execToPathFn ))
109
111
}
110
112
111
- func isNodeWindows (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine ) (bool , error ) {
113
+ func isNodeWindows (am * v1alpha4.AzureMachine ) bool {
114
+ return am .Spec .OSDisk .OSType == azure .WindowsOS
115
+ }
116
+
117
+ func getAzureMachine (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine ) (* v1alpha4.AzureMachine , error ) {
112
118
key := client.ObjectKey {
113
119
Namespace : m .Spec .InfrastructureRef .Namespace ,
114
120
Name : m .Spec .InfrastructureRef .Name ,
115
121
}
116
122
117
123
azMachine := & v1alpha4.AzureMachine {}
118
- if err := managementClusterClient .Get (ctx , key , azMachine ); err != nil {
119
- return false , err
120
- }
121
-
122
- return azMachine .Spec .OSDisk .OSType == azure .WindowsOS , nil
124
+ err := managementClusterClient .Get (ctx , key , azMachine )
125
+ return azMachine , err
123
126
}
124
127
125
128
func linuxLogs (execToPathFn func (outputFileName string , command string , args ... string ) func () error ) []func () error {
@@ -251,8 +254,10 @@ func windowsNetworkLogs(execToPathFn func(outputFileName string, command string,
251
254
}
252
255
253
256
// collectBootLog collects boot logs of the vm by using azure boot diagnostics
254
- func collectBootLog (ctx context.Context , m * clusterv1.Machine , outputPath string ) error {
255
- resourceId := strings .TrimPrefix (* m .Spec .ProviderID , azure .ProviderIDPrefix )
257
+ func collectBootLog (ctx context.Context , am * v1alpha4.AzureMachine , outputPath string ) error {
258
+ Logf ("INFO: Collecting boot logs for AzureMachine %s\n " , am .GetName ())
259
+
260
+ resourceId := strings .TrimPrefix (* am .Spec .ProviderID , azure .ProviderIDPrefix )
256
261
resource , err := autorest .ParseResourceID (resourceId )
257
262
if err != nil {
258
263
return errors .Wrap (err , "failed to parse resource id" )
0 commit comments