Skip to content

Commit 5a9edbb

Browse files
Merge pull request #10058 from sadasu/azure-custom-dns
CORS-4082, CORS-4086: Azure UserProvisionedDNS: Update bootstrap, master and worker ignition files
2 parents 8a14a07 + f485341 commit 5a9edbb

File tree

4 files changed

+79
-9
lines changed

4 files changed

+79
-9
lines changed

data/data/bootstrap/files/usr/local/bin/bootkube.sh.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ then
493493
copy_static_resources_for nutanix
494494
copy_static_resources_for gcp
495495
copy_static_resources_for aws
496+
copy_static_resources_for azure
496497

497498
cp mco-bootstrap/manifests/* manifests/
498499

pkg/infrastructure/azure/azure.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/openshift/installer/pkg/rhcos"
3232
"github.com/openshift/installer/pkg/types"
3333
aztypes "github.com/openshift/installer/pkg/types/azure"
34+
"github.com/openshift/installer/pkg/types/dns"
3435
)
3536

3637
const (
@@ -64,6 +65,7 @@ type Provider struct {
6465
Tags map[string]*string
6566
clientOptions *arm.ClientOptions
6667
computeClientOptions *arm.ClientOptions
68+
publicLBIP string
6769
}
6870

6971
var _ clusterapi.InfraReadyProvider = (*Provider)(nil)
@@ -436,7 +438,6 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
436438

437439
var lbBaps []*armnetwork.BackendAddressPool
438440
var extLBFQDN string
439-
var pubIPAddress string
440441
if in.InstallConfig.Config.PublicAPI() {
441442
publicIP, err := createPublicIP(ctx, &pipInput{
442443
name: fmt.Sprintf("%s-pip-v4", in.InfraID),
@@ -470,7 +471,7 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
470471
logrus.Debugf("updated external load balancer: %s", *loadBalancer.ID)
471472
lbBaps = loadBalancer.Properties.BackendAddressPools
472473
extLBFQDN = *publicIP.Properties.DNSSettings.Fqdn
473-
pubIPAddress = *publicIP.Properties.IPAddress
474+
p.publicLBIP = *publicIP.Properties.IPAddress
474475
}
475476

476477
// Save context for other hooks
@@ -483,8 +484,10 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
483484
p.NetworkClientFactory = networkClientFactory
484485
p.lbBackendAddressPools = lbBaps
485486

486-
if err := createDNSEntries(ctx, in, extLBFQDN, pubIPAddress, resourceGroupName, p.clientOptions); err != nil {
487-
return fmt.Errorf("error creating DNS records: %w", err)
487+
if in.InstallConfig.Config.Azure.UserProvisionedDNS != dns.UserProvisionedDNSEnabled {
488+
if err := createDNSEntries(ctx, in, extLBFQDN, p.publicLBIP, resourceGroupName, p.clientOptions); err != nil {
489+
return fmt.Errorf("error creating DNS records: %w", err)
490+
}
488491
}
489492

490493
return nil
@@ -714,7 +717,6 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
714717
return nil, fmt.Errorf("failed to get session: %w", err)
715718
}
716719

717-
bootstrapIgnData := in.BootstrapIgnData
718720
subscriptionID := session.Credentials.SubscriptionID
719721

720722
ignitionContainerName := "ignition"
@@ -739,6 +741,13 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
739741
logrus.Debugf("BlobIgnitionContainer.ID=%s", *blobIgnitionContainer.ID)
740742
}
741743

744+
// Edit Bootstrap, Master and Worker ignition files if needed. Currently, these
745+
// ignition files are updated only when userProvisionedDNS is enabled.
746+
ignOutput, err := editIgnition(ctx, in, p.publicLBIP)
747+
if err != nil {
748+
return nil, fmt.Errorf("failed to edit bootstrap, master or worker ignition: %w", err)
749+
}
750+
742751
sasURL := ""
743752

744753
if in.InstallConfig.Config.Azure.CustomerManagedKey == nil {
@@ -749,7 +758,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
749758
StorageAccountName: p.StorageAccountName,
750759
StorageAccountKeys: p.StorageAccountKeys,
751760
ClientOpts: p.clientOptions,
752-
BootstrapIgnData: bootstrapIgnData,
761+
BootstrapIgnData: ignOutput.UpdatedBootstrapIgn,
753762
CloudEnvironment: in.InstallConfig.Azure.CloudName,
754763
ContainerName: ignitionContainerName,
755764
BlobName: blobName,
@@ -765,7 +774,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
765774
}
766775
} else {
767776
logrus.Debugf("Creating a Page Blob for ignition shim because Customer Managed Key is provided")
768-
lengthBootstrapFile := int64(len(bootstrapIgnData))
777+
lengthBootstrapFile := int64(len(ignOutput.UpdatedBootstrapIgn))
769778
if lengthBootstrapFile%512 != 0 {
770779
lengthBootstrapFile = (((lengthBootstrapFile / 512) + 1) * 512)
771780
}
@@ -775,7 +784,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
775784
BlobURL: blobURL,
776785
ImageURL: "",
777786
StorageAccountName: p.StorageAccountName,
778-
BootstrapIgnData: bootstrapIgnData,
787+
BootstrapIgnData: ignOutput.UpdatedBootstrapIgn,
779788
ImageLength: lengthBootstrapFile,
780789
StorageAccountKeys: p.StorageAccountKeys,
781790
ClientOpts: p.clientOptions,
@@ -791,7 +800,8 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
791800

792801
ignSecrets := []*corev1.Secret{
793802
clusterapi.IgnitionSecret(ignShim, in.InfraID, "bootstrap"),
794-
clusterapi.IgnitionSecret(in.MasterIgnData, in.InfraID, "master"),
803+
clusterapi.IgnitionSecret(ignOutput.UpdatedMasterIgn, in.InfraID, "master"),
804+
clusterapi.IgnitionSecret(ignOutput.UpdatedWorkerIgn, in.InfraID, "worker"),
795805
}
796806

797807
return ignSecrets, nil
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package azure
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/sirupsen/logrus"
8+
capz "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
11+
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
12+
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
13+
"github.com/openshift/installer/pkg/types/azure"
14+
"github.com/openshift/installer/pkg/types/dns"
15+
)
16+
17+
// editIgnition attempts to edit the contents of the bootstrap ignition when the user has selected
18+
// a custom DNS configuration. Find the public and private load balancer addresses and fill in the
19+
// infrastructure file within the ignition struct.
20+
func editIgnition(ctx context.Context, in clusterapi.IgnitionInput, publicIP string) (*clusterapi.IgnitionOutput, error) {
21+
// ARO wants the ability to enable custom-dns on day-2. In that case, we might have to
22+
// add LB IPs to Infra CR and within bootstrap Ignition even when `UserProvisionedDNS` is
23+
// not enabled in install-config.
24+
if in.InstallConfig.Config.Azure.UserProvisionedDNS != dns.UserProvisionedDNSEnabled {
25+
return &clusterapi.IgnitionOutput{
26+
UpdatedBootstrapIgn: in.BootstrapIgnData,
27+
UpdatedMasterIgn: in.MasterIgnData,
28+
UpdatedWorkerIgn: in.WorkerIgnData}, nil
29+
}
30+
logrus.Debugf("Azure: Editing Ignition files to start in-cluster DNS when UserProvisionedDNS is enabled")
31+
azureCluster := &capz.AzureCluster{}
32+
key := client.ObjectKey{
33+
Name: in.InfraID,
34+
Namespace: capiutils.Namespace,
35+
}
36+
if err := in.Client.Get(ctx, key, azureCluster); err != nil {
37+
return nil, fmt.Errorf("failed to get Azure cluster: %w", err)
38+
}
39+
if apiLB := azureCluster.Spec.NetworkSpec.APIServerLB; apiLB == nil || len(apiLB.FrontendIPs) == 0 {
40+
return nil, fmt.Errorf("failed to get Azure cluster LB frontend IPs")
41+
}
42+
43+
apiIntLBIP := azureCluster.Spec.NetworkSpec.APIServerLB.FrontendIPs[0].PrivateIPAddress
44+
if apiIntLBIP == "" {
45+
return nil, fmt.Errorf("failed to get Azure cluster API Server Internal LB IP")
46+
}
47+
apiLBIP := apiIntLBIP
48+
// Update API LB IP for public clusters
49+
if in.InstallConfig.Config.PublicAPI() && publicIP != "" {
50+
apiLBIP = publicIP
51+
}
52+
logrus.Debugf("Azure: Editing Ignition files with API LB IP: %s and API Int LB IP: %s", apiLBIP, apiIntLBIP)
53+
return clusterapi.EditIgnition(in, azure.Name, []string{apiLBIP}, []string{apiIntLBIP})
54+
}

pkg/infrastructure/clusterapi/ignition.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/openshift/installer/pkg/asset/machines"
2222
"github.com/openshift/installer/pkg/asset/tls"
2323
awstypes "github.com/openshift/installer/pkg/types/aws"
24+
azuretypes "github.com/openshift/installer/pkg/types/azure"
2425
gcptypes "github.com/openshift/installer/pkg/types/gcp"
2526
)
2627

@@ -154,6 +155,10 @@ func addLoadBalancersToInfra(platform string, config *igntypes.Config, publicLBs
154155
if infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
155156
infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted = &cloudLBInfo
156157
}
158+
case azuretypes.Name:
159+
if infra.Status.PlatformStatus.Azure.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
160+
infra.Status.PlatformStatus.Azure.CloudLoadBalancerConfig.ClusterHosted = &cloudLBInfo
161+
}
157162
default:
158163
return fmt.Errorf("invalid platform %s", platform)
159164
}

0 commit comments

Comments
 (0)