From ae1d2c1fa510e834f37744d556faaa948ce5e061 Mon Sep 17 00:00:00 2001 From: Prashant Ghildiyal Date: Mon, 22 Nov 2021 10:43:18 +0530 Subject: [PATCH 1/3] used float64 instead of int --- util/ValidatorHelper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ValidatorHelper.go b/util/ValidatorHelper.go index c278d6b760..6605efa04a 100644 --- a/util/ValidatorHelper.go +++ b/util/ValidatorHelper.go @@ -248,7 +248,7 @@ func AutoScale(dat map[string]interface{}) (bool, error) { if !okMin || !okMax{ return false, errors.New("autoscaling.MinReplicas and autoscaling.MaxReplicas are mandatory fields") } - if minReplicas.(int) > maxReplicas.(int){ + if minReplicas.(float64) > maxReplicas.(float64){ return false, errors.New("autoscaling.MinReplicas can not be greater than autoscaling.MaxReplicas") } } From 424657a6d8100aa71da2d7e2dd6de581d815a3e1 Mon Sep 17 00:00:00 2001 From: Prashant Ghildiyal Date: Mon, 22 Nov 2021 11:13:38 +0530 Subject: [PATCH 2/3] fixed test cases --- util/ValidatorHelper_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/ValidatorHelper_test.go b/util/ValidatorHelper_test.go index 2e9c15727f..f7a2b09b41 100644 --- a/util/ValidatorHelper_test.go +++ b/util/ValidatorHelper_test.go @@ -108,25 +108,25 @@ func TestAutoScale(t *testing.T) { }, { name: "non-empty autoscaling enabled minReplicas maxReplicas object", - args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: 10, maxReplicas:11}}}, + args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: float64(10), maxReplicas: float64(11)}}}, want: true, wantErr: false, }, { name: "non-empty autoscaling enabled minReplicas empty maxReplicas object", - args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: 11}}}, + args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: float64(11)}}}, want: true, wantErr: false, }, { name: "non-empty autoscaling minReplicas maxReplicas object empty enabled", - args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{minReplicas: 10, maxReplicas:11}}}, + args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{minReplicas: float64(10), maxReplicas: float64(11)}}}, want: true, wantErr: false, }, { name: "negative: non-empty and greater minReplicas than maxReplicas object", - args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: true, minReplicas: 10, maxReplicas:9}}}, + args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: true, minReplicas: float64(10), maxReplicas: float64(9)}}}, want: false, wantErr: true, }, From b7e8c90c82a85e30e0f978080ed5a75b55f6a11c Mon Sep 17 00:00:00 2001 From: Prashant Ghildiyal Date: Mon, 22 Nov 2021 11:27:07 +0530 Subject: [PATCH 3/3] added comment --- util/ValidatorHelper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/ValidatorHelper.go b/util/ValidatorHelper.go index 6605efa04a..9a18842c54 100644 --- a/util/ValidatorHelper.go +++ b/util/ValidatorHelper.go @@ -248,6 +248,8 @@ func AutoScale(dat map[string]interface{}) (bool, error) { if !okMin || !okMax{ return false, errors.New("autoscaling.MinReplicas and autoscaling.MaxReplicas are mandatory fields") } + // see https://pkg.go.dev/encoding/json#Unmarshal for why conversion to float64 and not int + // Bug fix PR https://github.com/devtron-labs/devtron/pull/884 if minReplicas.(float64) > maxReplicas.(float64){ return false, errors.New("autoscaling.MinReplicas can not be greater than autoscaling.MaxReplicas") }