Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion util/ValidatorHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
8 changes: 4 additions & 4 deletions util/ValidatorHelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down