in cost-optimization/gke-shift-left-cost/api/builder_hpa.go [82:113]
func buildHPAV2beta1(hpa *v2beta1.HorizontalPodAutoscaler) HPA {
targetCPUPercentage := int32(0)
netrics := hpa.Spec.Metrics
for i := 0; i < len(netrics); i++ {
metric := netrics[i]
if metric.Type == v2beta1.ResourceMetricSourceType {
res := metric.Resource
if res.Name == "cpu" && res.TargetAverageUtilization != (*int32)(nil) {
targetCPUPercentage = *res.TargetAverageUtilization
}
}
}
var minReplicas int32 = 1
if hpa.Spec.MinReplicas != (*int32)(nil) {
minReplicas = *hpa.Spec.MinReplicas
}
namespace := "default"
if hpa.GetNamespace() != "" {
namespace = hpa.GetNamespace()
}
targetRef := hpa.Spec.ScaleTargetRef
return HPA{
APIVersionKindName: fmt.Sprintf("%s|%s|%s|%s", hpa.APIVersion, hpa.Kind, namespace, hpa.GetName()),
TargetRef: fmt.Sprintf("%s|%s|%s|%s", targetRef.APIVersion, targetRef.Kind, namespace, targetRef.Name),
MinReplicas: minReplicas,
MaxReplicas: hpa.Spec.MaxReplicas,
TargetCPUPercentage: targetCPUPercentage,
}
}