Skip to content

Commit

Permalink
Merge pull request #6 from evgkrsk/add-hpa
Browse files Browse the repository at this point in the history
Add HPA support
  • Loading branch information
evgkrsk authored May 2, 2022
2 parents a5726e8 + 8f15a6e commit d9bb222
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 1 deletion.
4 changes: 4 additions & 0 deletions charts/universal-chart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 3.2.0 - May 2, 2022

* feat: add HPA support and tests

## 3.1.0 - April 24, 2022

* feat: add PDB support and tests
Expand Down
2 changes: 1 addition & 1 deletion charts/universal-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
description: Nixys universal Helm chart for deploy your apps to Kubernetes
name: universal-chart
version: 3.1.0
version: 3.2.0
maintainers:
- name: Roman Andreev
email: [email protected]
Expand Down
24 changes: 24 additions & 0 deletions charts/universal-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,30 @@ Secret `data` object is a map where value can be a string, json or base64 encode
| `maxUnavailable` | Pods that can be unavailable after the eviction | `""` |
| `extraSelectorLabels` | Extra selectorLabels for select workload | `{}` |

### HorizontalPodAutoscaler parameters

`hpas` is map of HPA parameters, where key is a name

| Name | Description | Value |
|------------------|-------------------------------------------------------------------------|-------------------------|
| `labels` | Extra HPA labels | `{}` |
| `annotations` | Extra HPA annotations | `{}` |
| `apiVersion` | apiVersion for HPA object | `"autoscaling/v2beta1"` |
| `minReplicas` | minimum replicas for HPA | `2` |
| `maxReplicas` | maximum replicas for HPA | `3` |
| `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

| Name | Description | Value |
|------------|----------------------------------|--------------|
| apiVersion | apiVersion for target HPA object | "apps/v1" |
| kind | kind for target HPA object | "Deployment" |
| name | Required name of target object | "" |

## Configuration and installation details

### Using private registries
Expand Down
84 changes: 84 additions & 0 deletions charts/universal-chart/results/hpas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# Source: universal-chart/templates/hpa.yaml
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
name: test-hpa0
namespace: "default"
labels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
annotations:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-dep
minReplicas: 2
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 50
---
# Source: universal-chart/templates/hpa.yaml
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2
metadata:
name: test-hpa1
namespace: "default"
labels:
app.kubernetes.io/name: test
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
foo: bar
annotations:
bar.io/bar: foo
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-deploy
minReplicas: 1
maxReplicas: 2
metrics:
- resource:
name: cpu
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
53 changes: 53 additions & 0 deletions charts/universal-chart/samples/hpas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
hpas:
hpa0:
scaleTargetRef:
name: dep
targetCPU: 50
targetMemory: 50
hpa1:
apiVersion: autoscaling/v2
labels:
foo: bar
annotations:
bar.io/bar: foo
minReplicas: 1
maxReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: deploy
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
38 changes: 38 additions & 0 deletions charts/universal-chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- range $name, $hpa := .Values.hpas }}
---
kind: HorizontalPodAutoscaler
apiVersion: {{ .apiVersion | default "autoscaling/v2beta1" }}
metadata:
name: {{ include "helpers.app.fullname" (dict "name" $name "context" $) }}
namespace: {{ $.Release.Namespace | quote }}
labels:
{{- include "helpers.app.labels" $ | nindent 4 }}
{{- with .labels }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{- end }}
annotations:
{{- with .annotations }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{- end }}
spec:
{{- with .scaleTargetRef }}
scaleTargetRef:
apiVersion: {{ .apiVersion | default "apps/v1" }}
kind: {{ .kind | default "Deployment" }}
name: {{ include "helpers.app.fullname" (dict "name" .name "context" $) }}
{{- end }}
minReplicas: {{ .minReplicas | default "2" }}
maxReplicas: {{ .maxReplicas | default "3" }}
metrics:
{{- if not (empty .targetCPU) }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .targetCPU }}
{{- end }}
{{- if not (empty .targetMemory) }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .targetMemory }}
{{- end }}
{{- if .metrics }}
{{- toYaml .metrics | nindent 4 }}
{{- end }}
{{- end -}}

0 comments on commit d9bb222

Please sign in to comment.