diff --git a/pkg/controller/deployment/util/BUILD b/pkg/controller/deployment/util/BUILD index 23b57cdc39f..faba8b5e1a6 100644 --- a/pkg/controller/deployment/util/BUILD +++ b/pkg/controller/deployment/util/BUILD @@ -8,14 +8,9 @@ load( go_library( name = "go_default_library", - srcs = [ - "deployment_util.go", - "pod_util.go", - "replicaset_util.go", - ], + srcs = ["deployment_util.go"], importpath = "k8s.io/kubernetes/pkg/controller/deployment/util", deps = [ - "//pkg/apis/extensions:go_default_library", "//pkg/controller:go_default_library", "//pkg/util/labels:go_default_library", "//staging/src/k8s.io/api/apps/v1:go_default_library", @@ -25,15 +20,10 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//staging/src/k8s.io/client-go/kubernetes/typed/apps/v1:go_default_library", - "//staging/src/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library", - "//staging/src/k8s.io/client-go/listers/apps/v1:go_default_library", - "//staging/src/k8s.io/client-go/listers/core/v1:go_default_library", "//staging/src/k8s.io/client-go/util/integer:go_default_library", - "//staging/src/k8s.io/client-go/util/retry:go_default_library", "//vendor/github.com/golang/glog:go_default_library", ], ) diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index 3bab33a4c10..f2099d7c879 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -37,7 +37,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" appsclient "k8s.io/client-go/kubernetes/typed/apps/v1" "k8s.io/client-go/util/integer" - internalextensions "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/controller" labelsutil "k8s.io/kubernetes/pkg/util/labels" ) @@ -576,29 +575,6 @@ func ListReplicaSets(deployment *apps.Deployment, getRSList RsListFunc) ([]*apps return owned, nil } -// ListReplicaSetsInternal is ListReplicaSets for internalextensions. -// TODO: Remove the duplicate when call sites are updated to ListReplicaSets. -func ListReplicaSetsInternal(deployment *internalextensions.Deployment, getRSList func(string, metav1.ListOptions) ([]*internalextensions.ReplicaSet, error)) ([]*internalextensions.ReplicaSet, error) { - namespace := deployment.Namespace - selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector) - if err != nil { - return nil, err - } - options := metav1.ListOptions{LabelSelector: selector.String()} - all, err := getRSList(namespace, options) - if err != nil { - return nil, err - } - // Only include those whose ControllerRef matches the Deployment. - filtered := make([]*internalextensions.ReplicaSet, 0, len(all)) - for _, rs := range all { - if metav1.IsControlledBy(rs, deployment) { - filtered = append(filtered, rs) - } - } - return filtered, nil -} - // ListPods returns a list of pods the given deployment targets. // This needs a list of ReplicaSets for the Deployment, // which can be found with ListReplicaSets(). diff --git a/pkg/controller/deployment/util/pod_util.go b/pkg/controller/deployment/util/pod_util.go deleted file mode 100644 index e7c231c1e65..00000000000 --- a/pkg/controller/deployment/util/pod_util.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util - -import ( - "github.com/golang/glog" - - "k8s.io/api/core/v1" - errorsutil "k8s.io/apimachinery/pkg/util/errors" - v1core "k8s.io/client-go/kubernetes/typed/core/v1" - corelisters "k8s.io/client-go/listers/core/v1" - "k8s.io/client-go/util/retry" -) - -// TODO: use client library instead when it starts to support update retries -// see https://github.com/kubernetes/kubernetes/issues/21479 -type updatePodFunc func(pod *v1.Pod) error - -// UpdatePodWithRetries updates a pod with given applyUpdate function. -func UpdatePodWithRetries(podClient v1core.PodInterface, podLister corelisters.PodLister, namespace, name string, applyUpdate updatePodFunc) (*v1.Pod, error) { - var pod *v1.Pod - - retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error { - var err error - pod, err = podLister.Pods(namespace).Get(name) - if err != nil { - return err - } - pod = pod.DeepCopy() - // Apply the update, then attempt to push it to the apiserver. - if applyErr := applyUpdate(pod); applyErr != nil { - return applyErr - } - pod, err = podClient.Update(pod) - return err - }) - - // Ignore the precondition violated error, this pod is already updated - // with the desired label. - if retryErr == errorsutil.ErrPreconditionViolated { - glog.V(4).Infof("Pod %s/%s precondition doesn't hold, skip updating it.", namespace, name) - retryErr = nil - } - - return pod, retryErr -} diff --git a/pkg/controller/deployment/util/replicaset_util.go b/pkg/controller/deployment/util/replicaset_util.go deleted file mode 100644 index bf05a59278a..00000000000 --- a/pkg/controller/deployment/util/replicaset_util.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package util - -import ( - "github.com/golang/glog" - - apps "k8s.io/api/apps/v1" - errorsutil "k8s.io/apimachinery/pkg/util/errors" - appsclient "k8s.io/client-go/kubernetes/typed/apps/v1" - appslisters "k8s.io/client-go/listers/apps/v1" - "k8s.io/client-go/util/retry" -) - -// TODO: use client library instead when it starts to support update retries -// see https://github.com/kubernetes/kubernetes/issues/21479 -type updateRSFunc func(rs *apps.ReplicaSet) error - -// UpdateRSWithRetries updates a RS with given applyUpdate function. Note that RS not found error is ignored. -// The returned bool value can be used to tell if the RS is actually updated. -func UpdateRSWithRetries(rsClient appsclient.ReplicaSetInterface, rsLister appslisters.ReplicaSetLister, namespace, name string, applyUpdate updateRSFunc) (*apps.ReplicaSet, error) { - var rs *apps.ReplicaSet - - retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error { - var err error - rs, err = rsLister.ReplicaSets(namespace).Get(name) - if err != nil { - return err - } - rs = rs.DeepCopy() - // Apply the update, then attempt to push it to the apiserver. - if applyErr := applyUpdate(rs); applyErr != nil { - return applyErr - } - rs, err = rsClient.Update(rs) - return err - }) - - // Ignore the precondition violated error, but the RS isn't updated. - if retryErr == errorsutil.ErrPreconditionViolated { - glog.V(4).Infof("Replica set %s/%s precondition doesn't hold, skip updating it.", namespace, name) - retryErr = nil - } - - return rs, retryErr -}