Skip to content

Commit 5e7c361

Browse files
committed
keep stable order of agent pool profiles when reconciling managed cluster
1 parent fc938f4 commit 5e7c361

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

azure/services/managedclusters/spec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"fmt"
2323
"net"
24+
"sort"
2425

2526
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
2627
asocontainerservicev1hub "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001/storage"
@@ -715,6 +716,11 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existingObj genrunt
715716
}
716717
}
717718

719+
// keep a consistent order to prevent unnecessary updates
720+
sort.Slice(prevAgentPoolProfiles, func(i, j int) bool {
721+
return ptr.Deref(prevAgentPoolProfiles[i].Name, "") < ptr.Deref(prevAgentPoolProfiles[j].Name, "")
722+
})
723+
718724
managedCluster.Spec.AgentPoolProfiles = prevAgentPoolProfiles
719725

720726
if s.Preview {

azure/services/managedclusters/spec_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ func TestParameters(t *testing.T) {
5757
&agentpools.AgentPoolSpec{
5858
Replicas: 5,
5959
Mode: "mode",
60-
AzureName: "agentpool",
60+
AzureName: "agentpool-b",
6161
Patches: []string{`{"spec": {"tags": {"from": "patches"}}}`},
6262
},
63+
&agentpools.AgentPoolSpec{
64+
Replicas: 10,
65+
Mode: "mode",
66+
AzureName: "agentpool-a",
67+
},
6368
}, nil
6469
},
6570
PodCIDR: "pod cidr",
@@ -140,11 +145,19 @@ func TestParameters(t *testing.T) {
140145
},
141146
},
142147
AgentPoolProfiles: []asocontainerservicev1.ManagedClusterAgentPoolProfile{
148+
{
149+
Count: ptr.To(10),
150+
EnableAutoScaling: ptr.To(false),
151+
Mode: ptr.To(asocontainerservicev1.AgentPoolMode("mode")),
152+
Name: ptr.To("agentpool-a"),
153+
OsDiskSizeGB: ptr.To(asocontainerservicev1.ContainerServiceOSDisk(0)),
154+
Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
155+
},
143156
{
144157
Count: ptr.To(5),
145158
EnableAutoScaling: ptr.To(false),
146159
Mode: ptr.To(asocontainerservicev1.AgentPoolMode("mode")),
147-
Name: ptr.To("agentpool"),
160+
Name: ptr.To("agentpool-b"),
148161
OsDiskSizeGB: ptr.To(asocontainerservicev1.ContainerServiceOSDisk(0)),
149162
Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets),
150163
Tags: map[string]string{"from": "patches"},

0 commit comments

Comments
 (0)