Skip to content

Commit

Permalink
Add custom hpa apiversions and metrics support
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkrsk committed May 2, 2022
1 parent b184749 commit 8f15a6e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
1 change: 1 addition & 0 deletions charts/universal-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ Secret `data` object is a map where value can be a string, json or base64 encode
| `scaleTargetRef` | Required [scaleTargetRef](#hpa-scaletargetref-object-parameters) object | |
| `targetCPU` | target CPU utilization percentage | `""` |
| `targetMemory` | target memory utilization percentage | `""` |
| `metrics` | list of custom metrics | `[]` |

### HPA `scaleTargetRef` object parameters

Expand Down
48 changes: 39 additions & 9 deletions charts/universal-chart/results/hpas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ spec:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 10
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 50
---
# Source: universal-chart/templates/hpa.yaml
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2
metadata:
name: test-hpa1
namespace: "default"
Expand All @@ -44,11 +48,37 @@ spec:
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
- resource:
name: cpu
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 50
target:
averageUtilization: 50
type: Utilization
type: Resource
- pods:
metric:
name: packets-per-second
target:
averageValue: 1k
type: AverageValue
type: Pods
- object:
describedObject:
apiVersion: networking.k8s.io/v1
kind: Ingress
name: main-route
metric:
name: requests-per-second
target:
type: Value
value: 10k
type: Object
- external:
metric:
name: queue_messages_ready
selector:
matchLabels:
queue: worker_tasks
target:
averageValue: 30
type: AverageValue
type: External
41 changes: 38 additions & 3 deletions charts/universal-chart/samples/hpas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ hpas:
hpa0:
scaleTargetRef:
name: dep
targetCPU: 10
targetCPU: 50
targetMemory: 50
hpa1:
apiVersion: autoscaling/v2
labels:
foo: bar
annotations:
Expand All @@ -14,5 +16,38 @@ hpas:
apiVersion: apps/v1
kind: Deployment
name: deploy
targetCPU: 50
targetMemory: 50
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
- type: Pods
pods:
metric:
name: packets-per-second
target:
type: AverageValue
averageValue: 1k
- type: Object
object:
metric:
name: requests-per-second
describedObject:
apiVersion: networking.k8s.io/v1
kind: Ingress
name: main-route
target:
type: Value
value: 10k
- type: External
external:
metric:
name: queue_messages_ready
selector:
matchLabels:
queue: "worker_tasks"
target:
type: AverageValue
averageValue: 30
3 changes: 3 additions & 0 deletions charts/universal-chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ spec:
name: memory
targetAverageUtilization: {{ .targetMemory }}
{{- end }}
{{- if .metrics }}
{{- toYaml .metrics | nindent 4 }}
{{- end }}
{{- end -}}

0 comments on commit 8f15a6e

Please sign in to comment.