Skip to content

Add ability to disable creation of dns zone for unmanaged installs #5666

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// PrivateDNSZoneMode determines if the Private DNS Zone gets created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment mean that if PrivateDNSZoneMode is not set, the Private DNS Zone is not created? Or is it not created if set to None? I think the comment is fine but may need a bit more clarification.

Copy link
Contributor Author

@sadasu sadasu Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If PrivateDNSZoneMode is not set, it would follow the default behavior where Private DNS Zone will be created. That is the same behavior when its value ti set to PrivateDNSZoneModeSystem.
We set to PrivateDNSZoneModeNone, Private DNS Zone creation would be skipped.

Updated comment to hepefully make it clearer.

// It is created by default on a private cluster and can be skipped based on a configured value.
type PrivateDNSZoneMode string

const (
// ManagedClusterFinalizer allows Reconcile to clean up Azure resources associated with the AzureManagedControlPlane before
// removing it from the apiserver.
ManagedClusterFinalizer = "azuremanagedcontrolplane.infrastructure.cluster.x-k8s.io"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you move ManagedClusterFinalizer to its own const block?


// PrivateDNSZoneModeSystem represents mode System for azuremanagedcontrolplane.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// PrivateDNSZoneModeSystem represents mode System for azuremanagedcontrolplane.
// PrivateDNSZoneModeSystem represents mode System for Private DNS Zones.

I think this is a better description but feel free to disregard if not.

PrivateDNSZoneModeSystem string = "System"
PrivateDNSZoneModeSystem PrivateDNSZoneMode = "System"

// PrivateDNSZoneModeNone represents mode None for azuremanagedcontrolplane.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// PrivateDNSZoneModeNone represents mode None for azuremanagedcontrolplane.
// PrivateDNSZoneModeNone represents mode None for Private DNS Zones.

Same as above

PrivateDNSZoneModeNone string = "None"
PrivateDNSZoneModeNone PrivateDNSZoneMode = "None"
)

// UpgradeChannel determines the type of upgrade channel for automatically upgrading the cluster.
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/types_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ type NetworkClassSpec struct {
// +optional
PrivateDNSZoneName string `json:"privateDNSZoneName,omitempty"`

// PrivateDNSZone enables private dns zone creation modes for a private cluster.
// When unspecified, it defaults to PrivateDNSZoneModeSystem which creates a private DNS zone.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify what are the valid options for this field? Looks like it'll be "System or None". Can this also be validated in a webhook?

// +kubebuilder:validation:Enum=System;None
// +optional
PrivateDNSZone *PrivateDNSZoneMode `json:"privateDNSZone,omitempty"`

// PrivateDNSZoneResourceGroup defines the resource group to be used for Azure Private DNS Zone.
// If not specified, the resource group of the cluster will be used to create the Azure Private DNS Zone.
// +optional
Expand Down
9 changes: 7 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func (s *ClusterScope) VNetSpec() azure.ASOResourceSpecGetter[*asonetworkv1api20

// PrivateDNSSpec returns the private dns zone spec.
func (s *ClusterScope) PrivateDNSSpec() (zoneSpec azure.ResourceSpecGetter, linkSpec, recordSpec []azure.ResourceSpecGetter) {
if s.IsAPIServerPrivate() {
if s.IsAPIServerPrivate() && s.PrivateDNSZoneMode() != infrav1.PrivateDNSZoneModeNone {
resourceGroup := s.ResourceGroup()
if s.AzureCluster.Spec.NetworkSpec.PrivateDNSZoneResourceGroup != "" {
resourceGroup = s.AzureCluster.Spec.NetworkSpec.PrivateDNSZoneResourceGroup
Expand Down Expand Up @@ -1251,3 +1251,13 @@ func (s *ClusterScope) getLastAppliedSecurityRules(nsgName string) map[string]in
}
return lastAppliedSecurityRules
}

// PrivateDNSZoneMode returns the current Private DNS Zone mode.
// When unconfigured, the method returns the default.
// Returned value is used to determine if the Private DNS Zone should be created.
func (s *ClusterScope) PrivateDNSZoneMode() infrav1.PrivateDNSZoneMode {
if s.AzureCluster.Spec.NetworkSpec.PrivateDNSZone == nil {
return infrav1.PrivateDNSZoneModeSystem
}
return *s.AzureCluster.Spec.NetworkSpec.PrivateDNSZone
}
144 changes: 144 additions & 0 deletions azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,58 @@ func TestAPIServerHost(t *testing.T) {
},
want: "apiserver.example.private",
},
{
name: "private apiserver without private dns zone",
azureCluster: infrav1.AzureCluster{
Spec: infrav1.AzureClusterSpec{
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
SubscriptionID: fakeSubscriptionID,
IdentityRef: &corev1.ObjectReference{
Kind: infrav1.AzureClusterIdentityKind,
},
},
ControlPlaneEnabled: true,
NetworkSpec: infrav1.NetworkSpec{
NetworkClassSpec: infrav1.NetworkClassSpec{
PrivateDNSZoneName: "",
PrivateDNSZone: ptr.To(infrav1.PrivateDNSZoneModeNone),
},
APIServerLB: &infrav1.LoadBalancerSpec{
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
Type: infrav1.Internal,
},
},
},
},
},
want: "apiserver.my-cluster.capz.io",
},
{
name: "private apiserver with private dns zone",
azureCluster: infrav1.AzureCluster{
Spec: infrav1.AzureClusterSpec{
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
SubscriptionID: fakeSubscriptionID,
IdentityRef: &corev1.ObjectReference{
Kind: infrav1.AzureClusterIdentityKind,
},
},
ControlPlaneEnabled: true,
NetworkSpec: infrav1.NetworkSpec{
NetworkClassSpec: infrav1.NetworkClassSpec{
PrivateDNSZoneName: "",
PrivateDNSZone: ptr.To(infrav1.PrivateDNSZoneModeSystem),
},
APIServerLB: &infrav1.LoadBalancerSpec{
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
Type: infrav1.Internal,
},
},
},
},
},
want: "apiserver.my-cluster.capz.io",
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -4137,3 +4189,95 @@ func TestAPIServerLBName(t *testing.T) {
})
}
}

func TestPrivateDNSSpec(t *testing.T) {
tests := []struct {
name string
clusterName string
azureClusterNetworkSpec infrav1.NetworkSpec
expectPrivateDNSSpec bool
}{
{
name: "Default PrivateDNSZone (PrivateDNSZoneModeSystem)",
clusterName: "private-default",
azureClusterNetworkSpec: infrav1.NetworkSpec{
NetworkClassSpec: infrav1.NetworkClassSpec{
PrivateDNSZoneName: "fake-privateDNSZoneName",
},
APIServerLB: &infrav1.LoadBalancerSpec{
FrontendIPs: []infrav1.FrontendIP{
{
Name: "api-server-lb-internal-ip",
FrontendIPClass: infrav1.FrontendIPClass{
PrivateIPAddress: infrav1.DefaultInternalLBIPAddress,
},
},
},
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
Type: infrav1.Internal,
},
},
},
expectPrivateDNSSpec: true,
},
{
name: "PrivateDNSZone set to PrivateDNSZoneModeNone",
clusterName: "private-none",
azureClusterNetworkSpec: infrav1.NetworkSpec{
NetworkClassSpec: infrav1.NetworkClassSpec{
PrivateDNSZoneName: "fake-privateDNSZoneName",
PrivateDNSZone: ptr.To(infrav1.PrivateDNSZoneModeNone),
},
APIServerLB: &infrav1.LoadBalancerSpec{
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
Type: infrav1.Internal,
},
},
},
expectPrivateDNSSpec: false,
},
{
name: "Public LB",
clusterName: "public-none",
azureClusterNetworkSpec: infrav1.NetworkSpec{
NetworkClassSpec: infrav1.NetworkClassSpec{
PrivateDNSZoneName: "fake-privateDNSZoneName",
PrivateDNSZone: ptr.To(infrav1.PrivateDNSZoneModeNone),
},
APIServerLB: &infrav1.LoadBalancerSpec{
LoadBalancerClassSpec: infrav1.LoadBalancerClassSpec{
Type: infrav1.Public,
},
},
},
expectPrivateDNSSpec: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

cluster := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: tc.clusterName,
Namespace: "default",
},
}
azureCluster := &infrav1.AzureCluster{
ObjectMeta: metav1.ObjectMeta{
Name: tc.clusterName,
},
Spec: infrav1.AzureClusterSpec{
NetworkSpec: tc.azureClusterNetworkSpec,
},
}

clusterScope := &ClusterScope{
Cluster: cluster,
AzureCluster: azureCluster,
}
zoneSpec, _, _ := clusterScope.PrivateDNSSpec()
g.Expect(zoneSpec != nil).Should(Equal(tc.expectPrivateDNSSpec))
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,14 @@ spec:
description: LBType defines an Azure load balancer Type.
type: string
type: object
privateDNSZone:
description: |-
PrivateDNSZone enables private dns zone creation modes for a private cluster.
When unspecified, it defaults to PrivateDNSZoneModeSystem which creates a private DNS zone.
enum:
- System
- None
type: string
privateDNSZoneName:
description: PrivateDNSZoneName defines the zone name for the
Azure Private DNS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,14 @@ spec:
Type.
type: string
type: object
privateDNSZone:
description: |-
PrivateDNSZone enables private dns zone creation modes for a private cluster.
When unspecified, it defaults to PrivateDNSZoneModeSystem which creates a private DNS zone.
enum:
- System
- None
type: string
privateDNSZoneName:
description: PrivateDNSZoneName defines the zone name
for the Azure Private DNS.
Expand Down
Loading