diff --git a/pkg/operator/controller/ingress/controller.go b/pkg/operator/controller/ingress/controller.go index 0a208cfd3c..87991d7106 100644 --- a/pkg/operator/controller/ingress/controller.go +++ b/pkg/operator/controller/ingress/controller.go @@ -531,6 +531,11 @@ func computeEffectivePublishingStrategy(ic *operatorv1.IngressController, platfo platformStatus.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { effectiveStrategy.LoadBalancer.DNSManagementPolicy = operatorv1.UnmanagedLoadBalancerDNS } + case configv1.AzurePlatformType: + if platformStatus.Azure != nil && platformStatus.Azure.CloudLoadBalancerConfig != nil && + platformStatus.Azure.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { + effectiveStrategy.LoadBalancer.DNSManagementPolicy = operatorv1.UnmanagedLoadBalancerDNS + } case configv1.GCPPlatformType: if platformStatus.GCP != nil && platformStatus.GCP.CloudLoadBalancerConfig != nil && platformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { @@ -1330,7 +1335,7 @@ func (r *reconciler) allRouterPodsDeleted(ingress *operatorv1.IngressController) return true, nil } -// computeUpdatedInfraFromService updates PlatformStatus for GCP and AWS with Ingress LB IPs when the DNSType is `ClusterHosted`. +// computeUpdatedInfraFromService updates PlatformStatus for AWS, Azure and GCP with Ingress LB IPs when the DNSType is `ClusterHosted`. func computeUpdatedInfraFromService(service *corev1.Service, infraConfig *configv1.Infrastructure) (bool, error) { platformStatus := infraConfig.Status.PlatformStatus if platformStatus == nil { @@ -1373,6 +1378,24 @@ func computeUpdatedInfraFromService(service *corev1.Service, infraConfig *config } } return false, nil + case configv1.AzurePlatformType: + if platformStatus.Azure != nil && platformStatus.Azure.CloudLoadBalancerConfig != nil && platformStatus.Azure.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { + if platformStatus.Azure.CloudLoadBalancerConfig.ClusterHosted == nil { + platformStatus.Azure.CloudLoadBalancerConfig.ClusterHosted = &configv1.CloudLoadBalancerIPs{} + } + ingresses := service.Status.LoadBalancer.Ingress + ingressLBIPs := []configv1.IP{} + for _, ingress := range ingresses { + if len(ingress.IP) > 0 { + ingressLBIPs = append(ingressLBIPs, configv1.IP(ingress.IP)) + } + } + if !cmp.Equal(platformStatus.Azure.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs, ingressLBIPs, ipCmpOpts...) { + platformStatus.Azure.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs = ingressLBIPs + return true, nil + } + } + return false, nil case configv1.GCPPlatformType: if platformStatus.GCP != nil && platformStatus.GCP.CloudLoadBalancerConfig != nil && platformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { if platformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted == nil { diff --git a/pkg/operator/controller/ingress/controller_test.go b/pkg/operator/controller/ingress/controller_test.go index 434f7509ca..23c8297412 100644 --- a/pkg/operator/controller/ingress/controller_test.go +++ b/pkg/operator/controller/ingress/controller_test.go @@ -237,6 +237,29 @@ func TestSetDefaultPublishingStrategySetsPlatformDefaults(t *testing.T) { } } + makeDefaultAzurePlatformStatus = func(platform configv1.PlatformType) *configv1.PlatformStatus { + return &configv1.PlatformStatus{ + Type: platform, + Azure: &configv1.AzurePlatformStatus{ + CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{ + DNSType: configv1.PlatformDefaultDNSType, + }, + }, + } + } + + makeBYODNSAzurePlatformStatus = func(platform configv1.PlatformType) *configv1.PlatformStatus { + return &configv1.PlatformStatus{ + Type: platform, + Azure: &configv1.AzurePlatformStatus{ + CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{ + DNSType: configv1.ClusterHostedDNSType, + ClusterHosted: &configv1.CloudLoadBalancerIPs{}, + }, + }, + } + } + ingressConfigWithDefaultClassicLB = &configv1.Ingress{ Spec: configv1.IngressSpec{ LoadBalancer: configv1.LoadBalancer{ @@ -320,6 +343,18 @@ func TestSetDefaultPublishingStrategySetsPlatformDefaults(t *testing.T) { expectedIC: ingressControllerWithLoadBalancerUnmanagedDNS, domainMatchesBaseDomain: true, }, + { + name: "Azure", + platformStatus: makeDefaultAzurePlatformStatus(configv1.AzurePlatformType), + expectedIC: ingressControllerWithLoadBalancer, + domainMatchesBaseDomain: true, + }, + { + name: "Azure With BYO DNS", + platformStatus: makeBYODNSAzurePlatformStatus(configv1.AzurePlatformType), + expectedIC: ingressControllerWithLoadBalancerUnmanagedDNS, + domainMatchesBaseDomain: true, + }, { name: "GCP", platformStatus: makeDefaultGCPPlatformStatus(configv1.GCPPlatformType), @@ -1617,7 +1652,10 @@ func Test_IsProxyProtocolNeeded(t *testing.T) { func Test_computeUpdatedInfraFromService(t *testing.T) { var ( - IngressLBIP = configv1.IP("196.78.125.4") + IngressLBIP = configv1.IP("196.78.125.4") + nonePlatform = configv1.PlatformStatus{ + Type: configv1.NonePlatformType, + } awsPlatform = configv1.PlatformStatus{ Type: configv1.AWSPlatformType, } @@ -1645,6 +1683,27 @@ func Test_computeUpdatedInfraFromService(t *testing.T) { azurePlatform = configv1.PlatformStatus{ Type: configv1.AzurePlatformType, } + azurePlatformWithDNSType = configv1.PlatformStatus{ + Type: configv1.AzurePlatformType, + Azure: &configv1.AzurePlatformStatus{ + CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{ + DNSType: configv1.ClusterHostedDNSType, + }, + }, + } + azurePlatformWithLBIP = configv1.PlatformStatus{ + Type: configv1.AzurePlatformType, + Azure: &configv1.AzurePlatformStatus{ + CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{ + DNSType: configv1.ClusterHostedDNSType, + ClusterHosted: &configv1.CloudLoadBalancerIPs{ + IngressLoadBalancerIPs: []configv1.IP{ + IngressLBIP, + }, + }, + }, + }, + } gcpPlatform = configv1.PlatformStatus{ Type: configv1.GCPPlatformType, } @@ -1701,7 +1760,7 @@ func Test_computeUpdatedInfraFromService(t *testing.T) { }, { description: "unsupported platform should not cause an error", - platform: &azurePlatform, + platform: &nonePlatform, ingresses: []corev1.LoadBalancerIngress{}, expectUpdated: false, expectError: false, @@ -1782,6 +1841,44 @@ func Test_computeUpdatedInfraFromService(t *testing.T) { expectUpdated: true, expectError: false, }, + { + description: "azure platform without DNSType set", + platform: &azurePlatform, + ingresses: []corev1.LoadBalancerIngress{}, + expectUpdated: false, + expectError: false, + }, + { + description: "azure platform with DNSType and no LB IP", + platform: &azurePlatformWithDNSType, + ingresses: []corev1.LoadBalancerIngress{}, + expectUpdated: false, + expectError: false, + }, + { + description: "azure platform with DNSType and no LB IP in infra config, service has 1 IP", + platform: &azurePlatformWithDNSType, + ingresses: ingresses, + expectedLBIPs: []configv1.IP{IngressLBIP}, + expectUpdated: true, + expectError: false, + }, + { + description: "azure platform with no change to LB IPs", + platform: &azurePlatformWithLBIP, + ingresses: ingresses, + expectedLBIPs: []configv1.IP{IngressLBIP}, + expectUpdated: false, + expectError: false, + }, + { + description: "azure platform with DNSType and LB IP", + platform: &azurePlatformWithLBIP, + ingresses: ingressesWithMultipleIPs, + expectedLBIPs: []configv1.IP{IngressLBIP, configv1.IP("10.10.10.4")}, + expectUpdated: true, + expectError: false, + }, } for _, tc := range testCases { t.Run(tc.description, func(t *testing.T) {