Skip to content

feat(common): refactor horizontal pod autoscaler #34625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions charts/library/common-test/tests/hpa/names_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
suite: hpa name test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should generate correct hpa name
set:
workload:
workload-name:
enabled: true
primary: true
type: Deployment
podSpec: {}
workload-name-2:
enabled: true
type: Deployment
podSpec: {}
hpa:
vpa-name:
enabled: true
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
equal:
path: metadata.name
value: test-release-name-common-test
- documentIndex: &deploymentDoc 1
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
equal:
path: metadata.name
value: test-release-name-common-test-workload-name-2
- documentIndex: &hpaDoc 2
isKind:
of: HorizontalPodAutoscaler
- documentIndex: *hpaDoc
isAPIVersion:
of: autoscaling/v2
- documentIndex: *hpaDoc
equal:
path: metadata.name
value: test-release-name-common-test
- documentIndex: &otherHPADoc 3
isKind:
of: HorizontalPodAutoscaler
- documentIndex: *otherHPADoc
isAPIVersion:
of: autoscaling/v2
- documentIndex: *otherHPADoc
equal:
path: metadata.name
value: test-release-name-common-test-workload-name-2
265 changes: 265 additions & 0 deletions charts/library/common-test/tests/hpa/spec_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
suite: hpa spec test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should create hpa
set:
workload: &workload
workload-name:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name:
enabled: true
primary: true
probes:
readiness:
enabled: false
liveness:
enabled: false
startup:
enabled: false
hpa:
hpa-name:
enabled: true
asserts:
- documentIndex: &hpaDoc 1
isKind:
of: HorizontalPodAutoscaler
- documentIndex: *hpaDoc
isAPIVersion:
of: autoscaling/v2
- documentIndex: *hpaDoc
isSubset:
path: spec
content:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-release-name-common-test
minReplicas: 1
maxReplicas: 3

- it: should create hpa with targetSelector
set:
workload:
workload-name:
enabled: true
primary: true
type: Deployment
podSpec: {}
workload-name-2:
enabled: true
type: Deployment
podSpec: {}
hpa:
hpa-name:
enabled: true
targetSelector:
- workload-name-2
asserts:
- hasDocuments:
count: 3 # 2 Deployments, 1 HPA
- documentIndex: &hpaDoc 2
isKind:
of: HorizontalPodAutoscaler
- documentIndex: *hpaDoc
isAPIVersion:
of: autoscaling/v2
- documentIndex: *hpaDoc
isSubset:
path: spec
content:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-release-name-common-test-workload-name-2
minReplicas: 1
maxReplicas: 3

- it: should create hpa with options
set:
workload: *workload
hpa:
hpa-name:
enabled: true
minReplicas: 50
maxReplicas: 100
behavior:
scaleUp:
stabilizationWindowSeconds: 50
policies:
- type: Pods
value: 10
periodSeconds: 60
scaleDown:
selectPolicy: Min
stabilizationWindowSeconds: 150
policies:
- type: Percent
value: 20
periodSeconds: 60
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: cpu
target:
type: AverageValue
averageValue: 1000m
value: 1000m
- type: ContainerResource
containerResource:
name: memory
container: container-name
target:
type: Utilization
averageUtilization: 80
- type: Pods
pods:
metric:
name: custom-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
- type: Object
object:
metric:
name: object-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
describedObject:
apiVersion: apps/v1
kind: Deployment
name: some-name
- type: External
external:
metric:
name: external-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
asserts:
- documentIndex: &hpaDoc 1
isKind:
of: HorizontalPodAutoscaler
- documentIndex: *hpaDoc
isAPIVersion:
of: autoscaling/v2
- documentIndex: *hpaDoc
equal:
path: spec.minReplicas
value: 50
- documentIndex: *hpaDoc
equal:
path: spec.maxReplicas
value: 100
- documentIndex: *hpaDoc
equal:
path: spec.behavior
value:
scaleUp:
selectPolicy: Max
stabilizationWindowSeconds: 50
policies:
- type: Pods
value: 10
periodSeconds: 60
scaleDown:
selectPolicy: Min
stabilizationWindowSeconds: 150
policies:
- type: Percent
value: 20
periodSeconds: 60
- documentIndex: *hpaDoc
isSubset:
path: spec
content:
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: cpu
target:
type: AverageValue
averageValue: 1000m
value: 1000m
- type: ContainerResource
containerResource:
name: memory
container: container-name
target:
type: Utilization
averageUtilization: 80
- type: Pods
pods:
metric:
name: custom-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
- type: Object
object:
metric:
name: object-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
describedObject:
apiVersion: apps/v1
kind: Deployment
name: some-name
- type: External
external:
metric:
name: external-metric
selector:
matchLabels:
custom-label: custom-value
target:
type: AverageValue
averageValue: 1000m
Loading
Loading