Skip to content

Commit 0fb6bec

Browse files
committed
Ensure no new AKS LBs are created w/ Basic SKU
1 parent 23d5dbb commit 0fb6bec

10 files changed

+52
-23
lines changed

api/v1beta1/azuremanagedcontrolplane_types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ const (
125125
const (
126126
// LoadBalancerSKUStandard is the Standard load balancer SKU.
127127
LoadBalancerSKUStandard = "Standard"
128-
// LoadBalancerSKUBasic is the Basic load balancer SKU.
129-
LoadBalancerSKUBasic = "Basic"
130128
)
131129

132130
// KeyVaultNetworkAccessTypes defines the types of network access of key vault.

api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ func validateVersion(version string, fldPath *field.Path) field.ErrorList {
373373
return allErrs
374374
}
375375

376+
// validateLoadBalancerSKU validates the LoadBalancerSKU.
377+
func validateLoadBalancerSKU(loadBalancerSKU *string, fldPath *field.Path) field.ErrorList {
378+
var allErrs field.ErrorList
379+
if loadBalancerSKU != nil && *loadBalancerSKU != LoadBalancerSKUStandard {
380+
allErrs = append(allErrs, field.Invalid(fldPath, loadBalancerSKU, "LoadBalancerSKU must be 'Standard' if specified"))
381+
}
382+
383+
return allErrs
384+
}
385+
376386
// validateSSHKey validates an SSHKey.
377387
func (m *AzureManagedControlPlane) validateSSHKey(_ client.Client) field.ErrorList {
378388
if sshKey := m.Spec.SSHPublicKey; sshKey != nil && *sshKey != "" {

api/v1beta1/azuremanagedcontrolplane_webhook_test.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,37 @@ func TestValidateVersion(t *testing.T) {
209209
}
210210
}
211211

212+
func TestValidateLoadBalancerSKU(t *testing.T) {
213+
tests := []struct {
214+
name string
215+
loadBalancerSKU *string
216+
expectErr bool
217+
}{
218+
{
219+
name: "Valid Version",
220+
loadBalancerSKU: ptr.To(LoadBalancerSKUStandard),
221+
expectErr: false,
222+
},
223+
{
224+
name: "Invalid Version",
225+
loadBalancerSKU: ptr.To("Basic"),
226+
expectErr: true,
227+
},
228+
}
229+
230+
for _, tt := range tests {
231+
t.Run(tt.name, func(t *testing.T) {
232+
g := NewWithT(t)
233+
allErrs := validateLoadBalancerSKU(tt.loadBalancerSKU, field.NewPath("spec").Child("loadBalancerSKU"))
234+
if tt.expectErr {
235+
g.Expect(allErrs).NotTo(BeNil())
236+
} else {
237+
g.Expect(allErrs).To(BeNil())
238+
}
239+
})
240+
}
241+
}
242+
212243
func TestValidateLoadBalancerProfile(t *testing.T) {
213244
tests := []struct {
214245
name string
@@ -2235,21 +2266,11 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
22352266
Spec: AzureManagedControlPlaneSpec{
22362267
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
22372268
DNSServiceIP: ptr.To("192.168.0.10"),
2238-
LoadBalancerSKU: ptr.To("Standard"),
2239-
Version: "v1.18.0",
2240-
},
2241-
},
2242-
},
2243-
amcp: &AzureManagedControlPlane{
2244-
Spec: AzureManagedControlPlaneSpec{
2245-
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
2246-
DNSServiceIP: ptr.To("192.168.0.10"),
2247-
LoadBalancerSKU: ptr.To(LoadBalancerSKUBasic),
2269+
LoadBalancerSKU: ptr.To(LoadBalancerSKUStandard),
22482270
Version: "v1.18.0",
22492271
},
22502272
},
22512273
},
2252-
wantErr: true,
22532274
},
22542275
{
22552276
name: "AzureManagedControlPlane LoadBalancerSKU is immutable, unsetting is not allowed",

api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (mcp *AzureManagedControlPlaneTemplate) validateManagedControlPlaneTemplate
193193
mcp.Spec.Template.Spec.Version,
194194
field.NewPath("spec").Child("template").Child("spec").Child("version"))...)
195195

196+
allErrs = append(allErrs, validateLoadBalancerSKU(
197+
mcp.Spec.Template.Spec.LoadBalancerSKU,
198+
field.NewPath("spec").Child("template").Child("spec").Child("loadBalancerSKU"))...)
199+
196200
allErrs = append(allErrs, validateLoadBalancerProfile(
197201
mcp.Spec.Template.Spec.LoadBalancerProfile,
198202
field.NewPath("spec").Child("template").Child("spec").Child("loadBalancerProfile"))...)

api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestControlPlaneTemplateDefaultingWebhook(t *testing.T) {
3333
err := mcptw.Default(t.Context(), amcpt)
3434
g.Expect(err).NotTo(HaveOccurred())
3535
g.Expect(*amcpt.Spec.Template.Spec.NetworkPlugin).To(Equal("azure"))
36-
g.Expect(*amcpt.Spec.Template.Spec.LoadBalancerSKU).To(Equal("Standard"))
36+
g.Expect(*amcpt.Spec.Template.Spec.LoadBalancerSKU).To(Equal(LoadBalancerSKUStandard))
3737
g.Expect(amcpt.Spec.Template.Spec.Version).To(Equal("v1.17.5"))
3838
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.CIDRBlock).To(Equal(defaultAKSVnetCIDR))
3939
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooName"))
@@ -42,10 +42,9 @@ func TestControlPlaneTemplateDefaultingWebhook(t *testing.T) {
4242

4343
t.Logf("Testing amcp defaulting webhook with baseline")
4444
netPlug := "kubenet"
45-
lbSKU := "Basic"
45+
lbSKU := "Standard"
4646
netPol := "azure"
4747
amcpt.Spec.Template.Spec.NetworkPlugin = &netPlug
48-
amcpt.Spec.Template.Spec.LoadBalancerSKU = &lbSKU
4948
amcpt.Spec.Template.Spec.NetworkPolicy = &netPol
5049
amcpt.Spec.Template.Spec.Version = "9.99.99"
5150
amcpt.Spec.Template.Spec.VirtualNetwork.Name = "fooVnetName"
@@ -131,10 +130,10 @@ func TestControlPlaneTemplateUpdateWebhook(t *testing.T) {
131130
{
132131
name: "azuremanagedcontrolplanetemplate LoadBalancerSKU is immutable",
133132
oldControlPlaneTemplate: getAzureManagedControlPlaneTemplate(func(cpt *AzureManagedControlPlaneTemplate) {
134-
cpt.Spec.Template.Spec.LoadBalancerSKU = ptr.To("foo")
133+
cpt.Spec.Template.Spec.LoadBalancerSKU = ptr.To(LoadBalancerSKUStandard)
135134
}),
136135
controlPlaneTemplate: getAzureManagedControlPlaneTemplate(func(cpt *AzureManagedControlPlaneTemplate) {
137-
cpt.Spec.Template.Spec.LoadBalancerSKU = ptr.To("bar")
136+
cpt.Spec.Template.Spec.LoadBalancerSKU = ptr.To("Basic")
138137
}),
139138
wantErr: true,
140139
},

api/v1beta1/types_class.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type AzureManagedControlPlaneClassSpec struct {
147147

148148
// LoadBalancerSKU is the SKU of the loadBalancer to be provisioned.
149149
// Immutable.
150-
// +kubebuilder:validation:Enum=Basic;Standard
150+
// +kubebuilder:validation:Enum=Standard
151151
// +kubebuilder:default:=Standard
152152
// +optional
153153
LoadBalancerSKU *string `json:"loadBalancerSKU,omitempty"`

azure/scope/managedcontrolplane.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() azure.ASOResourceSpecGet
577577
managedClusterSpec.NetworkDataplane = s.ControlPlane.Spec.NetworkDataplane
578578
}
579579
if s.ControlPlane.Spec.LoadBalancerSKU != nil {
580-
// CAPZ accepts Standard/Basic, Azure accepts standard/basic
581580
managedClusterSpec.LoadBalancerSKU = strings.ToLower(*s.ControlPlane.Spec.LoadBalancerSKU)
582581
}
583582

azure/services/managedclusters/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type ManagedClusterSpec struct {
6969
// Version defines the desired Kubernetes version.
7070
Version string
7171

72-
// LoadBalancerSKU for the managed cluster. Possible values include: 'Standard', 'Basic'. Defaults to Standard.
72+
// LoadBalancerSKU for the managed cluster. 'Standard' is the only supported value. Defaults to Standard.
7373
LoadBalancerSKU string
7474

7575
// NetworkPlugin used for building Kubernetes network. Possible values include: 'azure', 'kubenet'. Defaults to azure.

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ spec:
595595
LoadBalancerSKU is the SKU of the loadBalancer to be provisioned.
596596
Immutable.
597597
enum:
598-
- Basic
599598
- Standard
600599
type: string
601600
location:

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanetemplates.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ spec:
575575
LoadBalancerSKU is the SKU of the loadBalancer to be provisioned.
576576
Immutable.
577577
enum:
578-
- Basic
579578
- Standard
580579
type: string
581580
location:

0 commit comments

Comments
 (0)