mirror of https://github.com/kubernetes/kops.git
Add MaxSurge to resolveSettings
This commit is contained in:
parent
b8e665018c
commit
4ddc58ca5e
|
|
@ -31,18 +31,35 @@ func resolveSettings(cluster *kops.Cluster, group *kops.InstanceGroup, numInstan
|
||||||
if rollingUpdate.MaxUnavailable == nil {
|
if rollingUpdate.MaxUnavailable == nil {
|
||||||
rollingUpdate.MaxUnavailable = def.MaxUnavailable
|
rollingUpdate.MaxUnavailable = def.MaxUnavailable
|
||||||
}
|
}
|
||||||
|
if rollingUpdate.MaxSurge == nil {
|
||||||
|
rollingUpdate.MaxSurge = def.MaxSurge
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rollingUpdate.MaxSurge == nil {
|
||||||
|
zero := intstr.FromInt(0)
|
||||||
|
rollingUpdate.MaxSurge = &zero
|
||||||
|
}
|
||||||
|
|
||||||
|
if rollingUpdate.MaxSurge.Type == intstr.String {
|
||||||
|
surge, _ := intstr.GetValueFromIntOrPercent(rollingUpdate.MaxSurge, numInstances, true)
|
||||||
|
surgeInt := intstr.FromInt(surge)
|
||||||
|
rollingUpdate.MaxSurge = &surgeInt
|
||||||
|
}
|
||||||
|
|
||||||
|
maxUnavailableDefault := intstr.FromInt(0)
|
||||||
|
if rollingUpdate.MaxSurge.Type == intstr.Int && rollingUpdate.MaxSurge.IntVal == 0 {
|
||||||
|
maxUnavailableDefault = intstr.FromInt(1)
|
||||||
|
}
|
||||||
if rollingUpdate.MaxUnavailable == nil || rollingUpdate.MaxUnavailable.IntVal < 0 {
|
if rollingUpdate.MaxUnavailable == nil || rollingUpdate.MaxUnavailable.IntVal < 0 {
|
||||||
one := intstr.FromInt(1)
|
rollingUpdate.MaxUnavailable = &maxUnavailableDefault
|
||||||
rollingUpdate.MaxUnavailable = &one
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rollingUpdate.MaxUnavailable.Type == intstr.String {
|
if rollingUpdate.MaxUnavailable.Type == intstr.String {
|
||||||
unavailable, err := intstr.GetValueFromIntOrPercent(rollingUpdate.MaxUnavailable, numInstances, false)
|
unavailable, err := intstr.GetValueFromIntOrPercent(rollingUpdate.MaxUnavailable, numInstances, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If unparseable use the default value
|
// If unparseable use the default value
|
||||||
unavailable = 1
|
unavailable = maxUnavailableDefault.IntValue()
|
||||||
}
|
}
|
||||||
if unavailable <= 0 {
|
if unavailable <= 0 {
|
||||||
// While we round down, percentages should resolve to a minimum of 1
|
// While we round down, percentages should resolve to a minimum of 1
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ func TestSettings(t *testing.T) {
|
||||||
defaultValue: intstr.FromInt(1),
|
defaultValue: intstr.FromInt(1),
|
||||||
nonDefaultValue: intstr.FromInt(2),
|
nonDefaultValue: intstr.FromInt(2),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "MaxSurge",
|
||||||
|
defaultValue: intstr.FromInt(0),
|
||||||
|
nonDefaultValue: intstr.FromInt(2),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
defaultCluster := &kops.RollingUpdate{}
|
defaultCluster := &kops.RollingUpdate{}
|
||||||
|
|
@ -165,3 +170,52 @@ func TestMaxUnavailable(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxSurge(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
numInstances int
|
||||||
|
value string
|
||||||
|
expected int32
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
numInstances: 1,
|
||||||
|
value: "0",
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numInstances: 1,
|
||||||
|
value: "0%",
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numInstances: 10,
|
||||||
|
value: "31%",
|
||||||
|
expected: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
numInstances: 10,
|
||||||
|
value: "100%",
|
||||||
|
expected: 10,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(fmt.Sprintf("%s %d", tc.value, tc.numInstances), func(t *testing.T) {
|
||||||
|
value := intstr.Parse(tc.value)
|
||||||
|
rollingUpdate := kops.RollingUpdate{
|
||||||
|
MaxSurge: &value,
|
||||||
|
}
|
||||||
|
instanceGroup := kops.InstanceGroup{
|
||||||
|
Spec: kops.InstanceGroupSpec{
|
||||||
|
RollingUpdate: &rollingUpdate,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
resolved := resolveSettings(&kops.Cluster{}, &instanceGroup, tc.numInstances)
|
||||||
|
assert.Equal(t, intstr.Int, resolved.MaxSurge.Type)
|
||||||
|
assert.Equal(t, tc.expected, resolved.MaxSurge.IntVal)
|
||||||
|
if tc.expected == 0 {
|
||||||
|
assert.Equal(t, int32(1), resolved.MaxUnavailable.IntVal, "MaxUnavailable default")
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, int32(0), resolved.MaxUnavailable.IntVal, "MaxUnavailable default")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue