Skip to content

Commit

Permalink
Add HPA support
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkrsk committed May 2, 2022
1 parent a5726e8 commit b184749
Show file tree
Hide file tree
Showing 6 changed files with 135 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
23 changes: 23 additions & 0 deletions charts/universal-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@ 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 | `""` |

### 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
54 changes: 54 additions & 0 deletions charts/universal-chart/results/hpas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# 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: 10
---
# Source: universal-chart/templates/hpa.yaml
kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
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:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
- type: Resource
resource:
name: memory
targetAverageUtilization: 50
18 changes: 18 additions & 0 deletions charts/universal-chart/samples/hpas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
hpas:
hpa0:
scaleTargetRef:
name: dep
targetCPU: 10
hpa1:
labels:
foo: bar
annotations:
bar.io/bar: foo
minReplicas: 1
maxReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: deploy
targetCPU: 50
targetMemory: 50
35 changes: 35 additions & 0 deletions charts/universal-chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- 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 }}
{{- end -}}

0 comments on commit b184749

Please sign in to comment.