Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add the configuration to meet the load cpu and memory usage. Sto… #854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
}
Loading