Skip to content

Commit

Permalink
Azure: Update DNS to use private zones
Browse files Browse the repository at this point in the history
  • Loading branch information
jhixson74 committed Mar 15, 2024
1 parent ab9fe8f commit 1cf99a6
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 113 deletions.
3 changes: 2 additions & 1 deletion pkg/asset/manifests/azure/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
if err != nil {
return nil, errors.Wrap(err, "failed to split CIDR into subnets")
}
privateDNSZoneName := installConfig.Config.ClusterDomain()

// CAPZ expects the capz-system to be created.
azureNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "capz-system"}}
Expand Down Expand Up @@ -55,7 +56,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
},
NetworkSpec: capz.NetworkSpec{
NetworkClassSpec: capz.NetworkClassSpec{
PrivateDNSZoneName: fmt.Sprintf("api.%s", clusterID.InfraID),
PrivateDNSZoneName: privateDNSZoneName,
},
Vnet: capz.VnetSpec{
ID: installConfig.Config.Azure.VirtualNetwork,
Expand Down
38 changes: 32 additions & 6 deletions pkg/infrastructure/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,16 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
return fmt.Errorf("failed to get session: %w", err)
}

// Create DNS entries
err = createAzureDNSEntries(ctx, in)
if err != nil {
return err
}

installConfig := in.InstallConfig.Config
platform := installConfig.Platform.Azure
subscriptionID := session.Credentials.SubscriptionID
cloudConfiguration := session.CloudConfig
clusterDomain := in.InstallConfig.Config.ClusterDomain()
clusterName := in.InstallConfig.Config.ObjectMeta.Name
baseDomain := in.InstallConfig.Config.BaseDomain

resourceGroupName := p.ResourceGroupName
baseDomainResourceGroupName := in.InstallConfig.Config.Azure.BaseDomainResourceGroupName
storageAccountName := fmt.Sprintf("cluster%s", randomString(5))
containerName := "vhd"
blobName := fmt.Sprintf("rhcos%s.vhd", randomString(5))
Expand Down Expand Up @@ -232,6 +230,34 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
storageURL := fmt.Sprintf("https://%s.blob.core.windows.net", storageAccountName)
blobURL := fmt.Sprintf("%s/%s/%s", storageURL, containerName, blobName)

useIPv6 := false
for _, network := range in.InstallConfig.Config.Networking.ServiceNetwork {
if network.IP.To4() == nil {
useIPv6 = true
}
}

// Create DNS entries
err = CreateDNSEntries(ctx, &CreateDNSEntriesInput{
SubscriptionID: subscriptionID,
ResourceGroupName: resourceGroupName,
BaseDomainResourceGroupName: baseDomainResourceGroupName,
BaseDomain: baseDomain,
ClusterDomain: clusterDomain,
ClusterName: clusterName,
Region: platform.Region,
InfraID: in.InfraID,
Private: in.InstallConfig.Config.Publish == types.InternalPublishingStrategy,
UseIPv6: useIPv6,
Tags: tags,
CloudName: platform.CloudName,
TokenCredential: tokenCredential,
CloudConfiguration: cloudConfiguration,
})
if err != nil {
log.Fatalf("failed to create DNS entries: %v", err)
}

// Create user assigned identity
userAssignedIdentityName := fmt.Sprintf("%s-identity", in.InfraID)
armmsiClientFactory, err := armmsi.NewClientFactory(subscriptionID, tokenCredential, nil)
Expand Down

0 comments on commit 1cf99a6

Please sign in to comment.