mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-30 22:16:22 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user