Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.13] make ServiceCIDR independent in ManagedPools #4549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")))
})
}