kube-linter
kube-linter copied to clipboard
[BUG] dangling-hpa only works for v2beta1
System info:
- OS: linux
Describe the bug
Description of the problem/feature request
Current implementation of template dangling-hpa
only support v2beta1 of horizontalpodautoscaler. There are a couple versions now v1, v2beta1, v2beta2, and v2
Description of the existing behavior vs. expected behavior This is tested on head of main branch.
The following is generating the expected warning for dangling
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: demo
spec:
maxReplicas: 5
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo-app
targetCPUUtilizationPercentage: 50
Changing the version to v1 lead to a false statement of No lint errors found!:
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: demo
spec:
maxReplicas: 5
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo-app
targetCPUUtilizationPercentage: 50
The expected output of this would be:
hpa.yaml: (object: <no namespace>/demo autoscaling/v1, Kind=HorizontalPodAutoscaler) no resources found matching HorizontalPodAutoscaler scaleTargetRef ({Deployment demo-app apps/v1}) (check: dangling-horizontalpodautoscaler, remediation: Confirm that your HorizontalPodAutoscaler's scaleTargetRef correctly matches one of your deployments.)
Same for v2.
Should just need to update here to deal with the over version https://github.com/stackrox/kube-linter/blob/main/pkg/templates/danglinghpa/template.go#L33
Related to #287