mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 16:49:35 +00:00
Chore: add rolling update partition type tweak function
This commit is contained in:
parent
f3ffeae426
commit
1b17b4fa79
@ -134,6 +134,15 @@ func tweakUpdateStrategyType(t apps.StatefulSetUpdateStrategyType) statefulSetTw
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tweakRollingUpdatePartition(partition int32) statefulSetTweak {
|
||||||
|
return func(ss *apps.StatefulSet) {
|
||||||
|
if ss.Spec.UpdateStrategy.RollingUpdate == nil {
|
||||||
|
ss.Spec.UpdateStrategy.RollingUpdate = &apps.RollingUpdateStatefulSetStrategy{}
|
||||||
|
}
|
||||||
|
ss.Spec.UpdateStrategy.RollingUpdate.Partition = partition
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestValidateStatefulSet(t *testing.T) {
|
func TestValidateStatefulSet(t *testing.T) {
|
||||||
validLabels := map[string]string{"a": "b"}
|
validLabels := map[string]string{"a": "b"}
|
||||||
validPodTemplate := api.PodTemplate{
|
validPodTemplate := api.PodTemplate{
|
||||||
@ -203,20 +212,11 @@ func TestValidateStatefulSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update strategy",
|
name: "update strategy",
|
||||||
set: apps.StatefulSet{
|
set: mkStatefulSet(&validPodTemplate,
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "abc-123", Namespace: metav1.NamespaceDefault},
|
tweakReplicas(3),
|
||||||
Spec: apps.StatefulSetSpec{
|
tweakUpdateStrategyType(apps.RollingUpdateStatefulSetStrategyType),
|
||||||
PodManagementPolicy: apps.OrderedReadyPodManagement,
|
tweakRollingUpdatePartition(2),
|
||||||
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
),
|
||||||
Template: validPodTemplate.Template,
|
|
||||||
Replicas: 3,
|
|
||||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{
|
|
||||||
Type: apps.RollingUpdateStatefulSetStrategyType,
|
|
||||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
|
||||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: 2}
|
|
||||||
}()},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "PVC policy " + enableStatefulSetAutoDeletePVC,
|
name: "PVC policy " + enableStatefulSetAutoDeletePVC,
|
||||||
@ -412,38 +412,21 @@ func TestValidateStatefulSet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid rolling update",
|
name: "invalid rolling update",
|
||||||
set: apps.StatefulSet{
|
set: mkStatefulSet(&validPodTemplate,
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "abc-123", Namespace: metav1.NamespaceDefault},
|
tweakReplicas(3),
|
||||||
Spec: apps.StatefulSetSpec{
|
tweakUpdateStrategyType(apps.OnDeleteStatefulSetStrategyType),
|
||||||
PodManagementPolicy: apps.OrderedReadyPodManagement,
|
tweakRollingUpdatePartition(1),
|
||||||
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
),
|
||||||
Template: validPodTemplate.Template,
|
|
||||||
Replicas: 3,
|
|
||||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.OnDeleteStatefulSetStrategyType,
|
|
||||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
|
||||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: 1}
|
|
||||||
}()},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
errs: field.ErrorList{
|
errs: field.ErrorList{
|
||||||
field.Invalid(field.NewPath("spec", "updateStrategy", "rollingUpdate"), nil, ""),
|
field.Invalid(field.NewPath("spec", "updateStrategy", "rollingUpdate"), nil, ""),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "negative parition",
|
name: "negative parition",
|
||||||
set: apps.StatefulSet{
|
set: mkStatefulSet(&validPodTemplate,
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "abc-123", Namespace: metav1.NamespaceDefault},
|
tweakReplicas(3),
|
||||||
Spec: apps.StatefulSetSpec{
|
tweakRollingUpdatePartition(-1),
|
||||||
PodManagementPolicy: apps.OrderedReadyPodManagement,
|
),
|
||||||
Selector: &metav1.LabelSelector{MatchLabels: validLabels},
|
|
||||||
Template: validPodTemplate.Template,
|
|
||||||
Replicas: 3,
|
|
||||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
|
|
||||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
|
||||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: -1}
|
|
||||||
}()},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
errs: field.ErrorList{
|
errs: field.ErrorList{
|
||||||
field.Invalid(field.NewPath("spec", "updateStrategy", "rollingUpdate", "partition"), nil, ""),
|
field.Invalid(field.NewPath("spec", "updateStrategy", "rollingUpdate", "partition"), nil, ""),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user