Skip to content

Commit

Permalink
OCPBUGS-15100: Fix invalid DNS name formatting for GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
candita committed Jun 22, 2023
1 parent e068d04 commit 9341a7f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/operator/controller/gateway-service-dns/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gateway_service_dns
import (
"context"
"reflect"
"strings"

logf "github.com/openshift/cluster-ingress-operator/pkg/log"
operatorcontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller"
Expand Down Expand Up @@ -222,6 +223,10 @@ func (r *reconciler) ensureDNSRecordsForGateway(ctx context.Context, gateway *ga
var errs []error
for _, domain := range domains {
name := operatorcontroller.GatewayDNSRecordName(gateway, domain)
// If domain doesn't have a trailing dot, add it
if !strings.HasSuffix(domain, ".") {
domain = domain + "."
}
_, _, err := dnsrecord.EnsureDNSRecord(r.client, name, labels, ownerRef, domain, service)
errs = append(errs, err)
}
Expand Down
35 changes: 30 additions & 5 deletions pkg/operator/controller/gateway-service-dns/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ func Test_Reconcile(t *testing.T) {
},
reconcileRequest: req("openshift-ingress", "example-gateway"),
expectCreate: []client.Object{
dnsrecord("example-gateway-5bfc88bc87-wildcard", "*.prod.example.com", "lb.example.com"),
dnsrecord("example-gateway-57b76476b6-wildcard", "*.stage.example.com", "lb.example.com"),
dnsrecord("example-gateway-5bfc88bc87-wildcard", "*.prod.example.com.", "lb.example.com"),
dnsrecord("example-gateway-57b76476b6-wildcard", "*.stage.example.com.", "lb.example.com"),
},
expectUpdate: []client.Object{},
},
{
name: "gateway with two listeners and one dnsrecord with a stale target",
name: "gateway with two listeners and one dnsrecord with a stale target, hostname already has trailing dot",
existingObjects: []runtime.Object{
gw(
"example-gateway",
Expand All @@ -161,14 +161,39 @@ func Test_Reconcile(t *testing.T) {
},
ingHost("newlb.example.com"),
),
dnsrecord("example-gateway-55bcfdb97d-wildcard", "*.example.com", "oldlb.example.com"),
dnsrecord("example-gateway-55bcfdb97d-wildcard", "*.example.com.", "oldlb.example.com"),
},
reconcileRequest: req("openshift-ingress", "example-gateway"),
expectCreate: []client.Object{},
expectUpdate: []client.Object{
dnsrecord("example-gateway-55bcfdb97d-wildcard", "*.example.com", "newlb.example.com"),
dnsrecord("example-gateway-55bcfdb97d-wildcard", "*.example.com.", "newlb.example.com"),
},
},
{
name: "gateway with two listeners and one host name, no dnsrecords, name ends up with trailing dot",
existingObjects: []runtime.Object{
gw(
"example-gateway",
l("stage-http", "*.stage.example.com", 80),
l("stage-https", "*.stage.example.com", 443),
),
svc(
"example-gateway",
map[string]string{
"gateway.istio.io/managed": "example-gateway",
},
map[string]string{
"istio.io/gateway-name": "example-gateway",
},
ingHost("lb.example.com"),
),
},
reconcileRequest: req("openshift-ingress", "example-gateway"),
expectCreate: []client.Object{
dnsrecord("example-gateway-57b76476b6-wildcard", "*.stage.example.com.", "lb.example.com"),
},
expectUpdate: []client.Object{},
},
}

scheme := runtime.NewScheme()
Expand Down

0 comments on commit 9341a7f

Please sign in to comment.