Skip to content

Commit 9a8ee32

Browse files
Merge pull request #4711 from sadasu/aws-custom-dns-generic
CORS-3713: Extend in-cluster DNS support to AWS Platform
2 parents 9856ad1 + 6b0ad96 commit 9a8ee32

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

pkg/controller/template/render.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,15 @@ func cloudPlatformAPIIntLoadBalancerIPs(cfg RenderConfig) (interface{}, error) {
690690
default:
691691
return nil, fmt.Errorf("")
692692
}
693+
case configv1.AWSPlatformType:
694+
switch cloudPlatformLoadBalancerIPState(cfg) {
695+
case availableLBIPState:
696+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.APIIntLoadBalancerIPs, nil
697+
case absentLBIPState:
698+
return nil, fmt.Errorf("AWS API Server IPs unavailable when the DNSType is ClusterHosted")
699+
default:
700+
return nil, fmt.Errorf("")
701+
}
693702
default:
694703
return nil, fmt.Errorf("invalid cloud platform for API Server Internal IPs")
695704
}
@@ -712,6 +721,15 @@ func cloudPlatformAPILoadBalancerIPs(cfg RenderConfig) (interface{}, error) {
712721
default:
713722
return nil, fmt.Errorf("")
714723
}
724+
case configv1.AWSPlatformType:
725+
switch cloudPlatformLoadBalancerIPState(cfg) {
726+
case availableLBIPState:
727+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.APILoadBalancerIPs, nil
728+
case absentLBIPState:
729+
return nil, fmt.Errorf("AWS API Server IPs unavailable when the DNSType is ClusterHosted")
730+
default:
731+
return nil, fmt.Errorf("")
732+
}
715733
default:
716734
return nil, fmt.Errorf("invalid cloud platform for API Server IPs")
717735
}
@@ -734,6 +752,15 @@ func cloudPlatformIngressLoadBalancerIPs(cfg RenderConfig) (interface{}, error)
734752
default:
735753
return nil, fmt.Errorf("")
736754
}
755+
case configv1.AWSPlatformType:
756+
switch cloudPlatformLoadBalancerIPState(cfg) {
757+
case availableLBIPState:
758+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs, nil
759+
case absentLBIPState:
760+
return nil, fmt.Errorf("AWS Ingress IPs unavailable when the DNSType is ClusterHosted")
761+
default:
762+
return nil, fmt.Errorf("")
763+
}
737764
default:
738765
return nil, fmt.Errorf("invalid cloud platform for Ingress LoadBalancer IPs")
739766
}
@@ -747,7 +774,8 @@ func cloudPlatformIngressLoadBalancerIPs(cfg RenderConfig) (interface{}, error)
747774
func cloudPlatformLoadBalancerIPState(cfg RenderConfig) LoadBalancerIPState {
748775
lbIPState := defaultLBIPState
749776
if cfg.Infra.Status.PlatformStatus != nil {
750-
if cfg.Infra.Status.PlatformStatus.Type == configv1.GCPPlatformType {
777+
switch cfg.Infra.Status.PlatformStatus.Type {
778+
case configv1.GCPPlatformType:
751779
// If DNSType is set to `ClusterHosted`, we expect the Load Balancer IP addresses to be set.
752780
// If absent, that is exoected to be temporary.
753781
if cfg.Infra.Status.PlatformStatus.GCP != nil && cfg.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig != nil && cfg.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
@@ -757,6 +785,16 @@ func cloudPlatformLoadBalancerIPState(cfg RenderConfig) LoadBalancerIPState {
757785
lbIPState = absentLBIPState
758786
}
759787
}
788+
case configv1.AWSPlatformType:
789+
// If DNSType is set to `ClusterHosted`, we expect the Load Balancer IP addresses to be set.
790+
// If absent, that is exoected to be temporary.
791+
if cfg.Infra.Status.PlatformStatus.AWS != nil && cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig != nil && cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
792+
if cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted != nil {
793+
lbIPState = availableLBIPState
794+
} else {
795+
lbIPState = absentLBIPState
796+
}
797+
}
760798
}
761799
}
762800
return lbIPState

pkg/operator/bootstrap.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ func appendManifestsByPlatform(manifests []manifest, infra configv1.Infrastructu
271271
manifests = getPlatformManifests(manifests, strings.ToLower(string(configv1.GCPPlatformType)), lbType)
272272
}
273273
}
274+
if infra.Status.PlatformStatus.AWS != nil {
275+
// Generate just the CoreDNS manifests for the AWS platform only when the DNSType is `ClusterHosted`.
276+
if infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig != nil && infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
277+
// We do not need the keepalived manifests to be generated because the cloud default Load Balancers are in use.
278+
// So, setting the lbType to `UserManaged` although the default cloud LBs are not user managed.
279+
lbType = configv1.LoadBalancerTypeUserManaged
280+
manifests = getPlatformManifests(manifests, strings.ToLower(string(configv1.AWSPlatformType)), lbType)
281+
}
282+
}
274283

275284
return manifests
276285
}
@@ -301,7 +310,7 @@ func getPlatformManifests(manifests []manifest, platformName string, lbType conf
301310
var corednsName string
302311
var corefileName string
303312
switch platformName {
304-
case strings.ToLower(string(configv1.GCPPlatformType)):
313+
case strings.ToLower(string(configv1.GCPPlatformType)), strings.ToLower(string(configv1.AWSPlatformType)):
305314
corednsName = "manifests/cloud-platform-alt-dns/coredns.yaml"
306315
corefileName = "manifests/cloud-platform-alt-dns/coredns-corefile.tmpl"
307316
default:

pkg/operator/render.go

+40-2
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ func cloudPlatformAPIIntLoadBalancerIPs(cfg mcfgv1.ControllerConfigSpec) (interf
382382
default:
383383
return nil, fmt.Errorf("")
384384
}
385+
case configv1.AWSPlatformType:
386+
switch cloudPlatformLoadBalancerIPState(cfg) {
387+
case availableLBIPState:
388+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.APIIntLoadBalancerIPs, nil
389+
case absentLBIPState:
390+
return nil, fmt.Errorf("AWS API Server Internal IPs unavailable when the DNSType is ClusterHosted")
391+
default:
392+
return nil, fmt.Errorf("")
393+
}
385394
default:
386395
return nil, fmt.Errorf("invalid cloud platform for API Server Internal IP")
387396
}
@@ -404,6 +413,15 @@ func cloudPlatformAPILoadBalancerIPs(cfg mcfgv1.ControllerConfigSpec) (interface
404413
default:
405414
return nil, fmt.Errorf("")
406415
}
416+
case configv1.AWSPlatformType:
417+
switch cloudPlatformLoadBalancerIPState(cfg) {
418+
case availableLBIPState:
419+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.APILoadBalancerIPs, nil
420+
case absentLBIPState:
421+
return nil, fmt.Errorf("AWS API Server IPs unavailable when the DNSType is ClusterHosted")
422+
default:
423+
return nil, fmt.Errorf("")
424+
}
407425
default:
408426
return nil, fmt.Errorf("invalid cloud platform for API Server IPs")
409427
}
@@ -426,6 +444,15 @@ func cloudPlatformIngressLoadBalancerIPs(cfg mcfgv1.ControllerConfigSpec) (inter
426444
default:
427445
return nil, fmt.Errorf("")
428446
}
447+
case configv1.AWSPlatformType:
448+
switch cloudPlatformLoadBalancerIPState(cfg) {
449+
case availableLBIPState:
450+
return cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs, nil
451+
case absentLBIPState:
452+
return nil, fmt.Errorf("AWS Ingress IPs unavailable when the DNSType is ClusterHosted")
453+
default:
454+
return nil, fmt.Errorf("")
455+
}
429456
default:
430457
return nil, fmt.Errorf("invalid cloud platform for Ingress LoadBalancer IPs")
431458
}
@@ -439,16 +466,27 @@ func cloudPlatformIngressLoadBalancerIPs(cfg mcfgv1.ControllerConfigSpec) (inter
439466
func cloudPlatformLoadBalancerIPState(cfg mcfgv1.ControllerConfigSpec) LoadBalancerIPState {
440467
lbIPState := defaultLBIPState
441468
if cfg.Infra.Status.PlatformStatus != nil {
442-
if cfg.Infra.Status.PlatformStatus.Type == configv1.GCPPlatformType {
469+
switch cfg.Infra.Status.PlatformStatus.Type {
470+
case configv1.GCPPlatformType:
443471
// If DNSType is set to `ClusterHosted`, we expect the Load Balancer IP addresses to be set.
444-
// If absent, that is exoected to be temporary.
472+
// If absent, that is expected to be temporary.
445473
if cfg.Infra.Status.PlatformStatus.GCP != nil && cfg.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig != nil && cfg.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
446474
if cfg.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted != nil {
447475
lbIPState = availableLBIPState
448476
} else {
449477
lbIPState = absentLBIPState
450478
}
451479
}
480+
case configv1.AWSPlatformType:
481+
// If DNSType is set to `ClusterHosted`, we expect the Load Balancer IP addresses to be set.
482+
// If absent, that is expected to be temporary.
483+
if cfg.Infra.Status.PlatformStatus.AWS != nil && cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig != nil && cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
484+
if cfg.Infra.Status.PlatformStatus.AWS.CloudLoadBalancerConfig.ClusterHosted != nil {
485+
lbIPState = availableLBIPState
486+
} else {
487+
lbIPState = absentLBIPState
488+
}
489+
}
452490
}
453491
}
454492
return lbIPState

0 commit comments

Comments
 (0)