Skip to content

Commit cb1dbc0

Browse files
authored
Merge pull request #3659 from k8s-infra-cherrypick-robot/cherry-pick-3639-to-release-1.8
[release-1.8] Fix managed clusters and agent pools diffs
2 parents a30c168 + 10773c9 commit cb1dbc0

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

azure/services/agentpools/spec.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p
237237
normalizedProfile.Count = existingProfile.Count
238238
}
239239

240+
// We do a just-in-time merge of existent kubernetes.azure.com-prefixed labels
241+
// So that we don't unintentionally delete them
242+
// See https://github.com/Azure/AKS/issues/3152
243+
if normalizedProfile.NodeLabels != nil {
244+
nodeLabels = mergeSystemNodeLabels(normalizedProfile.NodeLabels, existingPool.NodeLabels)
245+
normalizedProfile.NodeLabels = nodeLabels
246+
}
247+
240248
// Compute a diff to check if we require an update
241249
diff := cmp.Diff(normalizedProfile, existingProfile)
242250
if diff == "" {
@@ -245,12 +253,6 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p
245253
return nil, nil
246254
}
247255
log.V(4).Info("found a diff between the desired spec and the existing agentpool", "difference", diff)
248-
// We do a just-in-time merge of existent kubernetes.azure.com-prefixed labels
249-
// So that we don't unintentionally delete them
250-
// See https://github.com/Azure/AKS/issues/3152
251-
if normalizedProfile.NodeLabels != nil {
252-
nodeLabels = mergeSystemNodeLabels(normalizedProfile.NodeLabels, existingPool.NodeLabels)
253-
}
254256
}
255257

256258
var availabilityZones *[]string

azure/services/agentpools/spec_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,27 @@ func TestParameters(t *testing.T) {
260260
expected: sdkFakeAgentPool(),
261261
expectedError: nil,
262262
},
263+
{
264+
name: "difference in system node labels shouldn't trigger update",
265+
spec: fakeAgentPool(
266+
func(pool *AgentPoolSpec) {
267+
pool.NodeLabels = map[string]*string{
268+
"fake-label": pointer.String("fake-value"),
269+
}
270+
},
271+
),
272+
existing: sdkFakeAgentPool(
273+
func(pool *containerservice.AgentPool) {
274+
pool.NodeLabels = map[string]*string{
275+
"fake-label": pointer.String("fake-value"),
276+
"kubernetes.azure.com/scalesetpriority": pointer.String("spot"),
277+
}
278+
},
279+
sdkWithProvisioningState("Succeeded"),
280+
),
281+
expected: nil,
282+
expectedError: nil,
283+
},
263284
{
264285
name: "parameters with an existing agent pool and update needed on node taints",
265286
spec: fakeAgentPool(),

azure/services/managedclusters/spec.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,14 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing interface{
382382

383383
if s.APIServerAccessProfile != nil {
384384
managedCluster.APIServerAccessProfile = &containerservice.ManagedClusterAPIServerAccessProfile{
385-
AuthorizedIPRanges: &s.APIServerAccessProfile.AuthorizedIPRanges,
386385
EnablePrivateCluster: s.APIServerAccessProfile.EnablePrivateCluster,
387386
PrivateDNSZone: s.APIServerAccessProfile.PrivateDNSZone,
388387
EnablePrivateClusterPublicFQDN: s.APIServerAccessProfile.EnablePrivateClusterPublicFQDN,
389388
}
389+
390+
if len(s.APIServerAccessProfile.AuthorizedIPRanges) > 0 {
391+
managedCluster.APIServerAccessProfile.AuthorizedIPRanges = &s.APIServerAccessProfile.AuthorizedIPRanges
392+
}
390393
}
391394

392395
if s.OutboundType != nil {

azure/services/managedclusters/spec_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ func TestParameters(t *testing.T) {
154154
g.Expect(result).To(BeNil())
155155
},
156156
},
157+
{
158+
name: "no update needed if both clusters have no authorized IP ranges",
159+
existing: getExistingClusterWithAPIServerAccessProfile(),
160+
spec: &ManagedClusterSpec{
161+
Name: "test-managedcluster",
162+
ResourceGroup: "test-rg",
163+
Location: "test-location",
164+
Tags: map[string]string{
165+
"test-tag": "test-value",
166+
},
167+
Version: "v1.22.0",
168+
LoadBalancerSKU: "Standard",
169+
APIServerAccessProfile: &APIServerAccessProfile{
170+
AuthorizedIPRanges: func() []string {
171+
var arr []string
172+
return arr
173+
}(),
174+
},
175+
},
176+
expect: func(g *WithT, result interface{}) {
177+
g.Expect(result).To(BeNil())
178+
},
179+
},
157180
}
158181
for _, tc := range testcases {
159182
tc := tc
@@ -173,6 +196,14 @@ func TestParameters(t *testing.T) {
173196
}
174197
}
175198

199+
func getExistingClusterWithAPIServerAccessProfile() containerservice.ManagedCluster {
200+
mc := getExistingCluster()
201+
mc.APIServerAccessProfile = &containerservice.ManagedClusterAPIServerAccessProfile{
202+
EnablePrivateCluster: pointer.Bool(false),
203+
}
204+
return mc
205+
}
206+
176207
func getExistingCluster() containerservice.ManagedCluster {
177208
mc := getSampleManagedCluster()
178209
mc.ProvisioningState = pointer.String("Succeeded")

0 commit comments

Comments
 (0)