@@ -3,6 +3,7 @@ package ingress
33import (
44 "context"
55 "fmt"
6+ "net"
67 "regexp"
78 "regexp/syntax"
89 "strings"
@@ -475,10 +476,17 @@ func setDefaultPublishingStrategy(ic *operatorv1.IngressController, platformStat
475476 }
476477
477478 // When the platform's default DNS solution cannot be used, set the DNSManagementPolicy
478- // accordingly. This feature is currently being implemented first for GCP. Will be
479- // extended to AWS and Azure platforms later.
480- if platformStatus .Type == configv1 .GCPPlatformType && platformStatus .GCP != nil && platformStatus .GCP .CloudLoadBalancerConfig != nil {
481- if platformStatus .GCP .CloudLoadBalancerConfig .DNSType == configv1 .ClusterHostedDNSType {
479+ // accordingly. This feature is currently being implemented for GCP and AWS. Will be
480+ // extended to the Azure platform later.
481+ switch platformStatus .Type {
482+ case configv1 .AWSPlatformType :
483+ if platformStatus .AWS != nil && platformStatus .AWS .CloudLoadBalancerConfig != nil &&
484+ platformStatus .AWS .CloudLoadBalancerConfig .DNSType == configv1 .ClusterHostedDNSType {
485+ effectiveStrategy .LoadBalancer .DNSManagementPolicy = operatorv1 .UnmanagedLoadBalancerDNS
486+ }
487+ case configv1 .GCPPlatformType :
488+ if platformStatus .GCP != nil && platformStatus .GCP .CloudLoadBalancerConfig != nil &&
489+ platformStatus .GCP .CloudLoadBalancerConfig .DNSType == configv1 .ClusterHostedDNSType {
482490 effectiveStrategy .LoadBalancer .DNSManagementPolicy = operatorv1 .UnmanagedLoadBalancerDNS
483491 }
484492 }
@@ -1272,18 +1280,51 @@ func (r *reconciler) allRouterPodsDeleted(ingress *operatorv1.IngressController)
12721280 return true , nil
12731281}
12741282
1275- // computeUpdatedInfraFromService updates GCP's PlatformStatus with Ingress LB IPs when the DNSType is `ClusterHosted`.
1283+ // computeUpdatedInfraFromService updates PlatformStatus for GCP and AWS with Ingress LB IPs when the DNSType is `ClusterHosted`.
12761284func computeUpdatedInfraFromService (service * corev1.Service , infraConfig * configv1.Infrastructure ) (bool , error ) {
12771285 platformStatus := infraConfig .Status .PlatformStatus
12781286 if platformStatus == nil {
12791287 return false , fmt .Errorf ("invalid PlatformStatus within Infrastructure config" )
12801288 }
1289+ ipCmpOpts := []cmp.Option {
1290+ cmpopts .EquateEmpty (),
1291+ cmpopts .SortSlices (func (a , b configv1.IP ) bool {
1292+ return a < b
1293+ }),
1294+ }
1295+ // The cluster has to run its own CoreDNS pod for DNS. Update Infra CR with the Ingress LB IPs.
1296+ // These values are used to configure the in-cluster DNS to provide resolution for *.apps.
12811297 switch platformStatus .Type {
1298+ case configv1 .AWSPlatformType :
1299+ // On the AWS platform, only the Ingress LB's Hostname is available.
1300+ // Resolve this Hostname to its IPs before adding to the Infra CR.
1301+ if platformStatus .AWS != nil && platformStatus .AWS .CloudLoadBalancerConfig != nil && platformStatus .AWS .CloudLoadBalancerConfig .DNSType == configv1 .ClusterHostedDNSType {
1302+ if platformStatus .AWS .CloudLoadBalancerConfig .ClusterHosted == nil {
1303+ platformStatus .AWS .CloudLoadBalancerConfig .ClusterHosted = & configv1.CloudLoadBalancerIPs {}
1304+ }
1305+ ingresses := service .Status .LoadBalancer .Ingress
1306+ ingressLBIPs := []configv1.IP {}
1307+ for _ , ingress := range ingresses {
1308+ // Resolving the LoadBalancer's IPs is not ideal because they may change, but currently there is no better alternative.
1309+ ingressIPs , err := net .LookupIP (ingress .Hostname )
1310+ if err != nil {
1311+ return false , fmt .Errorf ("failed to lookup IP addresses corresponding to AWS LB hostname: %w" , err )
1312+ }
1313+
1314+ if len (ingressIPs ) > 0 {
1315+ for _ , ingressIP := range ingressIPs {
1316+ ingressLBIPs = append (ingressLBIPs , configv1 .IP (ingressIP .String ()))
1317+ }
1318+ }
1319+ }
1320+ if ! cmp .Equal (platformStatus .AWS .CloudLoadBalancerConfig .ClusterHosted .IngressLoadBalancerIPs , ingressLBIPs , ipCmpOpts ... ) {
1321+ platformStatus .AWS .CloudLoadBalancerConfig .ClusterHosted .IngressLoadBalancerIPs = ingressLBIPs
1322+ return true , nil
1323+ }
1324+ }
1325+ return false , nil
12821326 case configv1 .GCPPlatformType :
12831327 if platformStatus .GCP != nil && platformStatus .GCP .CloudLoadBalancerConfig != nil && platformStatus .GCP .CloudLoadBalancerConfig .DNSType == configv1 .ClusterHostedDNSType {
1284- // The cluster has to run its own CoreDNS pod for DNS. Update Infra CR
1285- // with the Ingress LB IPs. These values are used to configure the
1286- // in-cluster DNS to provide resolution for *.apps.
12871328 if platformStatus .GCP .CloudLoadBalancerConfig .ClusterHosted == nil {
12881329 platformStatus .GCP .CloudLoadBalancerConfig .ClusterHosted = & configv1.CloudLoadBalancerIPs {}
12891330 }
@@ -1294,12 +1335,6 @@ func computeUpdatedInfraFromService(service *corev1.Service, infraConfig *config
12941335 ingressLBIPs = append (ingressLBIPs , configv1 .IP (ingress .IP ))
12951336 }
12961337 }
1297- ipCmpOpts := []cmp.Option {
1298- cmpopts .EquateEmpty (),
1299- cmpopts .SortSlices (func (a , b configv1.IP ) bool {
1300- return a < b
1301- }),
1302- }
13031338 if ! cmp .Equal (platformStatus .GCP .CloudLoadBalancerConfig .ClusterHosted .IngressLoadBalancerIPs , ingressLBIPs , ipCmpOpts ... ) {
13041339 platformStatus .GCP .CloudLoadBalancerConfig .ClusterHosted .IngressLoadBalancerIPs = ingressLBIPs
13051340 return true , nil
0 commit comments