mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Remove unused Deployment util functions
This commit is contained in:
parent
647d8d8a22
commit
cda3f18b8c
@ -29,7 +29,6 @@ go_library(
|
|||||||
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
|
||||||
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
|
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1:go_default_library",
|
"//vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/listers/core/v1:go_default_library",
|
"//vendor/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||||
|
@ -32,13 +32,9 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/errors"
|
|
||||||
intstrutil "k8s.io/apimachinery/pkg/util/intstr"
|
intstrutil "k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
|
||||||
extensionsv1beta1 "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
|
extensionsv1beta1 "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
|
||||||
corelisters "k8s.io/client-go/listers/core/v1"
|
|
||||||
extensionslisters "k8s.io/client-go/listers/extensions/v1beta1"
|
|
||||||
"k8s.io/client-go/util/integer"
|
"k8s.io/client-go/util/integer"
|
||||||
internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
|
internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
@ -677,56 +673,6 @@ func FindOldReplicaSets(deployment *extensions.Deployment, rsList []*extensions.
|
|||||||
return requiredRSs, allRSs
|
return requiredRSs, allRSs
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForReplicaSetUpdated polls the replica set until it is updated.
|
|
||||||
func WaitForReplicaSetUpdated(c extensionslisters.ReplicaSetLister, desiredGeneration int64, namespace, name string) error {
|
|
||||||
return wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
|
|
||||||
rs, err := c.ReplicaSets(namespace).Get(name)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return rs.Status.ObservedGeneration >= desiredGeneration, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitForPodsHashPopulated polls the replica set until updated and fully labeled.
|
|
||||||
func WaitForPodsHashPopulated(c extensionslisters.ReplicaSetLister, desiredGeneration int64, namespace, name string) error {
|
|
||||||
return wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
|
|
||||||
rs, err := c.ReplicaSets(namespace).Get(name)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return rs.Status.ObservedGeneration >= desiredGeneration &&
|
|
||||||
rs.Status.FullyLabeledReplicas == *(rs.Spec.Replicas), nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// LabelPodsWithHash labels all pods in the given podList with the new hash label.
|
|
||||||
func LabelPodsWithHash(podList *v1.PodList, c clientset.Interface, podLister corelisters.PodLister, namespace, name, hash string) error {
|
|
||||||
for _, pod := range podList.Items {
|
|
||||||
// Ignore inactive Pods.
|
|
||||||
if !controller.IsPodActive(&pod) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Only label the pod that doesn't already have the new hash
|
|
||||||
if pod.Labels[extensions.DefaultDeploymentUniqueLabelKey] != hash {
|
|
||||||
_, err := UpdatePodWithRetries(c.CoreV1().Pods(namespace), podLister, pod.Namespace, pod.Name,
|
|
||||||
func(podToUpdate *v1.Pod) error {
|
|
||||||
// Precondition: the pod doesn't contain the new hash in its label.
|
|
||||||
if podToUpdate.Labels[extensions.DefaultDeploymentUniqueLabelKey] == hash {
|
|
||||||
return errors.ErrPreconditionViolated
|
|
||||||
}
|
|
||||||
podToUpdate.Labels = labelsutil.AddLabel(podToUpdate.Labels, extensions.DefaultDeploymentUniqueLabelKey, hash)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error in adding template hash label %s to pod %q: %v", hash, pod.Name, err)
|
|
||||||
}
|
|
||||||
glog.V(4).Infof("Labeled pod %s/%s of ReplicaSet %s/%s with hash %s.", pod.Namespace, pod.Name, namespace, name, hash)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFromReplicaSetTemplate sets the desired PodTemplateSpec from a replica set template to the given deployment.
|
// SetFromReplicaSetTemplate sets the desired PodTemplateSpec from a replica set template to the given deployment.
|
||||||
func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template v1.PodTemplateSpec) *extensions.Deployment {
|
func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template v1.PodTemplateSpec) *extensions.Deployment {
|
||||||
deployment.Spec.Template.ObjectMeta = template.ObjectMeta
|
deployment.Spec.Template.ObjectMeta = template.ObjectMeta
|
||||||
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
extensions "k8s.io/api/extensions/v1beta1"
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
@ -26,8 +24,6 @@ import (
|
|||||||
unversionedextensions "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
|
unversionedextensions "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
|
||||||
extensionslisters "k8s.io/client-go/listers/extensions/v1beta1"
|
extensionslisters "k8s.io/client-go/listers/extensions/v1beta1"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
|
||||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: use client library instead when it starts to support update retries
|
// TODO: use client library instead when it starts to support update retries
|
||||||
@ -62,10 +58,3 @@ func UpdateRSWithRetries(rsClient unversionedextensions.ReplicaSetInterface, rsL
|
|||||||
|
|
||||||
return rs, retryErr
|
return rs, retryErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReplicaSetHash returns the pod template hash of a ReplicaSet's pod template space
|
|
||||||
func GetReplicaSetHash(rs *extensions.ReplicaSet, uniquifier *int32) (string, error) {
|
|
||||||
rsTemplate := rs.Spec.Template.DeepCopy()
|
|
||||||
rsTemplate.Labels = labelsutil.CloneAndRemoveLabel(rsTemplate.Labels, extensions.DefaultDeploymentUniqueLabelKey)
|
|
||||||
return fmt.Sprintf("%d", controller.ComputeHash(rsTemplate, uniquifier)), nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user