From 5ef1485927a4818c2c5ffeeb5b6e7192cdce21b6 Mon Sep 17 00:00:00 2001 From: Mihaela Balas Date: Fri, 22 Nov 2024 14:00:51 +0200 Subject: [PATCH] Add keda support --- charts/temporal/templates/keda.yaml | 78 +++++++++++++++++++ .../temporal/templates/server-deployment.yaml | 2 + charts/temporal/values.yaml | 47 +++++++++++ 3 files changed, 127 insertions(+) create mode 100644 charts/temporal/templates/keda.yaml diff --git a/charts/temporal/templates/keda.yaml b/charts/temporal/templates/keda.yaml new file mode 100644 index 00000000..82d00b7e --- /dev/null +++ b/charts/temporal/templates/keda.yaml @@ -0,0 +1,78 @@ +{{- define "app.kedaTriggers" -}} +{{- $kedaMetrics := index . 0 -}} +{{- $targetCPUUtilizationPercentage := index . 1 -}} +{{- $prometheusServerAddress := index . 2 -}} +{{- $awsRegion := index . 3 -}} +{{- $parentContext := index . 4 -}} +{{- if gt (len $kedaMetrics) 0 -}} +{{- range $type, $metric := $kedaMetrics -}} +- type: {{ $type }} + metricType: {{ $metric.metricType }} + metadata: + {{- if eq $type "prometheus" }} + serverAddress: {{ $prometheusServerAddress }} + threshold: {{ $metric.threshold | quote }} + query: {{ tpl (toYaml $metric.query) $parentContext }} + authModes: "custom" + {{- else if eq $type "aws-sqs-queue" }} + queueURL: {{ tpl $metric.queueURL $parentContext }} + queueLength : {{ $metric.queueLength | quote }} + awsRegion: {{ $awsRegion }} + {{- else if eq $type "memory" }} + value: {{ $metric.value | quote }} + {{- end }} + {{- if eq $type "prometheus" }} + authenticationRef: + name: groundcover-cluster-trigger-auth + kind: ClusterTriggerAuthentication + {{- else if eq $type "aws-sqs-queue" }} + authenticationRef: + name: sqs-cluster-trigger-auth + kind: ClusterTriggerAuthentication + {{- end }} +{{- end -}} +{{- else -}} +- type: cpu + metricType: Utilization + metadata: + value: {{ $targetCPUUtilizationPercentage }} +{{- end -}} +{{- end -}} + + +{{- if $.Values.server.enabled }} +{{- range $service := (list "frontend" "history" "matching" "worker") }} +{{ $serviceValues := index $.Values.server $service }} +{{- if $serviceValues.keda }} +{{- $minReplicas := default $.Values.server.replicaCount $serviceValues.replicaCount }} +{{- $maxReplicas := $serviceValues.maxReplicaCount }} +{{- $kedaMetrics := $serviceValues.kedaMetrics }} +{{- $hpaBehavior := $serviceValues.hpaBehavior }} +{{- $targetCPUUtilizationPercentage := $serviceValues.targetCPUUtilizationPercentage | quote }} +{{- $prometheusServerAddress := $.Values.prometheusServerAddress | quote}} +{{- $awsRegion := $.Values.awsRegion -}} + +--- +apiVersion: keda.sh/v1alpha1 +kind: ScaledObject +metadata: + name: {{ include "temporal.componentname" (list $ $service) }}-scaledobject +spec: + advanced: + horizontalPodAutoscalerConfig: + name: {{ include "temporal.componentname" (list $ $service) }}-keda-hpa + {{- if $hpaBehavior }} + behavior: + {{- tpl (toYaml $hpaBehavior) $ | nindent 8 }} + {{- end }} + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "temporal.componentname" (list $ $service) }} + minReplicaCount: {{ $minReplicas }} + maxReplicaCount: {{ $maxReplicas }} + triggers: + {{- include "app.kedaTriggers" (list $kedaMetrics $targetCPUUtilizationPercentage $prometheusServerAddress $awsRegion $) | nindent 4 }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/temporal/templates/server-deployment.yaml b/charts/temporal/templates/server-deployment.yaml index 09bbaa95..ef90a7e5 100644 --- a/charts/temporal/templates/server-deployment.yaml +++ b/charts/temporal/templates/server-deployment.yaml @@ -16,7 +16,9 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: + {{- if not $serviceValues.keda }} replicas: {{ $replicaCount }} + {{- end }} strategy: type: {{ $.Values.server.deploymentStrategy.type }} {{- if eq $.Values.server.deploymentStrategy.type "RollingUpdate" }} diff --git a/charts/temporal/values.yaml b/charts/temporal/values.yaml index 7c52ee0e..ffae93be 100644 --- a/charts/temporal/values.yaml +++ b/charts/temporal/values.yaml @@ -198,6 +198,15 @@ server: - name: default retention: 3d frontend: + # -- enable Keda autoscaler + keda: false + + # -- Keda metrics + kedaMetrics: {} + + # -- hpa scaling behavior + hpaBehavior: {} + service: # Evaluated as template annotations: {} @@ -238,6 +247,15 @@ server: topologySpreadConstraints: [] podDisruptionBudget: {} history: + # -- enable Keda autoscaler + keda: false + + # -- Keda metrics + kedaMetrics: {} + + # -- hpa scaling behavior + hpaBehavior: {} + service: # type: ClusterIP port: 7234 @@ -260,6 +278,15 @@ server: topologySpreadConstraints: [] podDisruptionBudget: {} matching: + # -- enable Keda autoscaler + keda: false + + # -- Keda metrics + kedaMetrics: {} + + # -- hpa scaling behavior + hpaBehavior: {} + service: # type: ClusterIP port: 7235 @@ -282,6 +309,16 @@ server: topologySpreadConstraints: [] podDisruptionBudget: {} worker: + + # -- enable Keda autoscaler + keda: false + + # -- Keda metrics + kedaMetrics: {} + + # -- hpa scaling behavior + hpaBehavior: {} + service: # type: ClusterIP port: 7239 @@ -485,3 +522,13 @@ cassandra: type: ClusterIP mysql: enabled: false + + +# -- enable Keda autoscaler +keda: false + +# -- Keda metrics +kedaMetrics: {} + +# -- hpa scaling behavior +hpaBehavior: {}