From b91bf9630723fe2bbc95ead2a88c19c09168020b Mon Sep 17 00:00:00 2001 From: calvin Date: Sat, 23 Mar 2024 03:27:14 -0600 Subject: [PATCH] Signed-off-by: Simple-Analysis 4850112+Simple-Analysis@users.noreply.github.com Add support for memory utilization in HorizontalPodAutoscaler Signed-off-by: calvin --- charts/opensearch-dashboards/CHANGELOG.md | 12 ++++++- charts/opensearch-dashboards/Chart.yaml | 2 +- .../templates/_helpers.tpl | 15 ++++++++ .../templates/autoscaler.yaml | 34 +++++++++++++++++-- charts/opensearch-dashboards/values.yaml | 4 ++- 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/charts/opensearch-dashboards/CHANGELOG.md b/charts/opensearch-dashboards/CHANGELOG.md index 1fba9bb2..0ab18830 100644 --- a/charts/opensearch-dashboards/CHANGELOG.md +++ b/charts/opensearch-dashboards/CHANGELOG.md @@ -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 diff --git a/charts/opensearch-dashboards/Chart.yaml b/charts/opensearch-dashboards/Chart.yaml index a1242a5f..acd00645 100644 --- a/charts/opensearch-dashboards/Chart.yaml +++ b/charts/opensearch-dashboards/Chart.yaml @@ -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 diff --git a/charts/opensearch-dashboards/templates/_helpers.tpl b/charts/opensearch-dashboards/templates/_helpers.tpl index 6c4b60ba..a51f4ec0 100644 --- a/charts/opensearch-dashboards/templates/_helpers.tpl +++ b/charts/opensearch-dashboards/templates/_helpers.tpl @@ -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. */}} diff --git a/charts/opensearch-dashboards/templates/autoscaler.yaml b/charts/opensearch-dashboards/templates/autoscaler.yaml index be628442..ff054d39 100644 --- a/charts/opensearch-dashboards/templates/autoscaler.yaml +++ b/charts/opensearch-dashboards/templates/autoscaler.yaml @@ -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 @@ -11,5 +11,33 @@ spec: apiVersion: apps/v1 kind: Deployment name: {{ template "opensearch-dashboards.fullname" . }} - targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} -{{- end }} \ No newline at end of file + {{- 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 }} diff --git a/charts/opensearch-dashboards/values.yaml b/charts/opensearch-dashboards/values.yaml index 524031b4..40fece82 100644 --- a/charts/opensearch-dashboards/values.yaml +++ b/charts/opensearch-dashboards/values.yaml @@ -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"