Skip to content

Commit 4e774d5

Browse files
author
liuqx
committed
fix: Add the configuration to meet the load cpu and memory usage. Stop the recommendation
fix: Add the configuration to meet the load cpu and memory usage. Stop the recommendation
1 parent 96c7e4f commit 4e774d5

2 files changed

Lines changed: 40 additions & 23 deletions

File tree

pkg/recommendation/recommender/resource/recommend.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,20 @@ func (rr *ResourceRecommender) Recommend(ctx *framework.RecommendationContext) e
174174
memQuantity = &normalizedMem
175175
}
176176
}
177-
178-
cr.Target[corev1.ResourceCPU] = cpuQuantity.String()
179-
cr.Target[corev1.ResourceMemory] = memQuantity.String()
177+
// Resource Compliance recommendation enabled
178+
if rr.ResourceComplianceRecommendation {
179+
cr.Target[corev1.ResourceCPU] = cpuQuantity.String()
180+
cr.Target[corev1.ResourceMemory] = memQuantity.String()
181+
} else {
182+
if *cpuQuantity != c.Resources.Requests[corev1.ResourceCPU] {
183+
cr.Target[corev1.ResourceCPU] = cpuQuantity.String()
184+
}
185+
cr.Target[corev1.ResourceCPU] = ""
186+
if *memQuantity != c.Resources.Requests[corev1.ResourceMemory] {
187+
cr.Target[corev1.ResourceMemory] = memQuantity.String()
188+
}
189+
cr.Target[corev1.ResourceMemory] = ""
190+
}
180191

181192
newContainerSpec := corev1.Container{
182193
Name: c.Name,

pkg/recommendation/recommender/resource/registry.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@ var _ recommender.Recommender = &ResourceRecommender{}
1414

1515
type ResourceRecommender struct {
1616
base.BaseRecommender
17-
CpuSampleInterval string
18-
CpuRequestPercentile string
19-
CpuRequestMarginFraction string
20-
CpuTargetUtilization string
21-
CpuModelHistoryLength string
22-
MemSampleInterval string
23-
MemPercentile string
24-
MemMarginFraction string
25-
MemTargetUtilization string
26-
MemHistoryLength string
27-
OOMProtection bool
28-
OOMHistoryLength time.Duration
29-
OOMBumpRatio float64
30-
Specification bool
31-
SpecificationConfigs []Specification
32-
CpuHistogramBucketSize string
33-
CpuHistogramMaxValue string
34-
MemHistogramBucketSize string
35-
MemHistogramMaxValue string
36-
HistoryCompletionCheck bool
17+
CpuSampleInterval string
18+
CpuRequestPercentile string
19+
CpuRequestMarginFraction string
20+
CpuTargetUtilization string
21+
CpuModelHistoryLength string
22+
MemSampleInterval string
23+
MemPercentile string
24+
MemMarginFraction string
25+
MemTargetUtilization string
26+
MemHistoryLength string
27+
OOMProtection bool
28+
OOMHistoryLength time.Duration
29+
OOMBumpRatio float64
30+
Specification bool
31+
SpecificationConfigs []Specification
32+
CpuHistogramBucketSize string
33+
CpuHistogramMaxValue string
34+
MemHistogramBucketSize string
35+
MemHistogramMaxValue string
36+
HistoryCompletionCheck bool
37+
ResourceComplianceRecommendation bool
3738
}
3839

3940
func init() {
@@ -94,6 +95,10 @@ func NewResourceRecommender(recommender apis.Recommender, recommendationRule ana
9495
if err != nil {
9596
return nil, err
9697
}
98+
resourceComplianceRecommendation, err := recommender.GetConfigBool("resource-compliance-recommendation-check", false)
99+
if err != nil {
100+
return nil, err
101+
}
97102

98103
return &ResourceRecommender{
99104
*base.NewBaseRecommender(recommender),
@@ -117,5 +122,6 @@ func NewResourceRecommender(recommender apis.Recommender, recommendationRule ana
117122
memHistogramBucketSize,
118123
memHistogramMaxValue,
119124
historyCompletion,
125+
resourceComplianceRecommendation,
120126
}, nil
121127
}

0 commit comments

Comments
 (0)