diff --git a/pkg/operator/controller/gateway-service-dns/controller.go b/pkg/operator/controller/gateway-service-dns/controller.go index f15f559bd5..e91fe95b9b 100644 --- a/pkg/operator/controller/gateway-service-dns/controller.go +++ b/pkg/operator/controller/gateway-service-dns/controller.go @@ -247,6 +247,9 @@ func (r *reconciler) ensureDNSRecordsForGateway(ctx context.Context, gateway *ga if dnsrecord.ManageDNSForDomain(domain, infraConfig.Status.PlatformStatus, dnsConfig) { dnsPolicy = iov1.ManagedDNS } + if checkClusterHostedDNS(infraConfig) { + dnsPolicy = iov1.UnmanagedDNS + } _, _, err := dnsrecord.EnsureDNSRecord(r.client, name, labels, ownerRef, domain, dnsPolicy, service) errs = append(errs, err) } @@ -282,3 +285,23 @@ func (r *reconciler) deleteStaleDNSRecordsForGateway(ctx context.Context, gatewa } return errs } + +// checkClusterHostedDNS returns true if the platform supports in-cluster DNS and if +// that DNS solution is currently enabled in place of the Cloud provider's default DNS. +func checkClusterHostedDNS(infraConfig *configv1.Infrastructure) bool { + status := infraConfig.Status.PlatformStatus + switch status.Type { + case configv1.AWSPlatformType: + if status.AWS != nil && status.AWS.CloudLoadBalancerConfig != nil && status.AWS.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { + return true + } + return false + case configv1.GCPPlatformType: + if status.GCP != nil && status.GCP.CloudLoadBalancerConfig != nil && status.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType { + return true + } + return false + default: + return false + } +} diff --git a/pkg/operator/controller/gateway-service-dns/controller_test.go b/pkg/operator/controller/gateway-service-dns/controller_test.go index a53b9c8233..98ad733d37 100644 --- a/pkg/operator/controller/gateway-service-dns/controller_test.go +++ b/pkg/operator/controller/gateway-service-dns/controller_test.go @@ -41,6 +41,19 @@ func Test_Reconcile(t *testing.T) { }, }, } + infraConfigWithClusterHostedDNS := &configv1.Infrastructure{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + Status: configv1.InfrastructureStatus{ + PlatformStatus: &configv1.PlatformStatus{ + Type: configv1.GCPPlatformType, + GCP: &configv1.GCPPlatformStatus{ + CloudLoadBalancerConfig: &configv1.CloudLoadBalancerConfig{ + DNSType: configv1.ClusterHostedDNSType, + }, + }, + }, + }, + } gw := func(name string, listeners ...gatewayapiv1.Listener) *gatewayapiv1.Gateway { return &gatewayapiv1.Gateway{ ObjectMeta: metav1.ObjectMeta{ @@ -142,6 +155,20 @@ func Test_Reconcile(t *testing.T) { expectDelete: []client.Object{}, expectError: `infrastructures.config.openshift.io "cluster" not found`, }, + { + name: "platform with ClusterHostedDNS enabled", + existingObjects: []runtime.Object{ + dnsConfig, infraConfigWithClusterHostedDNS, + gw("example-gateway", l("stage-http", "*.stage.example.com", 80)), + svc("example-gateway", exampleManagedGatewayLabel, ingHost("lb.example.com")), + }, + reconcileRequest: req("openshift-ingress", "example-gateway"), + expectCreate: []client.Object{ + dnsrecord("example-gateway-64754456b8-wildcard", "*.stage.example.com.", iov1.UnmanagedDNS, exampleManagedGatewayLabel, "lb.example.com"), + }, + expectUpdate: []client.Object{}, + expectDelete: []client.Object{}, + }, { name: "gateway with no listeners", existingObjects: []runtime.Object{