E2E framework: fix nil pointer crash in TContext

Not all framework instances have a default namespace. TContext
crashed for those.

(cherry picked from commit 80cc14831e)

This got merged in https://github.com/kubernetes/kubernetes/pull/136140,
then reverted in https://github.com/kubernetes/kubernetes/pull/136151 and was
not brought back in https://github.com/kubernetes/kubernetes/pull/136156.
This commit is contained in:
Patrick Ohly
2026-01-09 16:23:11 +01:00
parent e3684b7eb2
commit 0c9c7ce40d

View File

@@ -187,7 +187,9 @@ func (f *Framework) TContext(ctx context.Context) ktesting.TContext {
}
tCtx := ktesting.InitCtx(ctx, f /* intentionally using f here and not f.TB because f overrides some methods */)
tCtx = tCtx.WithClients(f.clientConfig, f.restMapper, f.ClientSet, f.DynamicClient, apiextensions.NewForConfigOrDie(f.clientConfig))
tCtx = tCtx.WithNamespace(f.Namespace.Name)
if f.Namespace != nil {
tCtx = tCtx.WithNamespace(f.Namespace.Name)
}
tCtx = ensureLogger(tCtx)
return tCtx
}