Skip to content

Commit

Permalink
Signed-off-by: Simple-Analysis [email protected].…
Browse files Browse the repository at this point in the history
…github.com

Add support for memory utilization in HorizontalPodAutoscaler

Signed-off-by: calvin <[email protected]>
  • Loading branch information
calvin committed Mar 23, 2024
1 parent 0dfa606 commit b91bf96
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
12 changes: 11 additions & 1 deletion charts/opensearch-dashboards/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Security
---
## [2.17.0]
### Added
- Support for newer HorizontalPodAutoscaler api in Dashboards
- Ability to configure HorizontalPodAutoscaler to use memory as a metric source type
### Changed
### Deprecated
### Removed
### Fixed
### Security
---
## [2.16.0]
### Added
- Updated OpenSearch Dashboards appVersion to 2.12.0
- Updated OpenSearch Dashboards appVersion to 2.12.0
### Changed
### Deprecated
### Removed
Expand Down
2 changes: 1 addition & 1 deletion charts/opensearch-dashboards/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.16.0
version: 2.17.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
15 changes: 15 additions & 0 deletions charts/opensearch-dashboards/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ Return the appropriate apiVersion for ingress.
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for Horizontal Pod Autoscaler.
*/}}
{{- define "opensearch-dashboards.hpa.apiVersion" -}}
{{- if $.Capabilities.APIVersions.Has "autoscaling/v2/HorizontalPodAutoscaler" }}
{{- print "autoscaling/v2" }}
{{- else if $.Capabilities.APIVersions.Has "autoscaling/v2beta2/HorizontalPodAutoscaler" }}
{{- print "autoscaling/v2beta2" }}
{{- else if $.Capabilities.APIVersions.Has "autoscaling/v2beta1/HorizontalPodAutoscaler" }}
{{- print "autoscaling/v2beta1" }}
{{- else }}
{{- print "autoscaling/v1" }}
{{- end }}
{{- end }}

{{/*
Return if ingress is stable.
*/}}
Expand Down
34 changes: 31 additions & 3 deletions charts/opensearch-dashboards/templates/autoscaler.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.autoscaling.enabled -}}
apiVersion: autoscaling/v1
apiVersion: {{ include "opensearch-dashboards.hpa.apiVersion" . }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ template "opensearch-dashboards.fullname" . }}-hpa
Expand All @@ -11,5 +11,33 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: {{ template "opensearch-dashboards.fullname" . }}
targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v1" }}
targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }}
{{- else }}
metrics:
{{- if .Values.autoscaling.targetMemory }}
- type: Resource
resource:
name: memory
{{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v2beta1" }}
targetAverageUtilization: {{ .Values.autoscaling.targetMemory }}
{{- else }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemory }}
{{- end }}
{{- end }}
{{- if or .Values.autoscaling.targetCPU .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
{{- if eq (include "opensearch-dashboards.hpa.apiVersion" .) "autoscaling/v2beta1" }}
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }}
{{- else }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage | default .Values.autoscaling.targetCPU }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion charts/opensearch-dashboards/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 10
targetCPUUtilizationPercentage: 80
# The legacy `targetCPUUtilizationPercentage` key has been deprecated in favor of `targetCPU`
targetCPU: "80"
targetMemory: "80"

updateStrategy:
type: "Recreate"
Expand Down

0 comments on commit b91bf96

Please sign in to comment.