diff --git a/pkg/recommendation/recommender/resource/recommend.go b/pkg/recommendation/recommender/resource/recommend.go index f03f8fc5a..1d85ee525 100644 --- a/pkg/recommendation/recommender/resource/recommend.go +++ b/pkg/recommendation/recommender/resource/recommend.go @@ -175,8 +175,20 @@ func (rr *ResourceRecommender) Recommend(ctx *framework.RecommendationContext) e } } - cr.Target[corev1.ResourceCPU] = cpuQuantity.String() - cr.Target[corev1.ResourceMemory] = memQuantity.String() + // Resource Compliance recommendation enabled + if rr.ResourceComplianceRecommendation { + cr.Target[corev1.ResourceCPU] = cpuQuantity.String() + cr.Target[corev1.ResourceMemory] = memQuantity.String() + } else { + cr.Target[corev1.ResourceCPU] = "" + if *cpuQuantity != c.Resources.Requests[corev1.ResourceCPU] { + cr.Target[corev1.ResourceCPU] = cpuQuantity.String() + } + cr.Target[corev1.ResourceMemory] = "" + if *memQuantity != c.Resources.Requests[corev1.ResourceMemory] { + cr.Target[corev1.ResourceMemory] = memQuantity.String() + } + } newContainerSpec := corev1.Container{ Name: c.Name, diff --git a/pkg/recommendation/recommender/resource/registry.go b/pkg/recommendation/recommender/resource/registry.go index 438c61014..ea7cd28c5 100644 --- a/pkg/recommendation/recommender/resource/registry.go +++ b/pkg/recommendation/recommender/resource/registry.go @@ -14,26 +14,27 @@ var _ recommender.Recommender = &ResourceRecommender{} type ResourceRecommender struct { base.BaseRecommender - CpuSampleInterval string - CpuRequestPercentile string - CpuRequestMarginFraction string - CpuTargetUtilization string - CpuModelHistoryLength string - MemSampleInterval string - MemPercentile string - MemMarginFraction string - MemTargetUtilization string - MemHistoryLength string - OOMProtection bool - OOMHistoryLength time.Duration - OOMBumpRatio float64 - Specification bool - SpecificationConfigs []Specification - CpuHistogramBucketSize string - CpuHistogramMaxValue string - MemHistogramBucketSize string - MemHistogramMaxValue string - HistoryCompletionCheck bool + CpuSampleInterval string + CpuRequestPercentile string + CpuRequestMarginFraction string + CpuTargetUtilization string + CpuModelHistoryLength string + MemSampleInterval string + MemPercentile string + MemMarginFraction string + MemTargetUtilization string + MemHistoryLength string + OOMProtection bool + OOMHistoryLength time.Duration + OOMBumpRatio float64 + Specification bool + SpecificationConfigs []Specification + CpuHistogramBucketSize string + CpuHistogramMaxValue string + MemHistogramBucketSize string + MemHistogramMaxValue string + HistoryCompletionCheck bool + ResourceComplianceRecommendation bool } func init() { @@ -94,7 +95,10 @@ func NewResourceRecommender(recommender apis.Recommender, recommendationRule ana if err != nil { return nil, err } - + resourceComplianceRecommendation, err := recommender.GetConfigBool("resource-compliance-recommendation-check", false) + if err != nil { + return nil, err + } return &ResourceRecommender{ *base.NewBaseRecommender(recommender), cpuSampleInterval, @@ -117,5 +121,6 @@ func NewResourceRecommender(recommender apis.Recommender, recommendationRule ana memHistogramBucketSize, memHistogramMaxValue, historyCompletion, + resourceComplianceRecommendation, }, nil }