Skip to content

Commit

Permalink
Merge pull request #4549 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4503-to-release-1.13

[release-1.13] make ServiceCIDR independent in ManagedPools
  • Loading branch information
k8s-ci-robot committed Feb 7, 2024
2 parents b4f1bec + daffc8b commit 739b0f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azure/services/managedclusters/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ func (s *ManagedClusterSpec) Parameters(ctx context.Context, existing *asocontai
}

if s.ServiceCIDR != "" {
managedCluster.Spec.NetworkProfile.ServiceCidr = &s.ServiceCIDR
managedCluster.Spec.NetworkProfile.DnsServiceIP = s.DNSServiceIP
if s.DNSServiceIP == nil {
managedCluster.Spec.NetworkProfile.ServiceCidr = &s.ServiceCIDR
ip, _, err := net.ParseCIDR(s.ServiceCIDR)
if err != nil {
return nil, fmt.Errorf("failed to parse service cidr: %w", err)
Expand Down
31 changes: 31 additions & 0 deletions azure/services/managedclusters/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,35 @@ func TestParameters(t *testing.T) {
g.Expect(actual.Spec.DnsPrefix).To(Equal(ptr.To("managed by CAPZ")))
g.Expect(actual.Spec.EnablePodSecurityPolicy).To(Equal(ptr.To(true)))
})
t.Run("updating existing managed cluster to a non nil DNS Service IP", func(t *testing.T) {
g := NewGomegaWithT(t)

spec := &ManagedClusterSpec{
DNSPrefix: ptr.To("managed by CAPZ"),
Tags: map[string]string{"additional": "tags"},
ServiceCIDR: "123.200.198.0/10",
DNSServiceIP: ptr.To("123.200.198.99"),
}
existing := &asocontainerservicev1.ManagedCluster{
Spec: asocontainerservicev1.ManagedCluster_Spec{
DnsPrefix: ptr.To("set by the user"),
EnablePodSecurityPolicy: ptr.To(true), // set by the user

},
Status: asocontainerservicev1.ManagedCluster_STATUS{
AgentPoolProfiles: []asocontainerservicev1.ManagedClusterAgentPoolProfile_STATUS{},
Tags: map[string]string{},
},
}

actual, err := spec.Parameters(context.Background(), existing)

g.Expect(err).NotTo(HaveOccurred())
g.Expect(actual.Spec.AgentPoolProfiles).To(BeNil())
g.Expect(actual.Spec.Tags).To(BeNil())
g.Expect(actual.Spec.DnsPrefix).To(Equal(ptr.To("managed by CAPZ")))
g.Expect(actual.Spec.EnablePodSecurityPolicy).To(Equal(ptr.To(true)))
g.Expect(actual.Spec.NetworkProfile.DnsServiceIP).To(Equal(ptr.To("123.200.198.99")))
g.Expect(actual.Spec.NetworkProfile.ServiceCidr).To(Equal(ptr.To("123.200.198.0/10")))
})
}

0 comments on commit 739b0f2

Please sign in to comment.