Skip to content

Commit 4a331ef

Browse files
committed
Azure UserProvisionedDNS: Update bootstrap, master and worker ignition files
1. Edit bootstrap, master and worker ignition files after they have been created using EditIgnition() which was created as a common method for all platforms supporting this feature 2. Provide EditIgnition() with the api and api-int LB IPs for Azure 3. Stop creating DNS entries for Azure when userProvisionedDNS is enabled
1 parent e064c5f commit 4a331ef

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

pkg/infrastructure/azure/azure.go

Lines changed: 19 additions & 7 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)
@@ -471,6 +473,7 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
471473
lbBaps = loadBalancer.Properties.BackendAddressPools
472474
extLBFQDN = *publicIP.Properties.DNSSettings.Fqdn
473475
pubIPAddress = *publicIP.Properties.IPAddress
476+
p.publicLBIP = pubIPAddress
474477
}
475478

476479
// Save context for other hooks
@@ -483,8 +486,10 @@ func (p *Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput
483486
p.NetworkClientFactory = networkClientFactory
484487
p.lbBackendAddressPools = lbBaps
485488

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

490495
return nil
@@ -714,7 +719,6 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
714719
return nil, fmt.Errorf("failed to get session: %w", err)
715720
}
716721

717-
bootstrapIgnData := in.BootstrapIgnData
718722
subscriptionID := session.Credentials.SubscriptionID
719723

720724
ignitionContainerName := "ignition"
@@ -739,6 +743,13 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
739743
logrus.Debugf("BlobIgnitionContainer.ID=%s", *blobIgnitionContainer.ID)
740744
}
741745

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

744755
if in.InstallConfig.Config.Azure.CustomerManagedKey == nil {
@@ -749,7 +760,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
749760
StorageAccountName: p.StorageAccountName,
750761
StorageAccountKeys: p.StorageAccountKeys,
751762
ClientOpts: p.clientOptions,
752-
BootstrapIgnData: bootstrapIgnData,
763+
BootstrapIgnData: ignOutput.UpdatedBootstrapIgn,
753764
CloudEnvironment: in.InstallConfig.Azure.CloudName,
754765
ContainerName: ignitionContainerName,
755766
BlobName: blobName,
@@ -765,7 +776,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
765776
}
766777
} else {
767778
logrus.Debugf("Creating a Page Blob for ignition shim because Customer Managed Key is provided")
768-
lengthBootstrapFile := int64(len(bootstrapIgnData))
779+
lengthBootstrapFile := int64(len(ignOutput.UpdatedBootstrapIgn))
769780
if lengthBootstrapFile%512 != 0 {
770781
lengthBootstrapFile = (((lengthBootstrapFile / 512) + 1) * 512)
771782
}
@@ -775,7 +786,7 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
775786
BlobURL: blobURL,
776787
ImageURL: "",
777788
StorageAccountName: p.StorageAccountName,
778-
BootstrapIgnData: bootstrapIgnData,
789+
BootstrapIgnData: ignOutput.UpdatedBootstrapIgn,
779790
ImageLength: lengthBootstrapFile,
780791
StorageAccountKeys: p.StorageAccountKeys,
781792
ClientOpts: p.clientOptions,
@@ -791,7 +802,8 @@ func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]
791802

792803
ignSecrets := []*corev1.Secret{
793804
clusterapi.IgnitionSecret(ignShim, in.InfraID, "bootstrap"),
794-
clusterapi.IgnitionSecret(in.MasterIgnData, in.InfraID, "master"),
805+
clusterapi.IgnitionSecret(ignOutput.UpdatedMasterIgn, in.InfraID, "master"),
806+
clusterapi.IgnitionSecret(ignOutput.UpdatedWorkerIgn, in.InfraID, "worker"),
795807
}
796808

797809
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)