mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 01:23:48 +00:00
Add preconditions to pod/rs update retry func
This commit is contained in:
@@ -39,10 +39,11 @@ func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 {
|
||||
// TODO: use client library instead when it starts to support update retries
|
||||
// see https://github.com/kubernetes/kubernetes/issues/21479
|
||||
type updatePodFunc func(pod *api.Pod)
|
||||
type preconditionFunc func(pod *api.Pod) bool
|
||||
|
||||
// UpdatePodWithRetries updates a pod with given applyUpdate function. Note that pod not found error is ignored.
|
||||
// UpdatePodWithRetries updates a pod with given applyUpdate function, when the given precondition holds. Note that pod not found error is ignored.
|
||||
// The returned bool value can be used to tell if the pod is actually updated.
|
||||
func UpdatePodWithRetries(podClient unversionedcore.PodInterface, pod *api.Pod, applyUpdate updatePodFunc) (*api.Pod, bool, error) {
|
||||
func UpdatePodWithRetries(podClient unversionedcore.PodInterface, pod *api.Pod, preconditionHold preconditionFunc, applyUpdate updatePodFunc) (*api.Pod, bool, error) {
|
||||
var err error
|
||||
var podUpdated bool
|
||||
oldPod := pod
|
||||
@@ -51,8 +52,11 @@ func UpdatePodWithRetries(podClient unversionedcore.PodInterface, pod *api.Pod,
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !preconditionHold(pod) {
|
||||
glog.V(4).Infof("pod %s precondition doesn't hold, skip updating it.", pod.Name)
|
||||
return true, nil
|
||||
}
|
||||
// Apply the update, then attempt to push it to the apiserver.
|
||||
// TODO: add precondition for update
|
||||
applyUpdate(pod)
|
||||
if pod, err = podClient.Update(pod); err == nil {
|
||||
// Update successful.
|
||||
|
Reference in New Issue
Block a user