Skip to content

Commit 3bb2656

Browse files
fix: allow 0 maxUnavailable (#989)
1 parent dcb8c94 commit 3bb2656

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

apis/placement/v1/clusterresourceplacement_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ type RollingUpdateConfig struct {
500500
// Absolute number is calculated from percentage by rounding up.
501501
// We consider a resource unavailable when we either remove it from a cluster or in-place
502502
// upgrade the resources content on the same cluster.
503-
// The minimum of MaxUnavailable is 1 to avoid rolling out stuck during in-place resource update.
503+
// The minimum of MaxUnavailable is 0 to allow no downtime moving a placement from one cluster to another.
504+
// Please set it to be greater than 0 to avoid rolling out stuck during in-place resource update.
504505
// Defaults to 25%.
505506
// +kubebuilder:default="25%"
506507
// +kubebuilder:validation:XIntOrString

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ type RollingUpdateConfig struct {
762762
// Absolute number is calculated from percentage by rounding up.
763763
// We consider a resource unavailable when we either remove it from a cluster or in-place
764764
// upgrade the resources content on the same cluster.
765-
// The minimum of MaxUnavailable is 1 to avoid rolling out stuck during in-place resource update.
765+
// The minimum of MaxUnavailable is 0 to allow no downtime moving a placement from one cluster to another.
766+
// Please set it to be greater than 0 to avoid rolling out stuck during in-place resource update.
766767
// Defaults to 25%.
767768
// +kubebuilder:default="25%"
768769
// +kubebuilder:validation:XIntOrString

config/crd/bases/placement.kubernetes-fleet.io_clusterresourceplacements.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ spec:
715715
Absolute number is calculated from percentage by rounding up.
716716
We consider a resource unavailable when we either remove it from a cluster or in-place
717717
upgrade the resources content on the same cluster.
718-
The minimum of MaxUnavailable is 1 to avoid rolling out stuck during in-place resource update.
718+
The minimum of MaxUnavailable is 0 to allow no downtime moving a placement from one cluster to another.
719+
Please set it to be greater than 0 to avoid rolling out stuck during in-place resource update.
719720
Defaults to 25%.
720721
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
721722
x-kubernetes-int-or-string: true
@@ -2054,7 +2055,8 @@ spec:
20542055
Absolute number is calculated from percentage by rounding up.
20552056
We consider a resource unavailable when we either remove it from a cluster or in-place
20562057
upgrade the resources content on the same cluster.
2057-
The minimum of MaxUnavailable is 1 to avoid rolling out stuck during in-place resource update.
2058+
The minimum of MaxUnavailable is 0 to allow no downtime moving a placement from one cluster to another.
2059+
Please set it to be greater than 0 to avoid rolling out stuck during in-place resource update.
20582060
Defaults to 25%.
20592061
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
20602062
x-kubernetes-int-or-string: true

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ require (
4040

4141
require (
4242
dario.cat/mergo v1.0.0 // indirect
43+
github.com/Azure/azure-kusto-go v0.16.1 // indirect
4344
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
4445
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
4546
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
22
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3-
github.com/Azure/azure-kusto-go v0.14.0 h1:5XVmjh5kVgsm2scpsWisJ6Q1ZgWHJcIOPCZC1gatD4I=
4-
github.com/Azure/azure-kusto-go v0.14.0/go.mod h1:wSmXIsQwBVPHDNsSQsX98nuc12VyvxoNHQa2q9t1Ce0=
3+
github.com/Azure/azure-kusto-go v0.16.1 h1:vCBWcQghmC1qIErUUgVNWHxGhZVStu1U/hki6iBA14k=
4+
github.com/Azure/azure-kusto-go v0.16.1/go.mod h1:9F2zvXH8B6eWzgI1S4k1ZXAIufnBZ1bv1cW1kB1n3D0=
55
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU=
66
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
77
github.com/Azure/azure-sdk-for-go-extensions v0.1.4 h1:XNT7IWmj4u3AfSag3t2mFupHT59J58pknX+daqprjm8=

pkg/utils/validator/clusterresourceplacement.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ func validateRolloutStrategy(rolloutStrategy placementv1beta1.RolloutStrategy) e
388388
if err != nil {
389389
allErr = append(allErr, fmt.Errorf("maxUnavailable `%+v` is invalid: %w", rolloutStrategy.RollingUpdate.MaxUnavailable, err))
390390
}
391-
if value < 1 {
392-
allErr = append(allErr, fmt.Errorf("maxUnavailable must be greater than or equal to 1, got `%+v`", rolloutStrategy.RollingUpdate.MaxUnavailable))
391+
if value < 0 {
392+
allErr = append(allErr, fmt.Errorf("maxUnavailable must be greater than or equal to 0, got `%+v`", rolloutStrategy.RollingUpdate.MaxUnavailable))
393393
}
394394
}
395395
if rolloutStrategy.RollingUpdate.MaxSurge != nil {

pkg/utils/validator/clusterresourceplacement_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ func TestValidateClusterResourcePlacement_RolloutStrategy(t *testing.T) {
407407
},
408408
},
409409
wantErr: true,
410-
wantErrMsg: "maxUnavailable must be greater than or equal to 1, got `-10`",
410+
wantErrMsg: "maxUnavailable must be greater than or equal to 0, got `-10`",
411411
},
412-
"invalid rollout strategy - zero MaxUnavailable": {
412+
"valid rollout strategy - zero MaxUnavailable": {
413413
strategy: placementv1beta1.RolloutStrategy{
414414
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
415415
RollingUpdate: &placementv1beta1.RollingUpdateConfig{
@@ -419,8 +419,7 @@ func TestValidateClusterResourcePlacement_RolloutStrategy(t *testing.T) {
419419
},
420420
},
421421
},
422-
wantErr: true,
423-
wantErrMsg: "maxUnavailable must be greater than or equal to 1, got `0`",
422+
wantErr: false,
424423
},
425424
"invalid rollout strategy - % error MaxSurge": {
426425
strategy: placementv1beta1.RolloutStrategy{

pkg/webhook/clusterresourceplacement/v1beta1_clusterresourceplacement_validating_webhook_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
Kind: "ClusterRole",
3232
Name: "test-cluster-role",
3333
}
34-
errString = "the rollout Strategy field is invalid: maxUnavailable must be greater than or equal to 1, got `0`"
34+
errString = "the rollout Strategy field is invalid: maxUnavailable must be greater than or equal to 0, got `-1`"
3535
)
3636

3737
func TestHandle(t *testing.T) {
@@ -48,7 +48,7 @@ func TestHandle(t *testing.T) {
4848
Strategy: placementv1beta1.RolloutStrategy{
4949
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
5050
RollingUpdate: &placementv1beta1.RollingUpdateConfig{
51-
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
51+
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: -1},
5252
},
5353
},
5454
},
@@ -68,7 +68,7 @@ func TestHandle(t *testing.T) {
6868
Strategy: placementv1beta1.RolloutStrategy{
6969
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
7070
RollingUpdate: &placementv1beta1.RollingUpdateConfig{
71-
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
71+
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: -1},
7272
MaxSurge: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
7373
},
7474
},
@@ -89,7 +89,7 @@ func TestHandle(t *testing.T) {
8989
Strategy: placementv1beta1.RolloutStrategy{
9090
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
9191
RollingUpdate: &placementv1beta1.RollingUpdateConfig{
92-
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
92+
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: -1},
9393
},
9494
},
9595
},
@@ -108,7 +108,7 @@ func TestHandle(t *testing.T) {
108108
Strategy: placementv1beta1.RolloutStrategy{
109109
Type: placementv1beta1.RollingUpdateRolloutStrategyType,
110110
RollingUpdate: &placementv1beta1.RollingUpdateConfig{
111-
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
111+
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: -1},
112112
},
113113
},
114114
},

0 commit comments

Comments
 (0)