Skip to content

Commit

Permalink
feat(datahub-gms): Enable autoscaling via HPA (#517)
Browse files Browse the repository at this point in the history
* feat(datahub-gms): Enable autoscaling via HPA
  • Loading branch information
7onn authored Nov 29, 2024
1 parent 72138ab commit 2a0dc8c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/datahub/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Helm chart for DataHub
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.4.37
version: 0.4.38
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 0.14.1
Expand Down
2 changes: 1 addition & 1 deletion charts/datahub/subcharts/datahub-gms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ datahub-gms
===========
A Helm chart for DataHub's datahub-gms component

Current chart version is `0.2.0`
Current chart version is `0.2.176`

## Chart Values

Expand Down
19 changes: 19 additions & 0 deletions charts/datahub/subcharts/datahub-gms/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,22 @@ Return the appropriate apiVersion for ingress.
{{- print "networking.k8s.io/v1beta1" -}}
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for HorizontalPodAutoscaler.
*/}}
{{- define "datahub-gms.hpa.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "autoscaling/v2") (semverCompare ">=1.23-0" .Capabilities.KubeVersion.Version) -}}
{{- print "autoscaling/v2" -}}
{{- else -}}
{{- print "autoscaling/v2beta1" -}}
{{- end -}}
{{- end -}}

{{/*
Create image registry, name and tag for a datahub component
*/}}
{{- define "datahub.image" -}}
{{- $registry := .image.registry | default .imageRegistry -}}
{{ $registry }}/{{ .image.repository }}:{{ required "Global or specific tag is required" (.image.tag | default .version) -}}
{{- end -}}
52 changes: 52 additions & 0 deletions charts/datahub/subcharts/datahub-gms/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- if .Values.hpa.enabled }}
{{- $apiVersion := include "datahub-gms.hpa.apiVersion" . -}}
apiVersion: {{ $apiVersion }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "datahub-gms.fullname" . }}
labels:
{{- include "datahub-gms.labels" . | nindent 4 }}
{{- range $key, $val := .Values.extraLabels }}
{{ $key }}: {{ $val | quote }}
{{- end }}
spec:
{{- if and (.Values.global.strict_mode) (.Values.hpa.enabled) (.Values.global.datahub.managed_ingestion.enabled) (not .Values.global.datahub_standalone_consumers_enabled) }}
{{- fail "\nHPA cannot be used in non standalone mode. Please enable standalone consumers if you wish to run multiple GMS instances and managed ingestion." }}
{{- else }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "datahub-gms.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
{{- with .Values.hpa.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
metrics:
{{- with .Values.hpa.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
{{- if (eq $apiVersion "autoscaling/v2") }}
target:
type: Utilization
averageUtilization: {{ . }}
{{- else }}
targetAverageUtilization: {{ . }}
{{- end }}
{{- end }}
{{- with .Values.hpa.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
{{- if (eq $apiVersion "autoscaling/v2") }}
target:
type: Utilization
averageUtilization: {{ . }}
{{- else }}
targetAverageUtilization: {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/datahub/subcharts/datahub-gms/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

replicaCount: 1

hpa:
# Can only be enabled if global.datahub_standalone_consumers_enabled
enabled: false
minReplicas: 1
maxReplicas: 2
behavior: {}
targetCPUUtilizationPercentage: 100
targetMemoryUtilizationPercentage:

revisionHistoryLimit: 10

image:
Expand Down

0 comments on commit 2a0dc8c

Please sign in to comment.