-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OCPBUGS-31521: Don't allow DNS records for gateway to be created if they clash with any existing ingress controller. #1145
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
operatorv1 "github.com/openshift/api/operator/v1" | ||
iov1 "github.com/openshift/api/operatoringress/v1" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
@@ -41,6 +42,17 @@ func Test_Reconcile(t *testing.T) { | |
}, | ||
}, | ||
} | ||
ic := func(name, domain string) *operatorv1.IngressController { | ||
return &operatorv1.IngressController{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "openshift-ingress-operator", | ||
Name: name, | ||
}, | ||
Status: operatorv1.IngressControllerStatus{ | ||
Domain: domain, | ||
}, | ||
} | ||
} | ||
gw := func(name string, listeners ...gatewayapiv1beta1.Listener) *gatewayapiv1beta1.Gateway { | ||
return &gatewayapiv1beta1.Gateway{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -127,6 +139,7 @@ func Test_Reconcile(t *testing.T) { | |
infraConfig, | ||
gw("example-gateway", l("stage-http", "*.stage.example.com", 80)), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{}, | ||
|
@@ -140,6 +153,7 @@ func Test_Reconcile(t *testing.T) { | |
dnsConfig, | ||
gw("example-gateway", l("stage-http", "*.stage.example.com", 80)), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{}, | ||
|
@@ -153,6 +167,7 @@ func Test_Reconcile(t *testing.T) { | |
dnsConfig, infraConfig, | ||
gw("example-gateway"), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{}, | ||
|
@@ -170,6 +185,7 @@ func Test_Reconcile(t *testing.T) { | |
l("prod-https", "*.prod.example.com", 443), | ||
), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
|
@@ -190,6 +206,7 @@ func Test_Reconcile(t *testing.T) { | |
), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("newlb.example.com")), | ||
dnsrecord("example-gateway-7bdcfc8f68-wildcard", "*.example.com.", iov1.ManagedDNS, exampleGatewayLabel, "oldlb.example.com"), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{}, | ||
|
@@ -208,6 +225,7 @@ func Test_Reconcile(t *testing.T) { | |
), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
dnsrecord("example-gateway-64754456b8-wildcard", "*.old.example.com.", iov1.ManagedDNS, exampleGatewayLabel, "lb.example.com"), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
|
@@ -224,6 +242,7 @@ func Test_Reconcile(t *testing.T) { | |
dnsConfig, infraConfig, | ||
gw("example-gateway", l("stage-http", "*.stage.example.com", 80), l("stage-https", "*.stage.example.com", 443)), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
|
@@ -238,6 +257,7 @@ func Test_Reconcile(t *testing.T) { | |
dnsConfig, infraConfig, | ||
gw("example-gateway", l("http", "*.foo.com", 80)), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
|
@@ -246,12 +266,54 @@ func Test_Reconcile(t *testing.T) { | |
expectUpdate: []client.Object{}, | ||
expectDelete: []client.Object{}, | ||
}, | ||
{ | ||
name: "gateway with two unique host names, one of which clashes with an existing ingress controller", | ||
existingObjects: []runtime.Object{ | ||
dnsConfig, infraConfig, | ||
gw( | ||
"example-gateway", | ||
l("stage-https", "*.stage.apps.example.com", 443), | ||
l("apps-https", "*.apps.example.com", 443), | ||
), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
dnsrecord("example-gateway-644bf77744-wildcard", "*.stage.apps.example.com.", iov1.ManagedDNS, exampleGatewayLabel, "lb.example.com"), | ||
}, | ||
expectUpdate: []client.Object{}, | ||
expectDelete: []client.Object{}, | ||
}, | ||
rfredette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
name: "gateway with two unique host names, neither of which clashes with an existing ingress controller", | ||
existingObjects: []runtime.Object{ | ||
dnsConfig, infraConfig, | ||
gw( | ||
"example-gateway", | ||
l("stage-https", "*.stage.apps.example.com", 443), | ||
// apps.example.com looks like it'll clash with the default ic below, but the ic creates a record | ||
// for *.apps.example.com, which doesn't actually clash with apps.example.com | ||
l("apps-https", "apps.example.com", 443), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should clash though, because the DNSRecord for the listener is created as a wildcard and thus will be prefixed with |
||
), | ||
svc("example-gateway", gatewayManagedLabel, exampleGatewayLabel, ingHost("lb.example.com")), | ||
ic("default", "apps.example.com"), | ||
}, | ||
reconcileRequest: req("openshift-ingress", "example-gateway"), | ||
expectCreate: []client.Object{ | ||
dnsrecord("example-gateway-644bf77744-wildcard", "*.stage.apps.example.com.", iov1.ManagedDNS, exampleGatewayLabel, "lb.example.com"), | ||
dnsrecord("example-gateway-54b5446744", "apps.example.com.", iov1.ManagedDNS, exampleGatewayLabel, "lb.example.com"), | ||
}, | ||
expectUpdate: []client.Object{}, | ||
expectDelete: []client.Object{}, | ||
}, | ||
} | ||
|
||
scheme := runtime.NewScheme() | ||
iov1.AddToScheme(scheme) | ||
corev1.AddToScheme(scheme) | ||
gatewayapiv1beta1.AddToScheme(scheme) | ||
operatorv1.AddToScheme(scheme) | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package controller | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
operatorv1 "github.com/openshift/api/operator/v1" | ||
|
||
|
@@ -287,8 +288,12 @@ func ServiceMeshSubscriptionName() types.NamespacedName { | |
// is named using the Gateway's name, listener's hashed host name, and the | ||
// suffix "-wildcard". | ||
func GatewayDNSRecordName(gateway *gatewayapiv1beta1.Gateway, host string) types.NamespacedName { | ||
name := fmt.Sprintf("%s-%s", gateway.Name, util.Hash(host)) | ||
if strings.HasPrefix(host, "*.") { | ||
name = name + "-wildcard" | ||
} | ||
return types.NamespacedName{ | ||
Namespace: gateway.Namespace, | ||
Name: fmt.Sprintf("%s-%s-wildcard", gateway.Name, util.Hash(host)), | ||
Name: name, | ||
Comment on lines
+291
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't change this, the Listener's DNSRecord will always be a wildcard. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use %v instead of %w for errors.