Skip to content

Commit c28507a

Browse files
authored
Merge pull request #4550 from k8s-infra-cherrypick-robot/cherry-pick-4503-to-release-1.12
[release-1.12] make ServiceCIDR independent in ManagedPools
2 parents a22366f + ccd1a4e commit c28507a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

azure/services/managedclusters/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing *asocontai
365365
}
366366

367367
if s.ServiceCIDR != "" {
368+
managedCluster.Spec.NetworkProfile.ServiceCidr = &s.ServiceCIDR
368369
managedCluster.Spec.NetworkProfile.DnsServiceIP = s.DNSServiceIP
369370
if s.DNSServiceIP == nil {
370-
managedCluster.Spec.NetworkProfile.ServiceCidr = &s.ServiceCIDR
371371
ip, _, err := net.ParseCIDR(s.ServiceCIDR)
372372
if err != nil {
373373
return nil, fmt.Errorf("failed to parse service cidr: %w", err)

azure/services/managedclusters/spec_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,35 @@ func TestParameters(t *testing.T) {
262262
g.Expect(actual.Spec.DnsPrefix).To(Equal(ptr.To("managed by CAPZ")))
263263
g.Expect(actual.Spec.EnablePodSecurityPolicy).To(Equal(ptr.To(true)))
264264
})
265+
t.Run("updating existing managed cluster to a non nil DNS Service IP", func(t *testing.T) {
266+
g := NewGomegaWithT(t)
267+
268+
spec := &ManagedClusterSpec{
269+
DNSPrefix: ptr.To("managed by CAPZ"),
270+
Tags: map[string]string{"additional": "tags"},
271+
ServiceCIDR: "123.200.198.0/10",
272+
DNSServiceIP: ptr.To("123.200.198.99"),
273+
}
274+
existing := &asocontainerservicev1.ManagedCluster{
275+
Spec: asocontainerservicev1.ManagedCluster_Spec{
276+
DnsPrefix: ptr.To("set by the user"),
277+
EnablePodSecurityPolicy: ptr.To(true), // set by the user
278+
279+
},
280+
Status: asocontainerservicev1.ManagedCluster_STATUS{
281+
AgentPoolProfiles: []asocontainerservicev1.ManagedClusterAgentPoolProfile_STATUS{},
282+
Tags: map[string]string{},
283+
},
284+
}
285+
286+
actual, err := spec.Parameters(context.Background(), existing)
287+
288+
g.Expect(err).NotTo(HaveOccurred())
289+
g.Expect(actual.Spec.AgentPoolProfiles).To(BeNil())
290+
g.Expect(actual.Spec.Tags).To(BeNil())
291+
g.Expect(actual.Spec.DnsPrefix).To(Equal(ptr.To("managed by CAPZ")))
292+
g.Expect(actual.Spec.EnablePodSecurityPolicy).To(Equal(ptr.To(true)))
293+
g.Expect(actual.Spec.NetworkProfile.DnsServiceIP).To(Equal(ptr.To("123.200.198.99")))
294+
g.Expect(actual.Spec.NetworkProfile.ServiceCidr).To(Equal(ptr.To("123.200.198.0/10")))
295+
})
265296
}

0 commit comments

Comments
 (0)