Skip to content

Commit 7a8cd67

Browse files
authored
Merge pull request #2637 from nojnhuh/aks-public-ip
add enableNodePublicIP to managed machine pools
2 parents 392137a + be4ad86 commit 7a8cd67

15 files changed

+143
-66
lines changed

azure/converters/managedagentpool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ func AgentPoolToManagedClusterAgentPoolProfile(pool containerservice.AgentPool)
4242
OsDiskType: properties.OsDiskType,
4343
NodeLabels: properties.NodeLabels,
4444
EnableUltraSSD: properties.EnableUltraSSD,
45+
EnableNodePublicIP: properties.EnableNodePublicIP,
4546
}
4647
}

azure/scope/managedmachinepool.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
169169
managedControlPlane.Spec.VirtualNetwork.Name,
170170
managedControlPlane.Spec.VirtualNetwork.Subnet.Name,
171171
),
172-
Mode: managedMachinePool.Spec.Mode,
173-
MaxPods: managedMachinePool.Spec.MaxPods,
174-
AvailabilityZones: managedMachinePool.Spec.AvailabilityZones,
175-
OsDiskType: managedMachinePool.Spec.OsDiskType,
176-
EnableUltraSSD: managedMachinePool.Spec.EnableUltraSSD,
177-
Headers: maps.FilterByKeyPrefix(agentPoolAnnotations, azure.CustomHeaderPrefix),
172+
Mode: managedMachinePool.Spec.Mode,
173+
MaxPods: managedMachinePool.Spec.MaxPods,
174+
AvailabilityZones: managedMachinePool.Spec.AvailabilityZones,
175+
OsDiskType: managedMachinePool.Spec.OsDiskType,
176+
EnableUltraSSD: managedMachinePool.Spec.EnableUltraSSD,
177+
Headers: maps.FilterByKeyPrefix(agentPoolAnnotations, azure.CustomHeaderPrefix),
178+
EnableNodePublicIP: managedMachinePool.Spec.EnableNodePublicIP,
178179
}
179180

180181
if managedMachinePool.Spec.OSDiskSizeGB != nil {

azure/services/agentpools/spec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ type AgentPoolSpec struct {
8989

9090
// Headers is the list of headers to add to the HTTP requests to update this resource.
9191
Headers map[string]string
92+
93+
// EnableNodePublicIP controls whether or not nodes in the agent pool each have a public IP address.
94+
EnableNodePublicIP *bool `json:"enableNodePublicIP,omitempty"`
9295
}
9396

9497
// ResourceName returns the name of the agent pool.
@@ -206,6 +209,7 @@ func (s *AgentPoolSpec) Parameters(existing interface{}) (params interface{}, er
206209
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
207210
VMSize: sku,
208211
VnetSubnetID: vnetSubnetID,
212+
EnableNodePublicIP: s.EnableNodePublicIP,
209213
},
210214
}, nil
211215
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ spec:
205205
items:
206206
type: string
207207
type: array
208+
enableNodePublicIP:
209+
description: EnableNodePublicIP controls whether or not nodes in the
210+
pool each have a public IP address.
211+
type: boolean
208212
enableUltraSSD:
209213
description: EnableUltraSSD enables the storage type UltraSSD_LRS
210214
for the agent pool.

exp/api/v1alpha3/azuremanagedmachinepool_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
4545
dst.Spec.OSType = restored.Spec.OSType
4646
dst.Spec.NodeLabels = restored.Spec.NodeLabels
4747
dst.Spec.EnableUltraSSD = restored.Spec.EnableUltraSSD
48+
dst.Spec.EnableNodePublicIP = restored.Spec.EnableNodePublicIP
4849

4950
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
5051
dst.Status.Conditions = restored.Status.Conditions

exp/api/v1alpha3/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1alpha4/azuremanagedmachinepool_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (src *AzureManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
4545
dst.Spec.OSType = restored.Spec.OSType
4646
dst.Spec.NodeLabels = restored.Spec.NodeLabels
4747
dst.Spec.EnableUltraSSD = restored.Spec.EnableUltraSSD
48+
dst.Spec.EnableNodePublicIP = restored.Spec.EnableNodePublicIP
4849

4950
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
5051
dst.Status.Conditions = restored.Status.Conditions

exp/api/v1alpha4/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1beta1/azuremanagedmachinepool_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ type AzureManagedMachinePoolSpec struct {
9898
// +kubebuilder:validation:Enum=Linux;Windows
9999
// +optional
100100
OSType *string `json:"osType,omitempty"`
101+
102+
// EnableNodePublicIP controls whether or not nodes in the pool each have a public IP address.
103+
// +optional
104+
EnableNodePublicIP *bool `json:"enableNodePublicIP,omitempty"`
101105
}
102106

103107
// ManagedMachinePoolScaling specifies scaling options.

exp/api/v1beta1/azuremanagedmachinepool_webhook.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,32 +197,19 @@ func (m *AzureManagedMachinePool) ValidateUpdate(oldRaw runtime.Object, client c
197197
}
198198
}
199199

200-
if old.Spec.EnableUltraSSD != nil {
201-
// Prevent EnabledUltraSSD modification if it was already set to some value
202-
if m.Spec.EnableUltraSSD == nil {
203-
// unsetting the field is not allowed
204-
allErrs = append(allErrs,
205-
field.Invalid(
206-
field.NewPath("Spec", "EnableUltraSSD"),
207-
m.Spec.EnableUltraSSD,
208-
"field is immutable, unsetting is not allowed"))
209-
} else if *m.Spec.EnableUltraSSD != *old.Spec.EnableUltraSSD {
210-
// changing the field is not allowed
211-
allErrs = append(allErrs,
212-
field.Invalid(
213-
field.NewPath("Spec", "EnableUltraSSD"),
214-
m.Spec.EnableUltraSSD,
215-
"field is immutable"))
216-
}
217-
} else {
218-
if m.Spec.EnableUltraSSD != nil {
219-
allErrs = append(allErrs,
220-
field.Invalid(
221-
field.NewPath("Spec", "EnableUltraSSD"),
222-
m.Spec.EnableUltraSSD,
223-
"field is immutable, unsetting is not allowed"))
224-
}
200+
if err := validateBoolPtrImmutable(
201+
field.NewPath("Spec", "EnableUltraSSD"),
202+
old.Spec.EnableUltraSSD,
203+
m.Spec.EnableUltraSSD); err != nil {
204+
allErrs = append(allErrs, err)
205+
}
206+
if err := validateBoolPtrImmutable(
207+
field.NewPath("Spec", "EnableNodePublicIP"),
208+
old.Spec.EnableNodePublicIP,
209+
m.Spec.EnableNodePublicIP); err != nil {
210+
allErrs = append(allErrs, err)
225211
}
212+
226213
if len(allErrs) != 0 {
227214
return apierrors.NewInvalid(GroupVersion.WithKind("AzureManagedMachinePool").GroupKind(), m.Name, allErrs)
228215
}
@@ -336,3 +323,21 @@ func ensureStringSlicesAreEqual(a []string, b []string) bool {
336323
}
337324
return true
338325
}
326+
327+
func validateBoolPtrImmutable(path *field.Path, oldVal, newVal *bool) *field.Error {
328+
if oldVal != nil {
329+
// Prevent modification if it was already set to some value
330+
if newVal == nil {
331+
// unsetting the field is not allowed
332+
return field.Invalid(path, newVal, "field is immutable, unsetting is not allowed")
333+
}
334+
if *newVal != *oldVal {
335+
// changing the field is not allowed
336+
return field.Invalid(path, newVal, "field is immutable")
337+
}
338+
} else if newVal != nil {
339+
return field.Invalid(path, newVal, "field is immutable, setting is not allowed")
340+
}
341+
342+
return nil
343+
}

0 commit comments

Comments
 (0)