From 438792bc20f11b9ffdbd7140ebe542289fd65f3e Mon Sep 17 00:00:00 2001 From: Osama Khan Date: Fri, 7 Jul 2023 00:37:25 +0800 Subject: [PATCH] feat: Add vertical pod autoscaler template (#249) Co-authored-by: d3adb5 Co-authored-by: Hussnain Ahmad Co-authored-by: Zadkiel Aharonian Co-authored-by: Rasheed Amir --- CHANGELOG.md | 3 +++ README.md | 10 ++++++++++ Tiltfile | 16 ++++++++++++++++ Tiltfile-delete | 5 +++++ application/templates/vpa.yaml | 27 +++++++++++++++++++++++++++ application/values-test.yaml | 21 +++++++++++++++++++++ application/values.yaml | 15 +++++++++++++++ 7 files changed, 97 insertions(+) create mode 100644 application/templates/vpa.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 5538179b..6576491d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented here. +### v2.1.18 +- feat: Add vertical pod autoscaler template [PR-249](https://github.com/stakater/application/pull/249) + ### v2.1.17 - feat: allow overriding revisionHistoryLimit [PR-257](https://github.com/stakater/application/pull/257) diff --git a/README.md b/README.md index 0b031e19..ba28c0db 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,16 @@ Stakater [Forecastle](https://github.com/stakater/Forecastle) parameters | autoscaling.maxReplicas | Sets maximum replica count when autoscaling is enabled | `10` | | autoscaling.metrics | Configuration for hpa metrics, set when autoscaling is enabled | `{}` | +### VPA - Vertical Pod Autoscaler Parameters + +| Name | Description | Value | +| ------------------------ | -------------------------------------------------------------------------------------------- | --------------- | +| vpa.enabled | Enable vertical pod autoscaler | `false` | +| vpa.additionalLabels | Labels for vertical pod autoscaler | `{}` | +| vpa.annotations | Annotations for vertical pod autoscaler | `{}` | +| vpa.containerPolicies | container policies for individual containers. | `[]` | + + ### EndpointMonitor Paramaters Stakater [IngressMonitorController](https://github.com/stakater/IngressMonitorController) EndpointMonitor parameters diff --git a/Tiltfile b/Tiltfile index 1b690fae..b85ffcd1 100644 --- a/Tiltfile +++ b/Tiltfile @@ -46,5 +46,21 @@ local_resource( cmd='helm install grafana-operator -n grafana-operator oci://ghcr.io/stakater/charts/grafana-operator --version=0.0.1 --set operator.installPlanApproval=Automatic' ) +# Install openshift-vertical-pod-autoscaler +vpa_namespace = "openshift-vertical-pod-autoscaler" +namespace_create(vpa_namespace) +local_resource( + 'openshift-vertical-pod-autoscaler', + cmd='helm install openshift-vertical-pod-autoscaler -n openshift-vertical-pod-autoscaler oci://ghcr.io/stakater/charts/openshift-vertical-pod-autoscaler' + ) + +# Wait until VPA CRD becomes available +local_resource( + 'wait-for-crds', + cmd='timeout 300s bash -c "until kubectl wait --for condition=Established crd/verticalpodautoscalers.autoscaling.k8s.io; do sleep 10; done"', + resource_deps=[ + 'openshift-vertical-pod-autoscaler' + ]) + # Install cert-manager # it exists already diff --git a/Tiltfile-delete b/Tiltfile-delete index f2e3fd32..e928dcc4 100644 --- a/Tiltfile-delete +++ b/Tiltfile-delete @@ -8,6 +8,10 @@ def delete_external_secrets_operator(): print('Deleting external-secrets operator') local('helm uninstall external-secrets-operator -n external-secrets-operator') +def delete_openshift_vertical_pod_autoscaler(): + print('Uninstalling openshift-vertical-pod-autoscaler') + local('helm uninstall openshift-vertical-pod-autoscaler -n openshift-vertical-pod-autoscaler') + def delete_imc_crds(): print('Deleting imc crds') local('oc get crds -o name | grep \'endpointmonitor\\.stakater\\.com\' | xargs -r -n 1 oc delete') @@ -34,6 +38,7 @@ def delete_grafana_crds(): delete_grafana_operator() delete_external_secrets_operator() +delete_openshift_vertical_pod_autoscaler() delete_imc_crds() delete_forecastle_crds() delete_ss_crds() diff --git a/application/templates/vpa.yaml b/application/templates/vpa.yaml new file mode 100644 index 00000000..36fc32f4 --- /dev/null +++ b/application/templates/vpa.yaml @@ -0,0 +1,27 @@ +{{- if .Values.vpa.enabled -}} +{{- if not (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") }} + {{- fail "There is no VerticalPodAutoscaler resource definition in the target cluster!" }} +{{- end }} +apiVersion: "autoscaling.k8s.io/v1" +kind: VerticalPodAutoscaler +metadata: + name: {{ template "application.name" . }} + namespace: {{ include "application.namespace" . }} + labels: + {{- include "application.labels" . | nindent 4 }} + {{- with .Values.vpa.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.vpa.annotations }} + annotations: + {{- toYaml .Values.vpa.annotations | nindent 4 }} + {{- end }} +spec: + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "application.name" . }} + resourcePolicy: + containerPolicies: + {{- toYaml .Values.vpa.containerPolicies | nindent 6 }} +{{- end }} diff --git a/application/values-test.yaml b/application/values-test.yaml index 8a045636..2f2affb9 100644 --- a/application/values-test.yaml +++ b/application/values-test.yaml @@ -526,6 +526,27 @@ autoscaling: type: Utilization averageUtilization: 60 +# autoscaling is used for vertical pod autoscaling +vpa: +# enabled is a boolean flag for enabling or disabling vpa + enabled: true +# additionalLabels defines additional labels + additionalLabels: + # key: value +# annotations defines annotations in key value pair + annotations: + # key: value +# container policies for individual containers. +# There can be at most one entry for every named container and optionally a single wildcard entry with `containerName = '*'`, which handles all containers that do not have individual policies. + containerPolicies: + - containerName: '*' + minAllowed: + cpu: 0.5 + memory: 1Gi + maxAllowed: + cpu: 1 + memory: 5Gi + # EndpointMonitor for IMC (https://github.com/stakater/IngressMonitorController) endpointMonitor: enabled: true diff --git a/application/values.yaml b/application/values.yaml index 80d0fdf4..e816371f 100644 --- a/application/values.yaml +++ b/application/values.yaml @@ -616,6 +616,21 @@ autoscaling: type: Utilization averageUtilization: 60 +########################################################## +# VPA - Vertical Pod Autoscaling +########################################################## +vpa: +# enabled is a boolean flag for enabling or disabling vpa + enabled: false +# additionalLabels defines additional labels + additionalLabels: + # key: value +# annotations defines annotations in key value pair + annotations: + # key: value +# container policies for individual containers. + containerPolicies: [] + ########################################################## # EndpointMonitor for IMC # https://github.com/stakater/IngressMonitorController