Skip to content
Open
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
16 changes: 14 additions & 2 deletions pkg/recommendation/recommender/resource/recommend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 26 additions & 21 deletions pkg/recommendation/recommender/resource/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand All @@ -117,5 +121,6 @@ func NewResourceRecommender(recommender apis.Recommender, recommendationRule ana
memHistogramBucketSize,
memHistogramMaxValue,
historyCompletion,
resourceComplianceRecommendation,
}, nil
}