Merge pull request #7643 from bprashanth/rc_status

Requeue rc if a single get/put retry on status.Replicas fails
This commit is contained in:
Daniel Smith
2015-05-04 12:15:30 -07:00
5 changed files with 133 additions and 29 deletions

View File

@@ -19,7 +19,6 @@ package controller
import (
"encoding/json"
"fmt"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
@@ -27,12 +26,14 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"github.com/golang/glog"
"sync/atomic"
)
const CreatedByAnnotation = "kubernetes.io/created-by"
const (
CreatedByAnnotation = "kubernetes.io/created-by"
updateRetries = 1
)
// Expectations are a way for replication controllers to tell the rc manager what they expect. eg:
// RCExpectations: {
@@ -276,21 +277,28 @@ func filterActivePods(pods []api.Pod) []*api.Pod {
return result
}
// updateReplicaCount attempts to update the Status.Replicas of the given controller, with retries.
// Note that the controller pointer might contain a more recent version of the same controller passed into the function.
func updateReplicaCount(rcClient client.ReplicationControllerInterface, controller *api.ReplicationController, numReplicas int) error {
return wait.Poll(10*time.Millisecond, 100*time.Millisecond, func() (bool, error) {
if controller.Status.Replicas != numReplicas {
glog.V(4).Infof("Updating replica count for rc: %v, %d->%d", controller.Name, controller.Status.Replicas, numReplicas)
controller.Status.Replicas = numReplicas
_, err := rcClient.Update(controller)
if err != nil {
glog.V(2).Infof("Controller %v failed to update replica count: %v", controller.Name, err)
// Update the controller with the latest resource version for the next poll
controller, _ = rcClient.Get(controller.Name)
return false, err
}
// updateReplicaCount attempts to update the Status.Replicas of the given controller, with a single GET/PUT retry.
func updateReplicaCount(rcClient client.ReplicationControllerInterface, controller api.ReplicationController, numReplicas int) (updateErr error) {
// This is the steady state. It happens when the rc doesn't have any expectations, since
// we do a periodic relist every 30s.
if controller.Status.Replicas == numReplicas {
return nil
}
var getErr error
glog.V(4).Infof("Updating replica count for rc: %v, %d->%d", controller.Name, controller.Status.Replicas, numReplicas)
for i, rc := 0, &controller; ; i++ {
rc.Status.Replicas = numReplicas
_, updateErr = rcClient.Update(rc)
if updateErr == nil || i >= updateRetries {
return updateErr
}
return true, nil
})
// Update the controller with the latest resource version for the next poll
if rc, getErr = rcClient.Get(controller.Name); getErr != nil {
// If the GET fails we can't trust status.Replicas anymore. This error
// is bound to be more interesting than the update failure.
return getErr
}
}
// Failed 2 updates one of which was with the latest controller, return the update error
return
}