Switch statefulset controller to shared informers

This commit is contained in:
Andy Goldstein
2017-02-14 14:03:00 -05:00
parent eef16cf141
commit f6a186b1e1
13 changed files with 520 additions and 313 deletions

View File

@@ -17,8 +17,10 @@ limitations under the License.
package statefulset
import (
"fmt"
"sort"
"k8s.io/client-go/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
apps "k8s.io/kubernetes/pkg/apis/apps/v1beta1"
@@ -97,8 +99,16 @@ func (ssc *defaultStatefulSetControl) UpdateStatefulSet(set *apps.StatefulSet, p
sort.Sort(ascendingOrdinal(condemned))
// if the current number of replicas has changed update the statefulSets replicas
if err := ssc.podControl.UpdateStatefulSetReplicas(set, int32(ready)); err != nil {
return err
if set.Status.Replicas != int32(ready) {
obj, err := api.Scheme.Copy(set)
if err != nil {
return fmt.Errorf("unable to copy set: %v", err)
}
set = obj.(*apps.StatefulSet)
if err := ssc.podControl.UpdateStatefulSetReplicas(set, int32(ready)); err != nil {
return err
}
}
// Examine each replica with respect to its ordinal
@@ -123,8 +133,17 @@ func (ssc *defaultStatefulSetControl) UpdateStatefulSet(set *apps.StatefulSet, p
set.Name, replicas[i].Name)
return nil
}
// Enforce the StatefulSet invariants,
if err := ssc.podControl.UpdateStatefulPod(set, replicas[i]); err != nil {
// Enforce the StatefulSet invariants
if identityMatches(set, replicas[i]) && storageMatches(set, replicas[i]) {
continue
}
// Make a deep copy so we don't mutate the shared cache
copy, err := api.Scheme.DeepCopy(replicas[i])
if err != nil {
return err
}
replica := copy.(*v1.Pod)
if err := ssc.podControl.UpdateStatefulPod(set, replica); err != nil {
return err
}
}