@@ -387,6 +387,7 @@ func Finish(cmd *cobra.Command, appAPI applications.API, app applications.Applic
387
387
}
388
388
return & applications.BoundsRange {}
389
389
}
390
+ limitRequestRatio := patch .Configuration [0 ].ContainerResources .LimitRequestRatio
390
391
391
392
errs = append (errs , checkResourceList (
392
393
mode , "limit" ,
@@ -405,6 +406,11 @@ func Finish(cmd *cobra.Command, appAPI applications.API, app applications.Applic
405
406
targetUtilization (bounds ).Min , targetUtilization (bounds ).Max ,
406
407
cmd .CommandPath (), flagContainerResourcesTargetUtilizationMin , flagContainerResourcesTargetUtilizationMax ,
407
408
)... )
409
+
410
+ errs = append (errs , checkLimitRequestRatio (
411
+ limitRequestRatio ,
412
+ cmd .CommandPath (), flagContainerResourcesLimitRequestRatio ,
413
+ )... )
408
414
}
409
415
410
416
// Application resources are required to enable recommendations
@@ -499,6 +505,28 @@ func checkResourceList(mode applications.RecommendationsMode, name string, minLi
499
505
return errs
500
506
}
501
507
508
+ // checkLimitRequestRatio ensures the ratio does not produce invalid results.
509
+ func checkLimitRequestRatio (list * applications.ResourceList , fixCommand , fixFlag string ) ErrorList {
510
+ var errs ErrorList
511
+
512
+ for _ , resourceName := range []string {"cpu" , "memory" } {
513
+ r := list .Get (resourceName )
514
+ if r == nil {
515
+ continue
516
+ }
517
+
518
+ if f := r .Float64Value (); (f > 0 && f < 1 ) || f < 0 {
519
+ errs = append (errs , & Error {
520
+ Message : fmt .Sprintf ("invalid limit/request ratio for %s: %g (must be 0 or at least 1)" , resourceName , f ),
521
+ FixCommand : fixCommand ,
522
+ FixFlag : fixFlag ,
523
+ })
524
+ }
525
+ }
526
+
527
+ return errs
528
+ }
529
+
502
530
type Error struct {
503
531
Message string
504
532
FixCommand string
0 commit comments