mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #66473 from fisherxu/remove_code
Automatic merge from submit-queue (batch tested with PRs 64815, 66823, 66473, 66466). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Clean up unused code **What this PR does / why we need it**: Clean up the unused duplicate code. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
		@@ -8,14 +8,9 @@ load(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
go_library(
 | 
					go_library(
 | 
				
			||||||
    name = "go_default_library",
 | 
					    name = "go_default_library",
 | 
				
			||||||
    srcs = [
 | 
					    srcs = ["deployment_util.go"],
 | 
				
			||||||
        "deployment_util.go",
 | 
					 | 
				
			||||||
        "pod_util.go",
 | 
					 | 
				
			||||||
        "replicaset_util.go",
 | 
					 | 
				
			||||||
    ],
 | 
					 | 
				
			||||||
    importpath = "k8s.io/kubernetes/pkg/controller/deployment/util",
 | 
					    importpath = "k8s.io/kubernetes/pkg/controller/deployment/util",
 | 
				
			||||||
    deps = [
 | 
					    deps = [
 | 
				
			||||||
        "//pkg/apis/extensions:go_default_library",
 | 
					 | 
				
			||||||
        "//pkg/controller:go_default_library",
 | 
					        "//pkg/controller:go_default_library",
 | 
				
			||||||
        "//pkg/util/labels:go_default_library",
 | 
					        "//pkg/util/labels:go_default_library",
 | 
				
			||||||
        "//staging/src/k8s.io/api/apps/v1: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/apis/meta/v1:go_default_library",
 | 
				
			||||||
        "//staging/src/k8s.io/apimachinery/pkg/runtime: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/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/intstr:go_default_library",
 | 
				
			||||||
        "//staging/src/k8s.io/apimachinery/pkg/util/wait: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/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/integer:go_default_library",
 | 
				
			||||||
        "//staging/src/k8s.io/client-go/util/retry:go_default_library",
 | 
					 | 
				
			||||||
        "//vendor/github.com/golang/glog:go_default_library",
 | 
					        "//vendor/github.com/golang/glog:go_default_library",
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,6 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	appsclient "k8s.io/client-go/kubernetes/typed/apps/v1"
 | 
						appsclient "k8s.io/client-go/kubernetes/typed/apps/v1"
 | 
				
			||||||
	"k8s.io/client-go/util/integer"
 | 
						"k8s.io/client-go/util/integer"
 | 
				
			||||||
	internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/controller"
 | 
						"k8s.io/kubernetes/pkg/controller"
 | 
				
			||||||
	labelsutil "k8s.io/kubernetes/pkg/util/labels"
 | 
						labelsutil "k8s.io/kubernetes/pkg/util/labels"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -576,29 +575,6 @@ func ListReplicaSets(deployment *apps.Deployment, getRSList RsListFunc) ([]*apps
 | 
				
			|||||||
	return owned, nil
 | 
						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.
 | 
					// ListPods returns a list of pods the given deployment targets.
 | 
				
			||||||
// This needs a list of ReplicaSets for the Deployment,
 | 
					// This needs a list of ReplicaSets for the Deployment,
 | 
				
			||||||
// which can be found with ListReplicaSets().
 | 
					// which can be found with ListReplicaSets().
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user