Skip to content

Commit 1c6a5d3

Browse files
authored
Merge pull request #5521 from nojnhuh/aso-aks-fix
Ensure all agent pool parameters are preserved in managed cluster creates
2 parents 8bd1865 + 6080b8a commit 1c6a5d3

File tree

3 files changed

+64
-32
lines changed

3 files changed

+64
-32
lines changed

.golangci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- durationcheck # multiplying two durations
1919
- errcheck # unchecked errors
2020
- errchkjson # invalid types passed to json encoder
21+
- exhaustruct # checks if all structure fields are initialized
2122
- gci # ensures imports are organized
2223
- ginkgolinter # ginkgo and gomega
2324
- goconst # strings that can be replaced by constants
@@ -54,6 +55,10 @@ linters:
5455
- whitespace # unnecessary newlines
5556

5657
linters-settings:
58+
exhaustruct:
59+
include:
60+
# Hub ASO agent pools should be fully defined to prevent unnecessary updates
61+
- '.*storage\..*AgentPoolProfile$'
5762
gosec:
5863
excludes:
5964
- G307 # Deferring unsafe method "Close" on type "\*os.File"
@@ -185,9 +190,9 @@ issues:
185190
- path: (^test/|_test.go$)
186191
linters:
187192
- dogsled
193+
- exhaustruct
188194
- goconst
189195
- godot
190-
- prealloc
191196
- path: (^test/|_test.go$)
192197
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
193198
- source: \"github.com/onsi/(ginkgo/v2|gomega)\"

azure/converters/managedagentpool.go

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ limitations under the License.
1717
package converters
1818

1919
import (
20+
// NOTE: when the hub API version is updated, verify the
21+
// ManagedClusterAgentPoolProfile below has every field defined. If a field
22+
// isn't defined, the agent pool will be created with a zero/null value, and
23+
// then updated to the user-defined value. If the field is immutable, this
24+
// update will fail. The linter should catch if there are missing fields,
25+
// but verify that check is actually working.
2026
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20240901/storage"
2127
"k8s.io/utils/ptr"
2228
)
@@ -25,37 +31,50 @@ import (
2531
func AgentPoolToManagedClusterAgentPoolProfile(pool *asocontainerservicev1hub.ManagedClustersAgentPool) asocontainerservicev1hub.ManagedClusterAgentPoolProfile {
2632
properties := pool.Spec
2733
agentPool := asocontainerservicev1hub.ManagedClusterAgentPoolProfile{
28-
Name: ptr.To(pool.AzureName()),
29-
VmSize: properties.VmSize,
30-
OsType: properties.OsType,
31-
OsDiskSizeGB: properties.OsDiskSizeGB,
32-
Count: properties.Count,
33-
Type: properties.Type,
34-
OrchestratorVersion: properties.OrchestratorVersion,
35-
VnetSubnetReference: properties.VnetSubnetReference,
36-
Mode: properties.Mode,
37-
EnableAutoScaling: properties.EnableAutoScaling,
38-
MaxCount: properties.MaxCount,
39-
MinCount: properties.MinCount,
40-
NodeTaints: properties.NodeTaints,
41-
AvailabilityZones: properties.AvailabilityZones,
42-
MaxPods: properties.MaxPods,
43-
OsDiskType: properties.OsDiskType,
44-
NodeLabels: properties.NodeLabels,
45-
EnableUltraSSD: properties.EnableUltraSSD,
46-
EnableNodePublicIP: properties.EnableNodePublicIP,
47-
NodePublicIPPrefixReference: properties.NodePublicIPPrefixReference,
48-
ScaleSetPriority: properties.ScaleSetPriority,
49-
ScaleDownMode: properties.ScaleDownMode,
50-
SpotMaxPrice: properties.SpotMaxPrice,
51-
Tags: properties.Tags,
52-
KubeletDiskType: properties.KubeletDiskType,
53-
LinuxOSConfig: properties.LinuxOSConfig,
54-
EnableFIPS: properties.EnableFIPS,
55-
EnableEncryptionAtHost: properties.EnableEncryptionAtHost,
56-
}
57-
if properties.KubeletConfig != nil {
58-
agentPool.KubeletConfig = properties.KubeletConfig
34+
AvailabilityZones: properties.AvailabilityZones,
35+
CapacityReservationGroupReference: properties.CapacityReservationGroupReference,
36+
Count: properties.Count,
37+
CreationData: properties.CreationData,
38+
EnableAutoScaling: properties.EnableAutoScaling,
39+
EnableEncryptionAtHost: properties.EnableEncryptionAtHost,
40+
EnableFIPS: properties.EnableFIPS,
41+
EnableNodePublicIP: properties.EnableNodePublicIP,
42+
EnableUltraSSD: properties.EnableUltraSSD,
43+
GpuInstanceProfile: properties.GpuInstanceProfile,
44+
HostGroupReference: properties.HostGroupReference,
45+
KubeletConfig: properties.KubeletConfig,
46+
KubeletDiskType: properties.KubeletDiskType,
47+
LinuxOSConfig: properties.LinuxOSConfig,
48+
MaxCount: properties.MaxCount,
49+
MaxPods: properties.MaxPods,
50+
MinCount: properties.MinCount,
51+
Mode: properties.Mode,
52+
Name: ptr.To(pool.AzureName()),
53+
NetworkProfile: properties.NetworkProfile,
54+
NodeLabels: properties.NodeLabels,
55+
NodePublicIPPrefixReference: properties.NodePublicIPPrefixReference,
56+
NodeTaints: properties.NodeTaints,
57+
OrchestratorVersion: properties.OrchestratorVersion,
58+
OsDiskSizeGB: properties.OsDiskSizeGB,
59+
OsDiskType: properties.OsDiskType,
60+
OsSKU: properties.OsSKU,
61+
OsType: properties.OsType,
62+
PodSubnetReference: properties.PodSubnetReference,
63+
PowerState: properties.PowerState,
64+
PropertyBag: properties.PropertyBag,
65+
ProximityPlacementGroupReference: properties.ProximityPlacementGroupReference,
66+
ScaleDownMode: properties.ScaleDownMode,
67+
ScaleSetEvictionPolicy: properties.ScaleSetEvictionPolicy,
68+
ScaleSetPriority: properties.ScaleSetPriority,
69+
SecurityProfile: properties.SecurityProfile,
70+
SpotMaxPrice: properties.SpotMaxPrice,
71+
Tags: properties.Tags,
72+
Type: properties.Type,
73+
UpgradeSettings: properties.UpgradeSettings,
74+
VmSize: properties.VmSize,
75+
VnetSubnetReference: properties.VnetSubnetReference,
76+
WindowsProfile: properties.WindowsProfile,
77+
WorkloadRuntime: properties.WorkloadRuntime,
5978
}
6079
return agentPool
6180
}

pkg/mutators/azureasomanagedcontrolplane.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
"strings"
2424

2525
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
26+
// NOTE: when the hub API version is updated, verify the
27+
// ManagedClusterAgentPoolProfile below has every field defined. If a field
28+
// isn't defined, the agent pool will be created with a zero/null value, and
29+
// then updated to the user-defined value. If the field is immutable, this
30+
// update will fail. The linter should catch if there are missing fields,
31+
// but verify that check is actually working.
2632
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20240901/storage"
2733
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2834
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -350,12 +356,14 @@ func setAgentPoolProfilesFromAgentPools(managedCluster conversion.Convertible, a
350356
ScaleDownMode: hubPool.Spec.ScaleDownMode,
351357
ScaleSetEvictionPolicy: hubPool.Spec.ScaleSetEvictionPolicy,
352358
ScaleSetPriority: hubPool.Spec.ScaleSetPriority,
359+
SecurityProfile: hubPool.Spec.SecurityProfile,
353360
SpotMaxPrice: hubPool.Spec.SpotMaxPrice,
354361
Tags: hubPool.Spec.Tags,
355362
Type: hubPool.Spec.Type,
356363
UpgradeSettings: hubPool.Spec.UpgradeSettings,
357364
VmSize: hubPool.Spec.VmSize,
358365
VnetSubnetReference: hubPool.Spec.VnetSubnetReference,
366+
WindowsProfile: hubPool.Spec.WindowsProfile,
359367
WorkloadRuntime: hubPool.Spec.WorkloadRuntime,
360368
}
361369

0 commit comments

Comments
 (0)