diff --git a/azure/services/managedclusters/spec.go b/azure/services/managedclusters/spec.go index 0e8865b3194..23a699e733e 100644 --- a/azure/services/managedclusters/spec.go +++ b/azure/services/managedclusters/spec.go @@ -21,6 +21,7 @@ import ( "encoding/base64" "fmt" "net" + "sort" asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001" 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 } } + // keep a consistent order to prevent unnecessary updates + sort.Slice(prevAgentPoolProfiles, func(i, j int) bool { + return ptr.Deref(prevAgentPoolProfiles[i].Name, "") < ptr.Deref(prevAgentPoolProfiles[j].Name, "") + }) + managedCluster.Spec.AgentPoolProfiles = prevAgentPoolProfiles if s.Preview { diff --git a/azure/services/managedclusters/spec_test.go b/azure/services/managedclusters/spec_test.go index 23e0dc1c164..a5b388d87cd 100644 --- a/azure/services/managedclusters/spec_test.go +++ b/azure/services/managedclusters/spec_test.go @@ -57,9 +57,14 @@ func TestParameters(t *testing.T) { &agentpools.AgentPoolSpec{ Replicas: 5, Mode: "mode", - AzureName: "agentpool", + AzureName: "agentpool-b", Patches: []string{`{"spec": {"tags": {"from": "patches"}}}`}, }, + &agentpools.AgentPoolSpec{ + Replicas: 10, + Mode: "mode", + AzureName: "agentpool-a", + }, }, nil }, PodCIDR: "pod cidr", @@ -140,11 +145,19 @@ func TestParameters(t *testing.T) { }, }, AgentPoolProfiles: []asocontainerservicev1.ManagedClusterAgentPoolProfile{ + { + Count: ptr.To(10), + EnableAutoScaling: ptr.To(false), + Mode: ptr.To(asocontainerservicev1.AgentPoolMode("mode")), + Name: ptr.To("agentpool-a"), + OsDiskSizeGB: ptr.To(asocontainerservicev1.ContainerServiceOSDisk(0)), + Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets), + }, { Count: ptr.To(5), EnableAutoScaling: ptr.To(false), Mode: ptr.To(asocontainerservicev1.AgentPoolMode("mode")), - Name: ptr.To("agentpool"), + Name: ptr.To("agentpool-b"), OsDiskSizeGB: ptr.To(asocontainerservicev1.ContainerServiceOSDisk(0)), Type: ptr.To(asocontainerservicev1.AgentPoolType_VirtualMachineScaleSets), Tags: map[string]string{"from": "patches"},