Skip to content

Commit 8fcdca7

Browse files
committed
fix: custom hostname cert issuance
1 parent ebc3cba commit 8fcdca7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

internal/controller/gateway_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,19 @@ func (r *GatewayReconciler) ensureListenerCertificates(
514514

515515
isNew := cert.CreationTimestamp.IsZero()
516516
if isNew {
517+
// Use the downstream strategy for anchor-based ownership tracking
518+
// (labels + anchor ConfigMap) so cleanup logic can find these Certs.
517519
if err := downstreamStrategy.SetControllerReference(ctx, upstreamGateway, cert); err != nil {
520+
result.Err = fmt.Errorf("failed to set strategy reference on Certificate %s: %w", certName, err)
521+
return result
522+
}
523+
// Also set the downstream Gateway as the controller owner. The
524+
// downstream certificate solver controller walks the ownership
525+
// chain (Challenge → Order → Certificate → Gateway) to locate
526+
// the Gateway when creating solver HTTPRoutes for HTTP-01
527+
// challenges. Without this, the solver skips the Certificate
528+
// because it cannot resolve the anchor ConfigMap to a Gateway.
529+
if err := controllerutil.SetControllerReference(downstreamGateway, cert, downstreamClient.Scheme()); err != nil {
518530
result.Err = fmt.Errorf("failed to set controller reference on Certificate %s: %w", certName, err)
519531
return result
520532
}

internal/controller/gateway_controller_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ func TestEnsureDownstreamGatewayWildcardCert(t *testing.T) {
280280
existingUpstreamObjects []client.Object
281281
existingDownstreamObjects []client.Object
282282
assert func(t *testing.T, upstreamGateway, downstreamGateway *gatewayv1.Gateway)
283+
assertDownstream func(t *testing.T, downstreamClient client.Client, downstreamGateway *gatewayv1.Gateway)
283284
}{
284285
{
285286
name: "default https listener uses shared TLS secret",
@@ -378,6 +379,19 @@ func TestEnsureDownstreamGatewayWildcardCert(t *testing.T) {
378379
"cert-manager annotation should not be set; Certificates are created directly",
379380
)
380381
},
382+
assertDownstream: func(t *testing.T, downstreamClient client.Client, downstreamGateway *gatewayv1.Gateway) {
383+
var cert cmv1.Certificate
384+
certKey := client.ObjectKey{
385+
Namespace: downstreamGateway.Namespace,
386+
Name: listenerCertificateName("test-gw", "https-hostname-0"),
387+
}
388+
if assert.NoError(t, downstreamClient.Get(context.Background(), certKey, &cert), "Certificate should exist") {
389+
assert.True(t,
390+
metav1.IsControlledBy(&cert, downstreamGateway),
391+
"Certificate should have downstream Gateway as controller owner so the solver controller can find it",
392+
)
393+
}
394+
},
381395
},
382396
{
383397
name: "subdomain of target domain uses shared wildcard cert",
@@ -548,6 +562,10 @@ func TestEnsureDownstreamGatewayWildcardCert(t *testing.T) {
548562
assert.NoError(t, fakeUpstreamClient.Get(ctx, client.ObjectKeyFromObject(tt.upstreamGateway), updatedUpstreamGateway))
549563
tt.assert(t, updatedUpstreamGateway, downstreamGateway)
550564
}
565+
566+
if tt.assertDownstream != nil {
567+
tt.assertDownstream(t, fakeDownstreamClient, downstreamGateway)
568+
}
551569
})
552570
}
553571
}

0 commit comments

Comments
 (0)