From 5626a7fbb86499553ce4595d31591bc55f438cc1 Mon Sep 17 00:00:00 2001 From: MrZhousong <1206834441@qq.com> Date: Wed, 10 May 2023 14:49:16 +0800 Subject: [PATCH] [feature]When the data type of spec.replicas is int, cancel the upper limit (#142) * feature When the data type of spec.replicas is int, cancel the upper limit of 100. #141 Signed-off-by: zhousong * style update error field `CanaryReplicas` ==> `Replicas` #141 Signed-off-by: zhousong --------- Signed-off-by: zhousong Co-authored-by: zhousong --- .../rollout/validating/rollout_create_update_handler.go | 8 +++++--- .../validating/rollout_create_update_handler_test.go | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/webhook/rollout/validating/rollout_create_update_handler.go b/pkg/webhook/rollout/validating/rollout_create_update_handler.go index 9bbe3d3..13d86e4 100644 --- a/pkg/webhook/rollout/validating/rollout_create_update_handler.go +++ b/pkg/webhook/rollout/validating/rollout_create_update_handler.go @@ -240,9 +240,11 @@ func validateRolloutSpecCanarySteps(steps []appsv1alpha1.CanaryStep, fldPath *fi } if s.Replicas != nil { canaryReplicas, err := intstr.GetScaledValueFromIntOrPercent(s.Replicas, 100, true) - if err != nil || canaryReplicas <= 0 || canaryReplicas > 100 { - return field.ErrorList{field.Invalid(fldPath.Index(i).Child("CanaryReplicas"), - s.Replicas, `canaryReplicas must be positive number with with "0" < canaryReplicas <= "100", or a percentage with "0%" < canaryReplicas <= "100%"`)} + if err != nil || + canaryReplicas <= 0 || + (canaryReplicas > 100 && s.Replicas.Type == intstr.String) { + return field.ErrorList{field.Invalid(fldPath.Index(i).Child("Replicas"), + s.Replicas, `replicas must be positive number, or a percentage with "0%" < canaryReplicas <= "100%"`)} } } } diff --git a/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go b/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go index 672681e..a2f6552 100644 --- a/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go +++ b/pkg/webhook/rollout/validating/rollout_create_update_handler_test.go @@ -72,6 +72,12 @@ var ( { Weight: utilpointer.Int32Ptr(100), }, + { + Weight: utilpointer.Int32Ptr(101), + }, + { + Weight: utilpointer.Int32Ptr(200), + }, }, TrafficRoutings: []*appsv1alpha1.TrafficRouting{ {