From 5c8d925c8138a38d41dab92227dff2cf3e29f982 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 10 Mar 2020 21:38:54 -0700 Subject: [PATCH 1/4] Test flake wait for default service account --- test/integration/start_stop_delete_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index a7b11c8f42e5..780bcc708d28 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -169,6 +169,26 @@ func TestStartStop(t *testing.T) { // testPodScheduling asserts that this configuration can schedule new pods func testPodScheduling(ctx context.Context, t *testing.T, profile string) { t.Helper() + // to avoid https://github.com/kubernetes/minikube/issues/6997 + // adding this logic to minikube start is not necessary but useful for rare test flakes + saReady := func() error { // check if default service account is created. + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default"))) + if err != nil { + t.Logf("temporary error waiting for default service account: %v",err) + return fmt.Errorf("Error waiting for default service account %v",err) + } + return nil + } + + if err := retry.Expo(saReady, 500*time.Millisecond, time.Second*30); err != nil { + t.Errorf("default service account was not created in 30 seconds.", err) + } + + // schedule a pod to assert persistence + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "-f", filepath.Join(*testdataDir, "busybox.yaml"))) + if err != nil { + t.Fatalf("%s failed: %v", rr.Args, err) + } // schedule a pod to assert persistence rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "-f", filepath.Join(*testdataDir, "busybox.yaml"))) From a8311d722302df89f6c140bf67abd00cb48d1010 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 10 Mar 2020 21:52:26 -0700 Subject: [PATCH 2/4] lint --- test/integration/start_stop_delete_test.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 780bcc708d28..87c361b194a3 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -28,11 +28,13 @@ import ( "strconv" "strings" "testing" + "time" "github.com/docker/machine/libmachine/state" "github.com/google/go-cmp/cmp" "k8s.io/minikube/pkg/minikube/bootstrapper/images" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/util/retry" ) func TestStartStop(t *testing.T) { @@ -172,22 +174,15 @@ func testPodScheduling(ctx context.Context, t *testing.T, profile string) { // to avoid https://github.com/kubernetes/minikube/issues/6997 // adding this logic to minikube start is not necessary but useful for rare test flakes saReady := func() error { // check if default service account is created. - rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default"))) - if err != nil { - t.Logf("temporary error waiting for default service account: %v",err) - return fmt.Errorf("Error waiting for default service account %v",err) + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + t.Logf("temporary error waiting for default service account: %v", err) + return fmt.Errorf("Error waiting for default service account %v", err) } return nil } - if err := retry.Expo(saReady, 500*time.Millisecond, time.Second*30); err != nil { - t.Errorf("default service account was not created in 30 seconds.", err) - } - - // schedule a pod to assert persistence - rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "-f", filepath.Join(*testdataDir, "busybox.yaml"))) - if err != nil { - t.Fatalf("%s failed: %v", rr.Args, err) + if err := retry.Expo(saReady, 500*time.Microsecond, time.Second*30); err != nil { + t.Errorf("default service account was not created in 30 seconds.: %v", err) } // schedule a pod to assert persistence From 654952e93479325e7823413c70e1bcbe1aec0b4a Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 10 Mar 2020 22:13:05 -0700 Subject: [PATCH 3/4] add more checking for default SA --- test/integration/fn_mount_cmd.go | 2 +- test/integration/fn_pvc.go | 2 +- test/integration/functional_test.go | 30 ++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/test/integration/fn_mount_cmd.go b/test/integration/fn_mount_cmd.go index eedc9e7983c8..9bfc880134ba 100644 --- a/test/integration/fn_mount_cmd.go +++ b/test/integration/fn_mount_cmd.go @@ -106,7 +106,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { } start := time.Now() - if err := retry.Expo(checkMount, time.Second, 15*time.Second); err != nil { + if err := retry.Expo(checkMount, time.Second, Seconds(15)); err != nil { // For local testing, allow macOS users to click prompt. If they don't, skip the test. if runtime.GOOS == "darwin" { t.Skip("skipping: mount did not appear, likely because macOS requires prompt to allow non-codesigned binaries to listen on non-localhost port") diff --git a/test/integration/fn_pvc.go b/test/integration/fn_pvc.go index 4f97c830ef0d..0d1f7e5778a8 100644 --- a/test/integration/fn_pvc.go +++ b/test/integration/fn_pvc.go @@ -57,7 +57,7 @@ func validatePersistentVolumeClaim(ctx context.Context, t *testing.T, profile st } // Ensure the addon-manager has created the StorageClass before creating a claim, otherwise it won't be bound - if err := retry.Expo(checkStorageClass, time.Second, 90*time.Second); err != nil { + if err := retry.Expo(checkStorageClass, time.Second, Seconds(90)); err != nil { t.Errorf("no default storage class after retry: %v", err) } diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 8445aa364a7b..1dede00ea021 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -595,6 +595,20 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) { // validateServiceCmd asserts basic "service" command functionality func validateServiceCmd(ctx context.Context, t *testing.T, profile string) { + // to avoid https://github.com/kubernetes/minikube/issues/6997 + // adding this logic to minikube start is not necessary but useful for rare test flakes + saReady := func() error { // check if default service account is created. + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + t.Logf("temporary error waiting for default service account: %v", err) + return fmt.Errorf("Error waiting for default service account %v", err) + } + return nil + } + + if err := retry.Expo(saReady, 500*time.Microsecond, time.Second*30); err != nil { + t.Errorf("default service account was not created in 30 seconds.: %v", err) + } + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "deployment", "hello-node", "--image=gcr.io/hello-minikube-zero-install/hello-node")) if err != nil { t.Logf("%s failed: %v (may not be an error)", rr.Args, err) @@ -710,6 +724,20 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { // validateMySQL validates a minimalist MySQL deployment func validateMySQL(ctx context.Context, t *testing.T, profile string) { + // to avoid https://github.com/kubernetes/minikube/issues/6997 + // adding this logic to minikube start is not necessary but useful for rare test flakes + saReady := func() error { // check if default service account is created. + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + t.Logf("temporary error waiting for default service account: %v", err) + return fmt.Errorf("Error waiting for default service account %v", err) + } + return nil + } + + if err := retry.Expo(saReady, 500*time.Microsecond, time.Second*30); err != nil { + t.Errorf("default service account was not created in 30 seconds.: %v", err) + } + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "replace", "--force", "-f", filepath.Join(*testdataDir, "mysql.yaml"))) if err != nil { t.Fatalf("%s failed: %v", rr.Args, err) @@ -725,7 +753,7 @@ func validateMySQL(ctx context.Context, t *testing.T, profile string) { rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "exec", names[0], "--", "mysql", "-ppassword", "-e", "show databases;")) return err } - if err = retry.Expo(mysql, 5*time.Second, 180*time.Second); err != nil { + if err = retry.Expo(mysql, 5*time.Second, Seconds(180)); err != nil { t.Errorf("mysql failing: %v", err) } } From 50fab2093c8f02390e1e84200f6a9a371791feea Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 10 Mar 2020 22:49:31 -0700 Subject: [PATCH 4/4] missing get --- test/integration/functional_test.go | 4 ++-- test/integration/start_stop_delete_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 1dede00ea021..a333d8c6b3d0 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -598,7 +598,7 @@ func validateServiceCmd(ctx context.Context, t *testing.T, profile string) { // to avoid https://github.com/kubernetes/minikube/issues/6997 // adding this logic to minikube start is not necessary but useful for rare test flakes saReady := func() error { // check if default service account is created. - if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "serviceaccount", "default")); err != nil { t.Logf("temporary error waiting for default service account: %v", err) return fmt.Errorf("Error waiting for default service account %v", err) } @@ -727,7 +727,7 @@ func validateMySQL(ctx context.Context, t *testing.T, profile string) { // to avoid https://github.com/kubernetes/minikube/issues/6997 // adding this logic to minikube start is not necessary but useful for rare test flakes saReady := func() error { // check if default service account is created. - if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "serviceaccount", "default")); err != nil { t.Logf("temporary error waiting for default service account: %v", err) return fmt.Errorf("Error waiting for default service account %v", err) } diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 87c361b194a3..862d78843511 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -174,7 +174,7 @@ func testPodScheduling(ctx context.Context, t *testing.T, profile string) { // to avoid https://github.com/kubernetes/minikube/issues/6997 // adding this logic to minikube start is not necessary but useful for rare test flakes saReady := func() error { // check if default service account is created. - if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "serviceaccount", "default")); err != nil { + if _, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "serviceaccount", "default")); err != nil { t.Logf("temporary error waiting for default service account: %v", err) return fmt.Errorf("Error waiting for default service account %v", err) }