Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/operator/controller/gateway-service-dns/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +250 to +252
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain in a comment how this solves the problem of missing DNS name for Gateway objects?

Copy link
Contributor Author

@sadasu sadasu Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom-dns is enabled by the customer when they do not want OpenShift to use the cloud provider's default DNS. So, setting the dnsPolicy to iov1.UnmanagedDNS to cause the Gateway API controller to skip configuring the cloud's DNS.

Copy link
Contributor

@candita candita Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, can the tests provide whatever DNS is likely to be used instead, or at least something resembling DNS? We can't just assume it all works without testing it. Changing the name of this PR might help too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, can the tests provide whatever DNS is likely to be used instead, or at least something resembling DNS? We can't just assume it all works without testing it. Changing the name of this PR might help too.

The custom DNS CI workflows do that: install using on-cluster networking and then add user-provisioned DNS after the install. We will need to add those jobs to run in this repo.

_, _, err := dnsrecord.EnsureDNSRecord(r.client, name, labels, ownerRef, domain, dnsPolicy, service)
errs = append(errs, err)
}
Expand Down Expand Up @@ -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
}
}
27 changes: 27 additions & 0 deletions pkg/operator/controller/gateway-service-dns/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down