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:
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user