Add support for custom metrics for HPA (#2423)

* Add support for custom metrics for HPA
* Cleanup TargetCPUPercent references from possible places
* HPA v2beta has 80% default  cpu limit if not set

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2022-05-09 17:16:34 +05:30
committed by GitHub
parent 925f817e42
commit 39dd65b224
13 changed files with 496 additions and 77 deletions
+7 -2
View File
@@ -88,12 +88,16 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
if maxRepl == 0 {
maxRepl = minRepl
}
targetCPU := int32(execStrategy.TargetCPUPercent)
targetCPU := int32(execStrategy.TargetCPUPercent) // nolint: staticcheck
var hpaMetrics []asv2beta2.MetricSpec
if targetCPU > 0 {
if targetCPU > 0 && targetCPU < 100 {
hpaMetrics = append(hpaMetrics, ConvertTargetCPUToCustomMetric(targetCPU))
}
if execStrategy.Metrics != nil {
hpaMetrics = append(hpaMetrics, execStrategy.Metrics...)
}
hpa := &asv2beta2.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Name: hpaName,
@@ -105,6 +109,7 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
MinReplicas: &minRepl,
MaxReplicas: maxRepl,
Metrics: hpaMetrics,
Behavior: execStrategy.Behavior,
},
}