From 7d31b44bbe3111ab0f823a12d05ecb8b0925bc9a Mon Sep 17 00:00:00 2001 From: tianshapjq Date: Wed, 20 Dec 2017 17:10:31 +0800 Subject: [PATCH] cleanup useless functions and variables --- pkg/client/conditions/BUILD | 1 - pkg/client/conditions/conditions.go | 85 ----------------------------- 2 files changed, 86 deletions(-) diff --git a/pkg/client/conditions/BUILD b/pkg/client/conditions/BUILD index 5c381c4e119..a475e8f1cbd 100644 --- a/pkg/client/conditions/BUILD +++ b/pkg/client/conditions/BUILD @@ -10,7 +10,6 @@ go_library( srcs = ["conditions.go"], importpath = "k8s.io/kubernetes/pkg/client/conditions", deps = [ - "//pkg/api/v1/pod:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", diff --git a/pkg/client/conditions/conditions.go b/pkg/client/conditions/conditions.go index be4c0bfbf36..16255119545 100644 --- a/pkg/client/conditions/conditions.go +++ b/pkg/client/conditions/conditions.go @@ -23,17 +23,12 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/watch" - podutil "k8s.io/kubernetes/pkg/api/v1/pod" ) // 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") -// ErrContainerTerminated is returned by PodContainerRunning in the intermediate -// state where the pod indicates it's still running, but its container is already terminated -var ErrContainerTerminated = fmt.Errorf("container terminated") - // PodRunning returns true if the pod is running, false if the pod has not yet reached running state, // returns ErrPodCompleted if the pod has run to completion, or an error in any other case. func PodRunning(event watch.Event) (bool, error) { @@ -70,86 +65,6 @@ func PodCompleted(event watch.Event) (bool, error) { return false, nil } -// PodRunningAndReady returns true if the pod is running and ready, false if the pod has not -// yet reached those states, returns ErrPodCompleted if the pod has run to completion, or -// an error in any other case. -func PodRunningAndReady(event watch.Event) (bool, error) { - switch event.Type { - case watch.Deleted: - return false, errors.NewNotFound(schema.GroupResource{Resource: "pods"}, "") - } - switch t := event.Object.(type) { - case *v1.Pod: - switch t.Status.Phase { - case v1.PodFailed, v1.PodSucceeded: - return false, ErrPodCompleted - case v1.PodRunning: - return podutil.IsPodReady(t), nil - } - } - return false, nil -} - -// PodNotPending returns true if the pod has left the pending state, false if it has not, -// or an error in any other case (such as if the pod was deleted). -func PodNotPending(event watch.Event) (bool, error) { - switch event.Type { - case watch.Deleted: - return false, errors.NewNotFound(schema.GroupResource{Resource: "pods"}, "") - } - switch t := event.Object.(type) { - case *v1.Pod: - switch t.Status.Phase { - case v1.PodPending: - return false, nil - default: - return true, nil - } - } - return false, nil -} - -// PodContainerRunning returns false until the named container has ContainerStatus running (at least once), -// and will return an error if the pod is deleted, runs to completion, or the container pod is not available. -func PodContainerRunning(containerName string) watch.ConditionFunc { - return func(event watch.Event) (bool, error) { - switch event.Type { - case watch.Deleted: - return false, errors.NewNotFound(schema.GroupResource{Resource: "pods"}, "") - } - switch t := event.Object.(type) { - case *v1.Pod: - switch t.Status.Phase { - case v1.PodRunning, v1.PodPending: - case v1.PodFailed, v1.PodSucceeded: - return false, ErrPodCompleted - default: - return false, nil - } - for _, s := range t.Status.ContainerStatuses { - if s.Name != containerName { - continue - } - if s.State.Terminated != nil { - return false, ErrContainerTerminated - } - return s.State.Running != nil, nil - } - for _, s := range t.Status.InitContainerStatuses { - if s.Name != containerName { - continue - } - if s.State.Terminated != nil { - return false, ErrContainerTerminated - } - return s.State.Running != nil, nil - } - return false, nil - } - return false, nil - } -} - // 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) {