Skip to content

Commit e3a05f8

Browse files
authored
Merge pull request #4700 from willie-yao/aks-preview-followup
Follow-up tasks for enabling AKS preview features
2 parents 3e4b3b2 + b20759e commit e3a05f8

File tree

14 files changed

+194
-337
lines changed

14 files changed

+194
-337
lines changed

azure/converters/managedagentpool.go

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,14 @@ limitations under the License.
1717
package converters
1818

1919
import (
20-
asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
21-
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
20+
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001/storage"
2221
"k8s.io/utils/ptr"
2322
)
2423

2524
// AgentPoolToManagedClusterAgentPoolProfile converts a AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolProfile used in managedcluster reconcile.
26-
func AgentPoolToManagedClusterAgentPoolProfile(pool *asocontainerservicev1.ManagedClustersAgentPool) asocontainerservicev1.ManagedClusterAgentPoolProfile {
25+
func AgentPoolToManagedClusterAgentPoolProfile(pool *asocontainerservicev1hub.ManagedClustersAgentPool) asocontainerservicev1hub.ManagedClusterAgentPoolProfile {
2726
properties := pool.Spec
28-
agentPool := asocontainerservicev1.ManagedClusterAgentPoolProfile{
29-
Name: ptr.To(pool.AzureName()),
30-
VmSize: properties.VmSize,
31-
OsType: properties.OsType,
32-
OsDiskSizeGB: properties.OsDiskSizeGB,
33-
Count: properties.Count,
34-
Type: properties.Type,
35-
OrchestratorVersion: properties.OrchestratorVersion,
36-
VnetSubnetReference: properties.VnetSubnetReference,
37-
Mode: properties.Mode,
38-
EnableAutoScaling: properties.EnableAutoScaling,
39-
MaxCount: properties.MaxCount,
40-
MinCount: properties.MinCount,
41-
NodeTaints: properties.NodeTaints,
42-
AvailabilityZones: properties.AvailabilityZones,
43-
MaxPods: properties.MaxPods,
44-
OsDiskType: properties.OsDiskType,
45-
NodeLabels: properties.NodeLabels,
46-
EnableUltraSSD: properties.EnableUltraSSD,
47-
EnableNodePublicIP: properties.EnableNodePublicIP,
48-
NodePublicIPPrefixReference: properties.NodePublicIPPrefixReference,
49-
ScaleSetPriority: properties.ScaleSetPriority,
50-
ScaleDownMode: properties.ScaleDownMode,
51-
SpotMaxPrice: properties.SpotMaxPrice,
52-
Tags: properties.Tags,
53-
KubeletDiskType: properties.KubeletDiskType,
54-
LinuxOSConfig: properties.LinuxOSConfig,
55-
EnableFIPS: properties.EnableFIPS,
56-
EnableEncryptionAtHost: properties.EnableEncryptionAtHost,
57-
}
58-
if properties.KubeletConfig != nil {
59-
agentPool.KubeletConfig = properties.KubeletConfig
60-
}
61-
return agentPool
62-
}
63-
64-
// AgentPoolToManagedClusterAgentPoolPreviewProfile converts an AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolPreviewProfile used in managedcluster reconcile.
65-
func AgentPoolToManagedClusterAgentPoolPreviewProfile(pool *asocontainerservicev1preview.ManagedClustersAgentPool) asocontainerservicev1preview.ManagedClusterAgentPoolProfile {
66-
properties := pool.Spec
67-
68-
// Populate the same properties as the stable version since the patcher will handle the preview-only fields.
69-
agentPool := asocontainerservicev1preview.ManagedClusterAgentPoolProfile{
27+
agentPool := asocontainerservicev1hub.ManagedClusterAgentPoolProfile{
7028
Name: ptr.To(pool.AzureName()),
7129
VmSize: properties.VmSize,
7230
OsType: properties.OsType,

azure/converters/managedagentpool_test.go

Lines changed: 17 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package converters
1919
import (
2020
"testing"
2121

22-
asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
2322
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
23+
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001/storage"
2424
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
2525
. "github.com/onsi/gomega"
2626
"k8s.io/utils/ptr"
@@ -29,31 +29,31 @@ import (
2929
func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
3030
cases := []struct {
3131
name string
32-
pool *asocontainerservicev1.ManagedClustersAgentPool
33-
expect func(*GomegaWithT, asocontainerservicev1.ManagedClusterAgentPoolProfile)
32+
pool *asocontainerservicev1hub.ManagedClustersAgentPool
33+
expect func(*GomegaWithT, asocontainerservicev1hub.ManagedClusterAgentPoolProfile)
3434
}{
3535
{
3636
name: "Should set all values correctly",
37-
pool: &asocontainerservicev1.ManagedClustersAgentPool{
38-
Spec: asocontainerservicev1.ManagedClusters_AgentPool_Spec{
37+
pool: &asocontainerservicev1hub.ManagedClustersAgentPool{
38+
Spec: asocontainerservicev1hub.ManagedClusters_AgentPool_Spec{
3939
AzureName: "agentpool1",
4040
VmSize: ptr.To("Standard_D2s_v3"),
41-
OsType: ptr.To(asocontainerservicev1.OSType_Linux),
42-
OsDiskSizeGB: ptr.To[asocontainerservicev1.ContainerServiceOSDisk](100),
41+
OsType: ptr.To(string(asocontainerservicev1.OSType_Linux)),
42+
OsDiskSizeGB: ptr.To(100),
4343
Count: ptr.To(2),
44-
Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
44+
Type: ptr.To(string(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets)),
4545
OrchestratorVersion: ptr.To("1.22.6"),
4646
VnetSubnetReference: &genruntime.ResourceReference{
4747
ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
4848
},
49-
Mode: ptr.To(asocontainerservicev1.AgentPoolMode_User),
49+
Mode: ptr.To(string(asocontainerservicev1.AgentPoolMode_User)),
5050
EnableAutoScaling: ptr.To(true),
5151
MaxCount: ptr.To(5),
5252
MinCount: ptr.To(2),
5353
NodeTaints: []string{"key1=value1:NoSchedule"},
5454
AvailabilityZones: []string{"zone1"},
5555
MaxPods: ptr.To(60),
56-
OsDiskType: ptr.To(asocontainerservicev1.OSDiskType_Managed),
56+
OsDiskType: ptr.To(string(asocontainerservicev1.OSDiskType_Managed)),
5757
NodeLabels: map[string]string{
5858
"custom": "default",
5959
},
@@ -65,26 +65,26 @@ func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
6565
},
6666
},
6767

68-
expect: func(g *GomegaWithT, result asocontainerservicev1.ManagedClusterAgentPoolProfile) {
69-
g.Expect(result).To(Equal(asocontainerservicev1.ManagedClusterAgentPoolProfile{
68+
expect: func(g *GomegaWithT, result asocontainerservicev1hub.ManagedClusterAgentPoolProfile) {
69+
g.Expect(result).To(Equal(asocontainerservicev1hub.ManagedClusterAgentPoolProfile{
7070
Name: ptr.To("agentpool1"),
7171
VmSize: ptr.To("Standard_D2s_v3"),
72-
OsType: ptr.To(asocontainerservicev1.OSType_Linux),
73-
OsDiskSizeGB: ptr.To[asocontainerservicev1.ContainerServiceOSDisk](100),
72+
OsType: ptr.To(string(asocontainerservicev1.OSType_Linux)),
73+
OsDiskSizeGB: ptr.To(100),
7474
Count: ptr.To(2),
75-
Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
75+
Type: ptr.To(string(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets)),
7676
OrchestratorVersion: ptr.To("1.22.6"),
7777
VnetSubnetReference: &genruntime.ResourceReference{
7878
ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
7979
},
80-
Mode: ptr.To(asocontainerservicev1.AgentPoolMode_User),
80+
Mode: ptr.To(string(asocontainerservicev1.AgentPoolMode_User)),
8181
EnableAutoScaling: ptr.To(true),
8282
MaxCount: ptr.To(5),
8383
MinCount: ptr.To(2),
8484
NodeTaints: []string{"key1=value1:NoSchedule"},
8585
AvailabilityZones: []string{"zone1"},
8686
MaxPods: ptr.To(60),
87-
OsDiskType: ptr.To(asocontainerservicev1.OSDiskType_Managed),
87+
OsDiskType: ptr.To(string(asocontainerservicev1.OSDiskType_Managed)),
8888
NodeLabels: map[string]string{
8989
"custom": "default",
9090
},
@@ -108,86 +108,3 @@ func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
108108
})
109109
}
110110
}
111-
112-
func Test_AgentPoolToManagedClusterAgentPoolPreviewProfile(t *testing.T) {
113-
cases := []struct {
114-
name string
115-
pool *asocontainerservicev1preview.ManagedClustersAgentPool
116-
expect func(*GomegaWithT, asocontainerservicev1preview.ManagedClusterAgentPoolProfile)
117-
}{
118-
{
119-
name: "Should set all values correctly",
120-
pool: &asocontainerservicev1preview.ManagedClustersAgentPool{
121-
Spec: asocontainerservicev1preview.ManagedClusters_AgentPool_Spec{
122-
AzureName: "agentpool1",
123-
VmSize: ptr.To("Standard_D2s_v3"),
124-
OsType: ptr.To(asocontainerservicev1preview.OSType_Linux),
125-
OsDiskSizeGB: ptr.To[asocontainerservicev1preview.ContainerServiceOSDisk](100),
126-
Count: ptr.To(2),
127-
Type: ptr.To(asocontainerservicev1preview.AgentPoolType_VirtualMachineScaleSets),
128-
OrchestratorVersion: ptr.To("1.22.6"),
129-
VnetSubnetReference: &genruntime.ResourceReference{
130-
ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
131-
},
132-
Mode: ptr.To(asocontainerservicev1preview.AgentPoolMode_User),
133-
EnableAutoScaling: ptr.To(true),
134-
MaxCount: ptr.To(5),
135-
MinCount: ptr.To(2),
136-
NodeTaints: []string{"key1=value1:NoSchedule"},
137-
AvailabilityZones: []string{"zone1"},
138-
MaxPods: ptr.To(60),
139-
OsDiskType: ptr.To(asocontainerservicev1preview.OSDiskType_Managed),
140-
NodeLabels: map[string]string{
141-
"custom": "default",
142-
},
143-
Tags: map[string]string{
144-
"custom": "default",
145-
},
146-
EnableFIPS: ptr.To(true),
147-
EnableEncryptionAtHost: ptr.To(true),
148-
},
149-
},
150-
151-
expect: func(g *GomegaWithT, result asocontainerservicev1preview.ManagedClusterAgentPoolProfile) {
152-
g.Expect(result).To(Equal(asocontainerservicev1preview.ManagedClusterAgentPoolProfile{
153-
Name: ptr.To("agentpool1"),
154-
VmSize: ptr.To("Standard_D2s_v3"),
155-
OsType: ptr.To(asocontainerservicev1preview.OSType_Linux),
156-
OsDiskSizeGB: ptr.To[asocontainerservicev1preview.ContainerServiceOSDisk](100),
157-
Count: ptr.To(2),
158-
Type: ptr.To(asocontainerservicev1preview.AgentPoolType_VirtualMachineScaleSets),
159-
OrchestratorVersion: ptr.To("1.22.6"),
160-
VnetSubnetReference: &genruntime.ResourceReference{
161-
ARMID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
162-
},
163-
Mode: ptr.To(asocontainerservicev1preview.AgentPoolMode_User),
164-
EnableAutoScaling: ptr.To(true),
165-
MaxCount: ptr.To(5),
166-
MinCount: ptr.To(2),
167-
NodeTaints: []string{"key1=value1:NoSchedule"},
168-
AvailabilityZones: []string{"zone1"},
169-
MaxPods: ptr.To(60),
170-
OsDiskType: ptr.To(asocontainerservicev1preview.OSDiskType_Managed),
171-
NodeLabels: map[string]string{
172-
"custom": "default",
173-
},
174-
Tags: map[string]string{
175-
"custom": "default",
176-
},
177-
EnableFIPS: ptr.To(true),
178-
EnableEncryptionAtHost: ptr.To(true),
179-
}))
180-
},
181-
},
182-
}
183-
184-
for _, c := range cases {
185-
c := c
186-
t.Run(c.name, func(t *testing.T) {
187-
t.Parallel()
188-
g := NewGomegaWithT(t)
189-
result := AgentPoolToManagedClusterAgentPoolPreviewProfile(c.pool)
190-
c.expect(g, result)
191-
})
192-
}
193-
}

azure/scope/managedcontrolplane.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,6 @@ func (s *ManagedControlPlaneScope) IsManagedVersionUpgrade() bool {
528528
return isManagedVersionUpgrade(s.ControlPlane)
529529
}
530530

531-
// IsPreviewEnabled checks if the preview feature is enabled.
532-
func (s *ManagedControlPlaneScope) IsPreviewEnabled() bool {
533-
return ptr.Deref(s.ControlPlane.Spec.EnablePreviewFeatures, false)
534-
}
535-
536531
func isManagedVersionUpgrade(managedControlPlane *infrav1.AzureManagedControlPlane) bool {
537532
return managedControlPlane.Spec.AutoUpgradeProfile != nil &&
538533
managedControlPlane.Spec.AutoUpgradeProfile.UpgradeChannel != nil &&

azure/services/agentpools/agentpools.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ package agentpools
1919
import (
2020
"context"
2121

22-
asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230202preview"
23-
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
2422
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001/storage"
2523
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
2624
"k8s.io/utils/ptr"
2725
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2826
"sigs.k8s.io/cluster-api-provider-azure/azure"
2927
"sigs.k8s.io/cluster-api-provider-azure/azure/services/aso"
3028
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29+
"sigs.k8s.io/controller-runtime/pkg/conversion"
3130
)
3231

3332
const serviceName = "agentpools"
@@ -62,22 +61,10 @@ func postCreateOrUpdateResourceHook(ctx context.Context, scope AgentPoolScope, o
6261
if err != nil {
6362
return err
6463
}
65-
var existing *asocontainerservicev1.ManagedClustersAgentPool
66-
if scope.IsPreviewEnabled() {
67-
existingPreview := obj.(*asocontainerservicev1preview.ManagedClustersAgentPool)
68-
hub := &asocontainerservicev1hub.ManagedClustersAgentPool{}
69-
if err := existingPreview.ConvertTo(hub); err != nil {
70-
return err
71-
}
72-
stable := &asocontainerservicev1.ManagedClustersAgentPool{}
73-
if err := stable.ConvertFrom(hub); err != nil {
74-
return err
75-
}
76-
existing = stable
77-
} else {
78-
existing = obj.(*asocontainerservicev1.ManagedClustersAgentPool)
64+
agentPool := &asocontainerservicev1hub.ManagedClustersAgentPool{}
65+
if err := obj.(conversion.Convertible).ConvertTo(agentPool); err != nil {
66+
return err
7967
}
80-
agentPool := existing
8168

8269
// When autoscaling is set, add the annotation to the machine pool and update the replica count.
8370
if ptr.Deref(agentPool.Status.EnableAutoScaling, false) {

azure/services/agentpools/agentpools_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
4646
scope := mock_agentpools.NewMockAgentPoolScope(mockCtrl)
4747

4848
scope.EXPECT().RemoveCAPIMachinePoolAnnotation(clusterv1.ReplicasManagedByAnnotation)
49-
scope.EXPECT().IsPreviewEnabled().Return(false)
5049

5150
managedCluster := &asocontainerservicev1.ManagedClustersAgentPool{
5251
Status: asocontainerservicev1.ManagedClusters_AgentPool_STATUS{
@@ -65,7 +64,6 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
6564

6665
scope.EXPECT().SetCAPIMachinePoolAnnotation(clusterv1.ReplicasManagedByAnnotation, "true")
6766
scope.EXPECT().SetCAPIMachinePoolReplicas(ptr.To(1234))
68-
scope.EXPECT().IsPreviewEnabled().Return(false)
6967

7068
managedCluster := &asocontainerservicev1.ManagedClustersAgentPool{
7169
Status: asocontainerservicev1.ManagedClusters_AgentPool_STATUS{
@@ -85,7 +83,6 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
8583

8684
scope.EXPECT().SetCAPIMachinePoolAnnotation(clusterv1.ReplicasManagedByAnnotation, "true")
8785
scope.EXPECT().SetCAPIMachinePoolReplicas(ptr.To(1234))
88-
scope.EXPECT().IsPreviewEnabled().Return(true)
8986

9087
agentPool := &asocontainerservicev1preview.ManagedClustersAgentPool{
9188
Status: asocontainerservicev1preview.ManagedClusters_AgentPool_STATUS{

0 commit comments

Comments
 (0)