Skip to content

Commit

Permalink
fix: Add the configuration to meet the load cpu and memory usage. Sto…
Browse files Browse the repository at this point in the history
…p the recommendation
  • Loading branch information
liuqx committed Aug 24, 2023
1 parent 96c7e4f commit cbd132d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
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
}

0 comments on commit cbd132d

Please sign in to comment.