diff --git a/util/ValidatorHelper.go b/util/ValidatorHelper.go index c278d6b760..9a18842c54 100644 --- a/util/ValidatorHelper.go +++ b/util/ValidatorHelper.go @@ -248,7 +248,9 @@ 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){ + // 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") } } 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, },