zegl / kube-score

Kubernetes object analysis with recommendations for improved reliability and security. kube-score actively prevents downtime and bugs in your Kubernetes YAML and Charts. Static code analysis for Kubernetes.
https://kube-score.com
MIT License
2.74k stars 176 forks source link

[CRITICAL] HorizontalPodAutoscaler has target - reporting a potential false positive #332

Open rvillane opened 3 years ago

rvillane commented 3 years ago

Which version of kube-score are you using?

kube-score version: 1.10.0, commit: 95faa2ad082e05d8b7637d0bd5e1ae00d1550260, built: 2020-11-07T14:17:50Z

What did you do?

A complete description of the steps you took to trigger the incorrect behaviour. scored an HPA YAML definition associated to a Deployment

Include Kubernetes object YAML/JSON if you have it

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: inventory-processor-load-hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: inventory-processor-load
  minReplicas: 3
  maxReplicas: 12
  targetCPUUtilizationPercentage: 70

What did you expect to see?

A clear and concise description of what you expected to happen.

I've got the following validation error, definitely the HPA and Deployment and running fine, then it looks like a false positive to me, unless I'm totally misunderstanding the error message.

A description of what happened, include logs and program output

autoscaling/v1/HorizontalPodAutoscaler inventory-processor-load-hpa in default💥
    [CRITICAL] HorizontalPodAutoscaler has target
        · The HPA target does not match anything
zegl commented 3 years ago

Hey,

kube-score expects to receive all objects as input to the program so that it can make the correlations between them. You can see the testcase in https://github.com/zegl/kube-score/blob/master/score/testdata/hpa-targets-deployment.yaml as an example.

phyzical commented 3 weeks ago

i know this is old but just ran into this whehn using hpa with argo rollouts, and name prefixing

namePrefix: my-app-
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa
spec:
  maxReplicas: 1
  minReplicas: 1
  scaleTargetRef:
    apiVersion: argoproj.io/v1alpha1
    kind: Rollout
    name: rollout
  targetCPUUtilizationPercentage: 85
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollout
  namespace: development
spec: