Skip to content

Commit 05a9dcc

Browse files
committed
fix: mark shared tls cert ready
1 parent 21524ac commit 05a9dcc

File tree

2 files changed

+21
-82
lines changed

2 files changed

+21
-82
lines changed

internal/controller/httpproxy_controller.go

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,50 +1050,13 @@ func (r *HTTPProxyReconciler) buildCertificateStatuses(
10501050
useSharedTLS := hostnameUnderWildcard && r.Config.Gateway.HasDefaultListenerTLSSecret()
10511051

10521052
if useSharedTLS {
1053-
secret := &v1.Secret{}
1054-
secretKey := client.ObjectKey{
1055-
Namespace: downstreamNamespaceName,
1056-
Name: r.Config.Gateway.DefaultListenerTLSSecretName,
1057-
}
1058-
if err := downstreamClient.Get(ctx, secretKey, secret); err != nil {
1059-
if apierrors.IsNotFound(err) {
1060-
apimeta.SetStatusCondition(&hs.Conditions, metav1.Condition{
1061-
Type: networkingv1alpha.HostnameConditionCertificateReady,
1062-
Status: metav1.ConditionFalse,
1063-
Reason: networkingv1alpha.CertificateReadyReasonPending,
1064-
Message: "Shared TLS secret not found in downstream cluster",
1065-
ObservedGeneration: httpProxy.Generation,
1066-
})
1067-
} else {
1068-
apimeta.SetStatusCondition(&hs.Conditions, metav1.Condition{
1069-
Type: networkingv1alpha.HostnameConditionCertificateReady,
1070-
Status: metav1.ConditionUnknown,
1071-
Reason: networkingv1alpha.CertificateReadyReasonPending,
1072-
Message: fmt.Sprintf("Failed to get shared TLS secret: %v", err),
1073-
ObservedGeneration: httpProxy.Generation,
1074-
})
1075-
}
1076-
statuses = append(statuses, hs)
1077-
continue
1078-
}
1079-
1080-
if len(secret.Data["tls.crt"]) > 0 && len(secret.Data["tls.key"]) > 0 {
1081-
apimeta.SetStatusCondition(&hs.Conditions, metav1.Condition{
1082-
Type: networkingv1alpha.HostnameConditionCertificateReady,
1083-
Status: metav1.ConditionTrue,
1084-
Reason: networkingv1alpha.CertificateReadyReasonCertificateIssued,
1085-
Message: "Shared wildcard TLS certificate is ready",
1086-
ObservedGeneration: httpProxy.Generation,
1087-
})
1088-
} else {
1089-
apimeta.SetStatusCondition(&hs.Conditions, metav1.Condition{
1090-
Type: networkingv1alpha.HostnameConditionCertificateReady,
1091-
Status: metav1.ConditionFalse,
1092-
Reason: networkingv1alpha.CertificateReadyReasonPending,
1093-
Message: "Shared TLS secret is missing tls.crt or tls.key data",
1094-
ObservedGeneration: httpProxy.Generation,
1095-
})
1096-
}
1053+
apimeta.SetStatusCondition(&hs.Conditions, metav1.Condition{
1054+
Type: networkingv1alpha.HostnameConditionCertificateReady,
1055+
Status: metav1.ConditionTrue,
1056+
Reason: networkingv1alpha.CertificateReadyReasonCertificateIssued,
1057+
Message: "Using shared wildcard TLS certificate",
1058+
ObservedGeneration: httpProxy.Generation,
1059+
})
10971060
statuses = append(statuses, hs)
10981061
continue
10991062
}

internal/controller/httpproxy_controller_test.go

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,20 +2101,17 @@ func TestBuildCertificateStatuses(t *testing.T) {
21012101
},
21022102
}
21032103

2104-
makeSharedTLSSecret := func(hasTLSData bool) *corev1.Secret {
2105-
s := &corev1.Secret{
2106-
ObjectMeta: metav1.ObjectMeta{
2107-
Namespace: downstreamNamespaceName,
2108-
Name: "wildcard-tls",
2104+
gatewayWithCustomHostname := &gatewayv1.Gateway{
2105+
ObjectMeta: metav1.ObjectMeta{Name: "my-proxy", Namespace: "test-ns"},
2106+
Spec: gatewayv1.GatewaySpec{
2107+
Listeners: []gatewayv1.Listener{
2108+
{
2109+
Name: "https-hostname-0",
2110+
Protocol: gatewayv1.HTTPSProtocolType,
2111+
Hostname: ptr.To(gatewayv1.Hostname("custom.otherdomain.com")),
2112+
},
21092113
},
2110-
}
2111-
if hasTLSData {
2112-
s.Data = map[string][]byte{
2113-
"tls.crt": []byte("cert-data"),
2114-
"tls.key": []byte("key-data"),
2115-
}
2116-
}
2117-
return s
2114+
},
21182115
}
21192116

21202117
tests := []struct {
@@ -2171,41 +2168,20 @@ func TestBuildCertificateStatuses(t *testing.T) {
21712168
wantStatus: metav1.ConditionFalse,
21722169
},
21732170
{
2174-
name: "shared TLS secret found and valid returns CertificateIssued",
2171+
name: "shared TLS marks certificate ready immediately",
21752172
config: &sharedTLSConfig,
21762173
gateway: gatewayWithWildcardHostname,
21772174
downstreamCluster: true,
2178-
downstreamObjects: []client.Object{makeSharedTLSSecret(true)},
2175+
downstreamObjects: []client.Object{},
21792176
wantLen: 1,
21802177
wantReason: networkingv1alpha.CertificateReadyReasonCertificateIssued,
21812178
wantStatus: metav1.ConditionTrue,
2182-
wantMessage: "Shared wildcard TLS certificate is ready",
2183-
},
2184-
{
2185-
name: "shared TLS secret not found returns Pending",
2186-
config: &sharedTLSConfig,
2187-
gateway: gatewayWithWildcardHostname,
2188-
downstreamCluster: true,
2189-
downstreamObjects: []client.Object{},
2190-
wantLen: 1,
2191-
wantReason: networkingv1alpha.CertificateReadyReasonPending,
2192-
wantStatus: metav1.ConditionFalse,
2193-
wantMessage: "Shared TLS secret not found in downstream cluster",
2194-
},
2195-
{
2196-
name: "shared TLS secret missing tls data returns Pending",
2197-
config: &sharedTLSConfig,
2198-
gateway: gatewayWithWildcardHostname,
2199-
downstreamCluster: true,
2200-
downstreamObjects: []client.Object{makeSharedTLSSecret(false)},
2201-
wantLen: 1,
2202-
wantReason: networkingv1alpha.CertificateReadyReasonPending,
2203-
wantStatus: metav1.ConditionFalse,
2204-
wantMessage: "Shared TLS secret is missing tls.crt or tls.key data",
2179+
wantMessage: "Using shared wildcard TLS certificate",
22052180
},
22062181
{
22072182
name: "custom hostname still checks certificate even with shared TLS enabled",
22082183
config: &sharedTLSConfig,
2184+
gateway: gatewayWithCustomHostname,
22092185
downstreamCluster: true,
22102186
downstreamObjects: []client.Object{},
22112187
wantLen: 1,

0 commit comments

Comments
 (0)