Removes PartitionStatefulSetStrategyType and Partition from UpdateStrategy and replaces them with a parameterized RollingUpdate strategy.

This commit is contained in:
Kenneth Owens
2017-06-12 10:06:09 -07:00
parent b84567a57e
commit b1ce1ffc55
9 changed files with 76 additions and 112 deletions

View File

@@ -78,35 +78,29 @@ func ValidateStatefulSetSpec(spec *apps.StatefulSetSpec, fldPath *field.Path) fi
switch spec.UpdateStrategy.Type {
case "":
allErrs = append(allErrs, field.Required(fldPath.Child("updateStrategy"), ""))
case apps.OnDeleteStatefulSetStrategyType, apps.RollingUpdateStatefulSetStrategyType:
if spec.UpdateStrategy.Partition != nil {
case apps.OnDeleteStatefulSetStrategyType:
if spec.UpdateStrategy.RollingUpdate != nil {
allErrs = append(
allErrs,
field.Invalid(
fldPath.Child("updateStrategy").Child("partition"),
spec.UpdateStrategy.Partition.Ordinal,
fmt.Sprintf("only allowed for updateStrategy '%s'", apps.PartitionStatefulSetStrategyType)))
fldPath.Child("updateStrategy").Child("rollingUpdate"),
spec.UpdateStrategy.RollingUpdate,
fmt.Sprintf("only allowed for updateStrategy '%s'", apps.RollingUpdateStatefulSetStrategyType)))
}
case apps.PartitionStatefulSetStrategyType:
if spec.UpdateStrategy.Partition == nil {
allErrs = append(
allErrs,
field.Required(
fldPath.Child("updateStrategy").Child("partition"),
fmt.Sprintf("required for updateStrategy '%s'", apps.PartitionStatefulSetStrategyType)))
break
case apps.RollingUpdateStatefulSetStrategyType:
if spec.UpdateStrategy.RollingUpdate != nil {
allErrs = append(allErrs,
apivalidation.ValidateNonnegativeField(
int64(spec.UpdateStrategy.RollingUpdate.Partition),
fldPath.Child("updateStrategy").Child("rollingUpdate").Child("partition"))...)
}
allErrs = append(allErrs,
apivalidation.ValidateNonnegativeField(
int64(spec.UpdateStrategy.Partition.Ordinal),
fldPath.Child("updateStrategy").Child("partition").Child("ordinal"))...)
default:
allErrs = append(allErrs,
field.Invalid(fldPath.Child("updateStrategy"), spec.UpdateStrategy,
fmt.Sprintf("must be '%s', '%s', or '%s'",
fmt.Sprintf("must be '%s' or '%s'",
apps.RollingUpdateStatefulSetStrategyType,
apps.OnDeleteStatefulSetStrategyType,
apps.PartitionStatefulSetStrategyType)))
apps.OnDeleteStatefulSetStrategyType)))
}
allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(spec.Replicas), fldPath.Child("replicas"))...)

View File

@@ -97,9 +97,9 @@ func TestValidateStatefulSet(t *testing.T) {
Template: validPodTemplate.Template,
Replicas: 3,
UpdateStrategy: apps.StatefulSetUpdateStrategy{
Type: apps.PartitionStatefulSetStrategyType,
Partition: func() *apps.PartitionStatefulSetStrategy {
return &apps.PartitionStatefulSetStrategy{Ordinal: 2}
Type: apps.RollingUpdateStatefulSetStrategyType,
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
return &apps.RollingUpdateStatefulSetStrategy{Partition: 2}
}()},
},
},
@@ -259,7 +259,7 @@ func TestValidateStatefulSet(t *testing.T) {
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: "foo"},
},
},
"partitioned rolling update": {
"negative parition": {
ObjectMeta: metav1.ObjectMeta{Name: "abc-123", Namespace: metav1.NamespaceDefault},
Spec: apps.StatefulSetSpec{
PodManagementPolicy: apps.OrderedReadyPodManagement,
@@ -267,23 +267,11 @@ func TestValidateStatefulSet(t *testing.T) {
Template: validPodTemplate.Template,
Replicas: 3,
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
Partition: func() *apps.PartitionStatefulSetStrategy {
return &apps.PartitionStatefulSetStrategy{Ordinal: 2}
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
return &apps.RollingUpdateStatefulSetStrategy{Partition: -1}
}()},
},
},
"empty partition": {
ObjectMeta: metav1.ObjectMeta{Name: "abc-123", Namespace: metav1.NamespaceDefault},
Spec: apps.StatefulSetSpec{
PodManagementPolicy: apps.OrderedReadyPodManagement,
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
Template: validPodTemplate.Template,
Replicas: 3,
UpdateStrategy: apps.StatefulSetUpdateStrategy{
Type: apps.PartitionStatefulSetStrategyType,
Partition: nil},
},
},
}
for k, v := range errorCases {
errs := ValidateStatefulSet(&v)
@@ -304,8 +292,8 @@ func TestValidateStatefulSet(t *testing.T) {
field != "metadata.labels" &&
field != "status.replicas" &&
field != "spec.updateStrategy" &&
field != "spec.updateStrategy.partition" &&
field != "spec.updateStrategy.partition.ordinal" {
field != "spec.updateStrategy.rollingUpate" &&
field != "spec.updateStrategy.rollingUpdate.partition" {
t.Errorf("%s: missing prefix for: %v", k, errs[i])
}
}