kubelet: pass context to GetObjectTTLFromNodeFunc instead of context.Background()

Replace the internal context.Background() call in GetObjectTTLFromNodeFunc
with an explicit ctx parameter, removing the TODO comment.
This commit is contained in:
Ed Bartosh
2026-06-12 17:20:25 +03:00
parent 851b9abda6
commit 08e63e38d9
3 changed files with 6 additions and 7 deletions

View File

@@ -670,9 +670,9 @@ func NewMainKubelet(ctx context.Context,
configMapManager = configmap.NewWatchingConfigMapManager(klet.kubeClient, klet.resyncInterval)
case kubeletconfiginternal.TTLCacheChangeDetectionStrategy:
secretManager = secret.NewCachingSecretManager(
klet.kubeClient, manager.GetObjectTTLFromNodeFunc(klet.GetNode))
klet.kubeClient, manager.GetObjectTTLFromNodeFunc(ctx, klet.GetNode))
configMapManager = configmap.NewCachingConfigMapManager(
klet.kubeClient, manager.GetObjectTTLFromNodeFunc(klet.GetNode))
klet.kubeClient, manager.GetObjectTTLFromNodeFunc(ctx, klet.GetNode))
case kubeletconfiginternal.GetChangeDetectionStrategy:
secretManager = secret.NewSimpleSecretManager(klet.kubeClient)
configMapManager = configmap.NewSimpleConfigMapManager(klet.kubeClient)

View File

@@ -130,11 +130,9 @@ func (s *objectStore) DeleteReference(namespace, name string, _ types.UID) {
// GetObjectTTLFromNodeFunc returns a function that returns TTL value
// from a given Node object.
func GetObjectTTLFromNodeFunc(getNode func(context.Context) (*v1.Node, error)) GetObjectTTLFunc {
func GetObjectTTLFromNodeFunc(ctx context.Context, getNode func(context.Context) (*v1.Node, error)) GetObjectTTLFunc {
return func() (time.Duration, bool) {
// TODO: Pass context from upper level instead of using context.Background().
// This requires changing the GetObjectTTLFunc signature to accept a context parameter.
node, err := getNode(context.Background())
node, err := getNode(ctx)
if err != nil {
return time.Duration(0), false
}

View File

@@ -260,6 +260,7 @@ func TestCustomTTL(t *testing.T) {
}
func TestParseNodeAnnotation(t *testing.T) {
tCtx := ktesting.Init(t)
testCases := []struct {
node *v1.Node
err error
@@ -320,7 +321,7 @@ func TestParseNodeAnnotation(t *testing.T) {
}
for i, testCase := range testCases {
getNode := func(context.Context) (*v1.Node, error) { return testCase.node, testCase.err }
ttl, exists := GetObjectTTLFromNodeFunc(getNode)()
ttl, exists := GetObjectTTLFromNodeFunc(tCtx, getNode)()
if exists != testCase.exists {
t.Errorf("%d: incorrect parsing: %t", i, exists)
continue