Skip to content

Commit 52ccc2d

Browse files
rahuliiCopilotvepatel
authored
fix: skip secret lookup when tls[].secretName is empty (fixes spurious warning with wildcard TLS) (#10543)
* fix: skip secret lookup when tls[].secretName is empty When an Ingress has a tls: block with no secretName (relying on --wildcard-tls-secret), createIngressEx() was unconditionally attempting secretStore.GetSecret("namespace/") — an invalid key that can never exist — and emitting a spurious warning on every sync: W controller.go] Error trying to get the secret for Ingress <name>: secret doesn't exist or of an unsupported type Note the double space: secretName is "" and prints as blank. The downstream addSSLConfig() already handles this case correctly by falling through to the wildcard cert path when secretName == "" and isWildcardEnabled == true, so TLS works correctly. The warning is a false positive. Fix: guard the lookup with a secretName == "" check and store an empty SecretReference{} instead. The downstream code path is unchanged and wildcard TLS continues to work. At scale (clusters with 3000+ wildcard-TLS ingresses) this removes thousands of spurious warnings per resync and the reload pressure they cause. Fixes #10218 * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Rahul Sawra <r.sawra@gmail.com> --------- Signed-off-by: Rahul Sawra <r.sawra@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Venktesh Patel <ve.patel@f5.com>
1 parent bc5e2cf commit 52ccc2d

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

internal/k8s/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,14 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
27402740

27412741
for _, tls := range ing.Spec.TLS {
27422742
secretName := tls.SecretName
2743+
if secretName == "" {
2744+
// No secretName specified. Skip the store lookup to avoid a spurious
2745+
// "secret doesn't exist" warning on every sync of this Ingress.
2746+
// If --wildcard-tls-secret is configured, NGINX config generation will
2747+
// fall back to the wildcard TLS secret for this host.
2748+
ingEx.SecretRefs[secretName] = &secrets.SecretReference{}
2749+
continue
2750+
}
27432751
secretKey := ing.Namespace + "/" + secretName
27442752

27452753
secretRef := lbc.secretStore.GetSecret(secretKey)

internal/k8s/controller_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,62 @@ func TestCreateIngressEx_SetsWarningWhenPoliciesAnnotationUsedWithoutCustomResou
24352435
}
24362436
}
24372437

2438+
func TestCreateIngressEx_NoSpuriousWarningWhenTLSSecretNameEmpty(t *testing.T) {
2439+
t.Parallel()
2440+
2441+
// Ingress with a tls: block that has no secretName — relies on --wildcard-tls-secret.
2442+
ing := createTestIngress("wildcard-tls-ingress", "example.com")
2443+
ing.Spec.TLS = []networking.IngressTLS{
2444+
{
2445+
Hosts: []string{"example.com"},
2446+
// SecretName intentionally absent — relying on wildcard TLS secret.
2447+
},
2448+
}
2449+
2450+
tests := []struct {
2451+
name string
2452+
wildcardTLSSecret string
2453+
}{
2454+
{
2455+
name: "wildcard TLS configured",
2456+
wildcardTLSSecret: "default/wildcard-tls-secret",
2457+
},
2458+
{
2459+
name: "wildcard TLS not configured",
2460+
wildcardTLSSecret: "",
2461+
},
2462+
}
2463+
2464+
for _, tc := range tests {
2465+
t.Run(tc.name, func(t *testing.T) {
2466+
t.Parallel()
2467+
2468+
lbc := LoadBalancerController{
2469+
namespacedInformers: map[string]*namespacedInformer{
2470+
"default": {},
2471+
},
2472+
secretStore: secrets.NewEmptyFakeSecretsStore(),
2473+
specialSecrets: specialSecrets{
2474+
wildcardTLSSecret: tc.wildcardTLSSecret,
2475+
},
2476+
Logger: nl.LoggerFromContext(context.Background()),
2477+
}
2478+
2479+
ingEx := lbc.createIngressEx(ing, map[string]bool{"example.com": true}, nil)
2480+
2481+
// The empty-secretName entry must be present in SecretRefs with no error —
2482+
// downstream addSSLConfig() reads this key and falls through to the wildcard path.
2483+
ref, exists := ingEx.SecretRefs[""]
2484+
if !exists {
2485+
t.Fatal("expected SecretRefs[\"\"] to exist for empty-secretName TLS block")
2486+
}
2487+
if ref.Error != nil {
2488+
t.Errorf("expected no error in SecretRefs[\"\"] when secretName is empty, got: %v", ref.Error)
2489+
}
2490+
})
2491+
}
2492+
}
2493+
24382494
func TestSyncPolicy_UpdatesMergeableIngressesWhenPolicyChanges(t *testing.T) {
24392495
t.Parallel()
24402496

0 commit comments

Comments
 (0)