Add preconditions to pod/rs update retry func

This commit is contained in:
Janet Kuo
2016-03-02 15:06:00 -08:00
parent 2a4479fa60
commit aae2073a78
3 changed files with 50 additions and 31 deletions

View File

@@ -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.