mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
kubeadm: use separate context in GetConfigMapWithShortRetry
Intentionally pass a new context to this API call. This will let the API call run independently of the parent context timeout, which is quite short and can cause the API call to return abruptly.
This commit is contained in:
@@ -237,54 +237,3 @@ func TestMutateConfigMapWithConflict(t *testing.T) {
|
||||
t.Fatalf("ConfigMap mutation with conflict was invalid, has: %q", cm.Data["key"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConfigMapWithShortRetry(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
reactorFunc func(core.Action) (bool, runtime.Object, error)
|
||||
errorCheckFunc func(*testing.T, error)
|
||||
}{
|
||||
{
|
||||
name: "context deadline exceeded error is handled",
|
||||
reactorFunc: func(core.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, context.DeadlineExceeded
|
||||
},
|
||||
errorCheckFunc: func(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "would exceed context deadline error is handled",
|
||||
reactorFunc: func(core.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, errors.New("Wait returned an error: rate: Wait(n=1) would exceed context deadline")
|
||||
},
|
||||
errorCheckFunc: func(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "API error is not handled",
|
||||
reactorFunc: func(core.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, apierrors.NewNotFound(schema.GroupResource{}, "")
|
||||
},
|
||||
errorCheckFunc: func(t *testing.T, err error) {
|
||||
if !apierrors.IsNotFound(err) {
|
||||
t.Errorf("expected error: IsNotFound, got: %v", err)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
client := fake.NewSimpleClientset()
|
||||
client.PrependReactor("get", "configmaps", tc.reactorFunc)
|
||||
_, err := GetConfigMapWithShortRetry(client, "foo", "bar")
|
||||
tc.errorCheckFunc(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user