Removes PartitionStatefulSetStrategyType and Partition from UpdateStrategy and replaces them with a parameterized RollingUpdate strategy.
This commit is contained in:
@@ -483,8 +483,8 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
|
||||
|
||||
// we compute the minimum ordinal of the target sequence for a destructive update based on the strategy.
|
||||
updateMin := 0
|
||||
if set.Spec.UpdateStrategy.Type == apps.PartitionStatefulSetStrategyType {
|
||||
updateMin = int(set.Spec.UpdateStrategy.Partition.Ordinal)
|
||||
if set.Spec.UpdateStrategy.RollingUpdate != nil {
|
||||
updateMin = int(*set.Spec.UpdateStrategy.RollingUpdate.Partition)
|
||||
}
|
||||
// we terminate the Pod with the largest ordinal that does not match the update revision.
|
||||
for target := len(replicas) - 1; target >= updateMin; target-- {
|
||||
|
@@ -1053,7 +1053,7 @@ func TestStatefulSetControlOnDeleteUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatefulSetControlPartitionUpdate(t *testing.T) {
|
||||
func TestStatefulSetControlRollingUpdateWithPartition(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
partition int32
|
||||
@@ -1066,9 +1066,9 @@ func TestStatefulSetControlPartitionUpdate(t *testing.T) {
|
||||
testFn := func(test *testcase, t *testing.T) {
|
||||
set := test.initial()
|
||||
set.Spec.UpdateStrategy = apps.StatefulSetUpdateStrategy{
|
||||
Type: apps.PartitionStatefulSetStrategyType,
|
||||
Partition: func() *apps.PartitionStatefulSetStrategy {
|
||||
return &apps.PartitionStatefulSetStrategy{Ordinal: test.partition}
|
||||
Type: apps.RollingUpdateStatefulSetStrategyType,
|
||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: &test.partition}
|
||||
}(),
|
||||
}
|
||||
client := fake.NewSimpleClientset(set)
|
||||
@@ -2068,28 +2068,28 @@ func updateComplete(set *apps.StatefulSet, pods []*v1.Pod) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if set.Spec.UpdateStrategy.Type == apps.RollingUpdateStatefulSetStrategyType {
|
||||
if set.Status.CurrentReplicas < *set.Spec.Replicas {
|
||||
return false
|
||||
}
|
||||
for i := range pods {
|
||||
if getPodRevision(pods[i]) != set.Status.CurrentRevision {
|
||||
switch set.Spec.UpdateStrategy.Type {
|
||||
case apps.OnDeleteStatefulSetStrategyType:
|
||||
return true
|
||||
case apps.RollingUpdateStatefulSetStrategyType:
|
||||
if set.Spec.UpdateStrategy.RollingUpdate == nil || *set.Spec.UpdateStrategy.RollingUpdate.Partition <= 0 {
|
||||
if set.Status.CurrentReplicas < *set.Spec.Replicas {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
if set.Spec.UpdateStrategy.Type == apps.PartitionStatefulSetStrategyType {
|
||||
if set.Status.UpdatedReplicas < (*set.Spec.Replicas - set.Spec.UpdateStrategy.Partition.Ordinal) {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < int(set.Spec.UpdateStrategy.Partition.Ordinal); i++ {
|
||||
if getPodRevision(pods[i]) != set.Status.CurrentRevision {
|
||||
for i := range pods {
|
||||
if getPodRevision(pods[i]) != set.Status.CurrentRevision {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partition := int(*set.Spec.UpdateStrategy.RollingUpdate.Partition)
|
||||
if len(pods) < partition {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for i := int(set.Spec.UpdateStrategy.Partition.Ordinal); i < int(*set.Spec.Replicas); i++ {
|
||||
if getPodRevision(pods[i]) != set.Status.UpdateRevision {
|
||||
return false
|
||||
for i := partition; i < len(pods); i++ {
|
||||
if getPodRevision(pods[i]) != set.Status.UpdateRevision {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -286,10 +286,9 @@ func newStatefulSetPod(set *apps.StatefulSet, ordinal int) *v1.Pod {
|
||||
// the current revision. updateRevision is the name of the update revision. ordinal is the ordinal of the Pod. If the
|
||||
// returned error is nil, the returned Pod is valid.
|
||||
func newVersionedStatefulSetPod(currentSet, updateSet *apps.StatefulSet, currentRevision, updateRevision string, ordinal int) *v1.Pod {
|
||||
if (currentSet.Spec.UpdateStrategy.Type == apps.RollingUpdateStatefulSetStrategyType &&
|
||||
ordinal < int(currentSet.Status.CurrentReplicas)) ||
|
||||
(currentSet.Spec.UpdateStrategy.Type == apps.PartitionStatefulSetStrategyType &&
|
||||
ordinal < int(currentSet.Spec.UpdateStrategy.Partition.Ordinal)) {
|
||||
if currentSet.Spec.UpdateStrategy.Type == apps.RollingUpdateStatefulSetStrategyType &&
|
||||
(currentSet.Spec.UpdateStrategy.RollingUpdate == nil && ordinal < int(currentSet.Status.CurrentReplicas)) ||
|
||||
(currentSet.Spec.UpdateStrategy.RollingUpdate != nil && ordinal < int(*currentSet.Spec.UpdateStrategy.RollingUpdate.Partition)) {
|
||||
pod := newStatefulSetPod(currentSet, ordinal)
|
||||
setPodRevision(pod, currentRevision)
|
||||
return pod
|
||||
|
Reference in New Issue
Block a user