@@ -31,9 +31,8 @@ import (
3131 "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
3232 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
3333 "github.com/pkg/errors"
34- "k8s.io/apimachinery/pkg/runtime/schema"
3534 "k8s.io/utils/ptr"
36- clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1 "
35+ clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2 "
3736 "sigs.k8s.io/cluster-api/test/framework"
3837 "sigs.k8s.io/cluster-api/util"
3938 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -56,40 +55,24 @@ const (
5655var _ framework.ClusterLogCollector = & AzureLogCollector {}
5756
5857// CollectMachineLog collects logs from a machine.
59- func (k AzureLogCollector ) CollectMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1beta1.Machine , outputPath string ) error {
60- infraGV , err := schema .ParseGroupVersion (m .Spec .InfrastructureRef .APIVersion )
61- if err != nil {
62- return fmt .Errorf ("invalid spec.infrastructureRef.apiVersion %q: %w" , m .Spec .InfrastructureRef .APIVersion , err )
63- }
64- infraKind := m .Spec .InfrastructureRef .Kind
65- infraGK := schema.GroupKind {
66- Group : infraGV .Group ,
67- Kind : infraKind ,
68- }
58+ func (k AzureLogCollector ) CollectMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1.Machine , outputPath string ) error {
59+ infraGK := m .Spec .InfrastructureRef .GroupKind ()
6960
7061 switch infraGK {
7162 case infrav1 .GroupVersion .WithKind (infrav1 .AzureMachineKind ).GroupKind ():
7263 return collectAzureMachineLog (ctx , managementClusterClient , m , outputPath )
7364 case infrav1exp .GroupVersion .WithKind (infrav1exp .AzureMachinePoolMachineKind ).GroupKind ():
7465 // Logs collected for AzureMachinePool
7566 default :
76- Logf ("Unknown machine infra kind: %s" , infraGV . WithKind ( infraKind ) )
67+ Logf ("Unknown machine infra kind: %s" , infraGK )
7768 }
7869
7970 return nil
8071}
8172
8273// CollectMachinePoolLog collects logs from a machine pool.
83- func (k AzureLogCollector ) CollectMachinePoolLog (ctx context.Context , managementClusterClient client.Client , mp * clusterv1beta1.MachinePool , outputPath string ) error {
84- infraGV , err := schema .ParseGroupVersion (mp .Spec .Template .Spec .InfrastructureRef .APIVersion )
85- if err != nil {
86- return fmt .Errorf ("invalid spec.infrastructureRef.apiVersion %q: %w" , mp .Spec .Template .Spec .InfrastructureRef .APIVersion , err )
87- }
88- infraKind := mp .Spec .Template .Spec .InfrastructureRef .Kind
89- infraGK := schema.GroupKind {
90- Group : infraGV .Group ,
91- Kind : infraKind ,
92- }
74+ func (k AzureLogCollector ) CollectMachinePoolLog (ctx context.Context , managementClusterClient client.Client , mp * clusterv1.MachinePool , outputPath string ) error {
75+ infraGK := mp .Spec .Template .Spec .InfrastructureRef .GroupKind ()
9376
9477 switch infraGK {
9578 case infrav1exp .GroupVersion .WithKind (infrav1 .AzureMachinePoolKind ).GroupKind ():
@@ -101,32 +84,32 @@ func (k AzureLogCollector) CollectMachinePoolLog(ctx context.Context, management
10184 // AKS node logs aren't accessible.
10285 Logf ("Skipping logs for %s" , infrav1 .AzureASOManagedMachinePoolKind )
10386 default :
104- Logf ("Unknown machine pool infra kind: %s" , infraGV . WithKind ( infraKind ) )
87+ Logf ("Unknown machine pool infra kind: %s" , infraGK )
10588 }
10689
10790 return nil
10891}
10992
11093// CollectInfrastructureLogs collects log from the infrastructure.
11194// This is currently a no-op implementation to satisfy the LogCollector interface.
112- func (k AzureLogCollector ) CollectInfrastructureLogs (_ context.Context , _ client.Client , _ * clusterv1beta1 .Cluster , _ string ) error {
95+ func (k AzureLogCollector ) CollectInfrastructureLogs (_ context.Context , _ client.Client , _ * clusterv1 .Cluster , _ string ) error {
11396 return nil
11497}
11598
116- func collectAzureMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1beta1 .Machine , outputPath string ) error {
99+ func collectAzureMachineLog (ctx context.Context , managementClusterClient client.Client , m * clusterv1 .Machine , outputPath string ) error {
117100 am , err := getAzureMachine (ctx , managementClusterClient , m )
118101 if err != nil {
119- return fmt .Errorf ("get AzureMachine %s/%s: %w" , m .Spec . InfrastructureRef . Namespace , m .Spec .InfrastructureRef .Name , err )
102+ return fmt .Errorf ("get AzureMachine %s/%s: %w" , m .Namespace , m .Spec .InfrastructureRef .Name , err )
120103 }
121104
122105 cluster , err := util .GetClusterFromMetadata (ctx , managementClusterClient , m .ObjectMeta )
123106 if err != nil {
124107 return err
125108 }
126109
127- azureCluster , err := getAzureCluster (ctx , managementClusterClient , cluster .Spec . InfrastructureRef . Namespace , cluster .Spec .InfrastructureRef .Name )
110+ azureCluster , err := getAzureCluster (ctx , managementClusterClient , cluster .Namespace , cluster .Spec .InfrastructureRef .Name )
128111 if err != nil {
129- return fmt .Errorf ("get AzureCluster %s/%s: %w" , cluster .Spec . InfrastructureRef . Namespace , cluster .Spec .InfrastructureRef .Name , err )
112+ return fmt .Errorf ("get AzureCluster %s/%s: %w" , cluster .Namespace , cluster .Spec .InfrastructureRef .Name , err )
130113 }
131114 subscriptionID := azureCluster .Spec .SubscriptionID
132115 resourceGroup := azureCluster .Spec .ResourceGroup
@@ -135,20 +118,20 @@ func collectAzureMachineLog(ctx context.Context, managementClusterClient client.
135118 return collectVMLog (ctx , cluster , subscriptionID , resourceGroup , name , outputPath )
136119}
137120
138- func collectAzureMachinePoolLog (ctx context.Context , managementClusterClient client.Client , mp * clusterv1beta1 .MachinePool , outputPath string ) error {
121+ func collectAzureMachinePoolLog (ctx context.Context , managementClusterClient client.Client , mp * clusterv1 .MachinePool , outputPath string ) error {
139122 am , err := getAzureMachinePool (ctx , managementClusterClient , mp )
140123 if err != nil {
141- return fmt .Errorf ("get AzureMachinePool %s/%s: %w" , mp .Spec . Template . Spec . InfrastructureRef . Namespace , mp .Spec .Template .Spec .InfrastructureRef .Name , err )
124+ return fmt .Errorf ("get AzureMachinePool %s/%s: %w" , mp .Namespace , mp .Spec .Template .Spec .InfrastructureRef .Name , err )
142125 }
143126
144127 cluster , err := util .GetClusterFromMetadata (ctx , managementClusterClient , mp .ObjectMeta )
145128 if err != nil {
146129 return err
147130 }
148131
149- azureCluster , err := getAzureCluster (ctx , managementClusterClient , cluster .Spec . InfrastructureRef . Namespace , cluster .Spec .InfrastructureRef .Name )
132+ azureCluster , err := getAzureCluster (ctx , managementClusterClient , cluster .Namespace , cluster .Spec .InfrastructureRef .Name )
150133 if err != nil {
151- return fmt .Errorf ("get AzureCluster %s/%s: %w" , cluster .Spec . InfrastructureRef . Namespace , cluster .Spec .InfrastructureRef .Name , err )
134+ return fmt .Errorf ("get AzureCluster %s/%s: %w" , cluster .Namespace , cluster .Spec .InfrastructureRef .Name , err )
152135 }
153136 subscriptionID := azureCluster .Spec .SubscriptionID
154137 resourceGroup := azureCluster .Spec .ResourceGroup
@@ -157,7 +140,7 @@ func collectAzureMachinePoolLog(ctx context.Context, managementClusterClient cli
157140 return collectVMSSLog (ctx , cluster , subscriptionID , resourceGroup , name , outputPath )
158141}
159142
160- func collectVMLog (ctx context.Context , cluster * clusterv1beta1 .Cluster , subscriptionID , resourceGroup , name , outputPath string ) error {
143+ func collectVMLog (ctx context.Context , cluster * clusterv1 .Cluster , subscriptionID , resourceGroup , name , outputPath string ) error {
161144 cred , err := azidentity .NewDefaultAzureCredential (nil )
162145 if err != nil {
163146 return errors .Wrap (err , "failed to get default azure credential" )
@@ -197,7 +180,7 @@ func collectVMLog(ctx context.Context, cluster *clusterv1beta1.Cluster, subscrip
197180 return kinderrors .NewAggregate (errs )
198181}
199182
200- func collectVMSSLog (ctx context.Context , cluster * clusterv1beta1 .Cluster , subscriptionID , resourceGroup , name , outputPath string ) error {
183+ func collectVMSSLog (ctx context.Context , cluster * clusterv1 .Cluster , subscriptionID , resourceGroup , name , outputPath string ) error {
201184 vmssID := azure .VMSSID (subscriptionID , resourceGroup , name )
202185
203186 cred , err := azidentity .NewDefaultAzureCredential (nil )
@@ -322,7 +305,7 @@ func collectVMSSLog(ctx context.Context, cluster *clusterv1beta1.Cluster, subscr
322305}
323306
324307// collectLogsFromNode collects logs from various sources by ssh'ing into the node
325- func collectLogsFromNode (cluster * clusterv1beta1 .Cluster , hostname string , isWindows bool , outputPath string ) error {
308+ func collectLogsFromNode (cluster * clusterv1 .Cluster , hostname string , isWindows bool , outputPath string ) error {
326309 nodeOSType := azure .LinuxOS
327310 if isWindows {
328311 nodeOSType = azure .WindowsOS
@@ -392,9 +375,9 @@ func getAzureASOManagedCluster(ctx context.Context, managementClusterClient clie
392375 return azManagedCluster , err
393376}
394377
395- func getAzureMachine (ctx context.Context , managementClusterClient client.Client , m * clusterv1beta1 .Machine ) (* infrav1.AzureMachine , error ) {
378+ func getAzureMachine (ctx context.Context , managementClusterClient client.Client , m * clusterv1 .Machine ) (* infrav1.AzureMachine , error ) {
396379 key := client.ObjectKey {
397- Namespace : m .Spec . InfrastructureRef . Namespace ,
380+ Namespace : m .Namespace ,
398381 Name : m .Spec .InfrastructureRef .Name ,
399382 }
400383
@@ -403,9 +386,9 @@ func getAzureMachine(ctx context.Context, managementClusterClient client.Client,
403386 return azMachine , err
404387}
405388
406- func getAzureMachinePool (ctx context.Context , managementClusterClient client.Client , mp * clusterv1beta1 .MachinePool ) (* infrav1exp.AzureMachinePool , error ) {
389+ func getAzureMachinePool (ctx context.Context , managementClusterClient client.Client , mp * clusterv1 .MachinePool ) (* infrav1exp.AzureMachinePool , error ) {
407390 key := client.ObjectKey {
408- Namespace : mp .Spec . Template . Spec . InfrastructureRef . Namespace ,
391+ Namespace : mp .Namespace ,
409392 Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
410393 }
411394
0 commit comments