adapt: pkg/api/kubegraph/analysis.FindHPASpecsMissingCPUTargets
@@ -5,6 +5,8 @@ import (
"strings"
"k8s.io/apimachinery/pkg/util/sets"
+ kapi "k8s.io/kubernetes/pkg/api"
+ "k8s.io/kubernetes/pkg/apis/autoscaling"
graphapi "github.com/gonum/graph"
"github.com/gonum/graph/path"
@@ -36,7 +38,15 @@ func FindHPASpecsMissingCPUTargets(graph osgraph.Graph, namer osgraph.Namer) []o
for _, uncastNode := range graph.NodesByKind(kubenodes.HorizontalPodAutoscalerNodeKind) {
node := uncastNode.(*kubenodes.HorizontalPodAutoscalerNode)
- if node.HorizontalPodAutoscaler.Spec.TargetCPUUtilizationPercentage == nil {
+ cpuFound := false
+ for _, metric := range node.HorizontalPodAutoscaler.Spec.Metrics {
+ if metric.Type == autoscaling.ResourceMetricSourceType && metric.Resource != nil && metric.Resource.Name == kapi.ResourceCPU {
+ cpuFound = true
+ break
+ }
+ }
+
+ if !cpuFound {
markers = append(markers, osgraph.Marker{
Node: node,
Severity: osgraph.ErrorSeverity,
