@@ -23,11 +23,14 @@ import (
23
23
"context"
24
24
"sync"
25
25
26
+ asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
26
27
. "github.com/onsi/ginkgo/v2"
27
28
. "github.com/onsi/gomega"
28
29
"k8s.io/apimachinery/pkg/types"
29
30
"k8s.io/utils/ptr"
30
31
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
32
+ infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha1"
33
+ "sigs.k8s.io/cluster-api-provider-azure/exp/mutators"
31
34
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
32
35
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
33
36
"sigs.k8s.io/cluster-api/test/framework"
@@ -46,7 +49,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
46
49
47
50
originalReplicas := map [types.NamespacedName ]int32 {}
48
51
for _ , mp := range input .MachinePools {
49
- originalReplicas [client .ObjectKeyFromObject (mp )] = ptr .Deref [ int32 ] (mp .Spec .Replicas , 0 )
52
+ originalReplicas [client .ObjectKeyFromObject (mp )] = ptr .Deref (mp .Spec .Replicas , 0 )
50
53
}
51
54
52
55
By ("Scaling the machine pools out" )
@@ -58,7 +61,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
58
61
framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
59
62
ClusterProxy : bootstrapClusterProxy ,
60
63
Cluster : input .Cluster ,
61
- Replicas : ptr .Deref [ int32 ] (mp .Spec .Replicas , 0 ) + 1 ,
64
+ Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) + 1 ,
62
65
MachinePools : []* expv1.MachinePool {mp },
63
66
WaitForMachinePoolToScale : input .WaitIntervals ,
64
67
})
@@ -75,7 +78,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
75
78
framework .ScaleMachinePoolAndWait (ctx , framework.ScaleMachinePoolAndWaitInput {
76
79
ClusterProxy : bootstrapClusterProxy ,
77
80
Cluster : input .Cluster ,
78
- Replicas : ptr .Deref [ int32 ] (mp .Spec .Replicas , 0 ) - 1 ,
81
+ Replicas : ptr .Deref (mp .Spec .Replicas , 0 ) - 1 ,
79
82
MachinePools : []* expv1.MachinePool {mp },
80
83
WaitForMachinePoolToScale : input .WaitIntervals ,
81
84
})
@@ -87,15 +90,41 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp
87
90
// System node pools cannot be scaled to 0, so only include user node pools.
88
91
var machinePoolsToScale []* expv1.MachinePool
89
92
for _ , mp := range input .MachinePools {
90
- ammp := & infrav1.AzureManagedMachinePool {}
91
- err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
92
- Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
93
- Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
94
- }, ammp )
95
- Expect (err ).NotTo (HaveOccurred ())
96
-
97
- if ammp .Spec .Mode != string (infrav1 .NodePoolModeSystem ) {
98
- machinePoolsToScale = append (machinePoolsToScale , mp )
93
+ switch mp .Spec .Template .Spec .InfrastructureRef .Kind {
94
+ case infrav1 .AzureManagedMachinePoolKind :
95
+ ammp := & infrav1.AzureManagedMachinePool {}
96
+ err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
97
+ Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
98
+ Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
99
+ }, ammp )
100
+ Expect (err ).NotTo (HaveOccurred ())
101
+
102
+ if ammp .Spec .Mode != string (infrav1 .NodePoolModeSystem ) {
103
+ machinePoolsToScale = append (machinePoolsToScale , mp )
104
+ }
105
+ case infrav1exp .AzureASOManagedMachinePoolKind :
106
+ ammp := & infrav1exp.AzureASOManagedMachinePool {}
107
+ err := bootstrapClusterProxy .GetClient ().Get (ctx , types.NamespacedName {
108
+ Namespace : mp .Spec .Template .Spec .InfrastructureRef .Namespace ,
109
+ Name : mp .Spec .Template .Spec .InfrastructureRef .Name ,
110
+ }, ammp )
111
+ Expect (err ).NotTo (HaveOccurred ())
112
+
113
+ resources , err := mutators .ToUnstructured (ctx , ammp .Spec .Resources )
114
+ Expect (err ).NotTo (HaveOccurred ())
115
+ for _ , resource := range resources {
116
+ if resource .GetKind () != "ManagedClustersAgentPool" {
117
+ continue
118
+ }
119
+ // mode may not be set in spec. Get the ASO object and check in status.
120
+ resource .SetNamespace (ammp .Namespace )
121
+ agentPool := & asocontainerservicev1.ManagedClustersAgentPool {}
122
+ Expect (bootstrapClusterProxy .GetClient ().Get (ctx , client .ObjectKeyFromObject (resource ), agentPool )).To (Succeed ())
123
+ if ptr .Deref (agentPool .Status .Mode , "" ) != asocontainerservicev1 .AgentPoolMode_STATUS_System {
124
+ machinePoolsToScale = append (machinePoolsToScale , mp )
125
+ }
126
+ break
127
+ }
99
128
}
100
129
}
101
130
0 commit comments