From 86fe8f6472985d276be52c95313cd2e0e1cca859 Mon Sep 17 00:00:00 2001 From: SataQiu <1527062125@qq.com> Date: Fri, 20 Mar 2020 15:13:12 +0800 Subject: [PATCH] e2e/framework: remove direct imports to /pkg/client/conditions Signed-off-by: SataQiu <1527062125@qq.com> --- test/e2e/framework/BUILD | 2 +- test/e2e/framework/pod/BUILD | 1 - test/e2e/framework/pod/resource.go | 9 ++++++--- test/e2e/framework/util.go | 19 +++++++++++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/test/e2e/framework/BUILD b/test/e2e/framework/BUILD index c2a8d33744d..acb3b7fa5df 100644 --- a/test/e2e/framework/BUILD +++ b/test/e2e/framework/BUILD @@ -25,7 +25,6 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/api/v1/pod:go_default_library", - "//pkg/client/conditions:go_default_library", "//pkg/controller:go_default_library", "//pkg/kubelet/apis/config:go_default_library", "//pkg/kubelet/apis/stats/v1alpha1:go_default_library", @@ -49,6 +48,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library", "//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library", "//staging/src/k8s.io/client-go/discovery:go_default_library", "//staging/src/k8s.io/client-go/discovery/cached/memory:go_default_library", diff --git a/test/e2e/framework/pod/BUILD b/test/e2e/framework/pod/BUILD index 16c48229cef..196f712ad9e 100644 --- a/test/e2e/framework/pod/BUILD +++ b/test/e2e/framework/pod/BUILD @@ -12,7 +12,6 @@ go_library( importpath = "k8s.io/kubernetes/test/e2e/framework/pod", visibility = ["//visibility:public"], deps = [ - "//pkg/client/conditions:go_default_library", "//pkg/kubelet/types:go_default_library", "//pkg/kubelet/util/format:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", diff --git a/test/e2e/framework/pod/resource.go b/test/e2e/framework/pod/resource.go index 04a0ae8fa14..da22ad63c4d 100644 --- a/test/e2e/framework/pod/resource.go +++ b/test/e2e/framework/pod/resource.go @@ -33,13 +33,16 @@ import ( "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubectl/pkg/util/podutils" - "k8s.io/kubernetes/pkg/client/conditions" kubetypes "k8s.io/kubernetes/pkg/kubelet/types" e2elog "k8s.io/kubernetes/test/e2e/framework/log" testutils "k8s.io/kubernetes/test/utils" imageutils "k8s.io/kubernetes/test/utils/image" ) +// errPodCompleted is returned by PodRunning or PodContainerRunning to indicate that +// the pod has already reached completed state. +var errPodCompleted = fmt.Errorf("pod ran to completion") + // TODO: Move to its own subpkg. // expectNoError checks if "err" is set, and if so, fails assertion while logging the error. func expectNoError(err error, explain ...interface{}) { @@ -155,7 +158,7 @@ func podRunning(c clientset.Interface, podName, namespace string) wait.Condition case v1.PodRunning: return true, nil case v1.PodFailed, v1.PodSucceeded: - return false, conditions.ErrPodCompleted + return false, errPodCompleted } return false, nil } @@ -184,7 +187,7 @@ func podRunningAndReady(c clientset.Interface, podName, namespace string) wait.C switch pod.Status.Phase { case v1.PodFailed, v1.PodSucceeded: e2elog.Logf("The status of Pod %s is %s which is unexpected", podName, pod.Status.Phase) - return false, conditions.ErrPodCompleted + return false, errPodCompleted case v1.PodRunning: e2elog.Logf("The status of Pod %s is %s (Ready = %v)", podName, pod.Status.Phase, podutils.IsPodReady(pod)) return podutils.IsPodReady(pod), nil diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index af9cba5d425..a97b20dd190 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -50,10 +50,12 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" utilyaml "k8s.io/apimachinery/pkg/util/yaml" + "k8s.io/apimachinery/pkg/watch" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" @@ -62,7 +64,6 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" watchtools "k8s.io/client-go/tools/watch" podutil "k8s.io/kubernetes/pkg/api/v1/pod" - "k8s.io/kubernetes/pkg/client/conditions" "k8s.io/kubernetes/pkg/controller" taintutils "k8s.io/kubernetes/pkg/util/taints" testutils "k8s.io/kubernetes/test/utils" @@ -281,10 +282,24 @@ func waitForServiceAccountInNamespace(c clientset.Interface, ns, serviceAccountN } ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout) defer cancel() - _, err = watchtools.UntilWithoutRetry(ctx, w, conditions.ServiceAccountHasSecrets) + _, err = watchtools.UntilWithoutRetry(ctx, w, serviceAccountHasSecrets) return err } +// serviceAccountHasSecrets returns true if the service account has at least one secret, +// false if it does not, or an error. +func serviceAccountHasSecrets(event watch.Event) (bool, error) { + switch event.Type { + case watch.Deleted: + return false, apierrors.NewNotFound(schema.GroupResource{Resource: "serviceaccounts"}, "") + } + switch t := event.Object.(type) { + case *v1.ServiceAccount: + return len(t.Secrets) > 0, nil + } + return false, nil +} + // WaitForDefaultServiceAccountInNamespace waits for the default service account to be provisioned // the default service account is what is associated with pods when they do not specify a service account // as a result, pods are not able to be provisioned in a namespace until the service account is provisioned