Skip to content

Commit

Permalink
Add keda support
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaelabalas84 committed Nov 25, 2024
1 parent e03023a commit 5ef1485
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
78 changes: 78 additions & 0 deletions charts/temporal/templates/keda.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions charts/temporal/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand Down
47 changes: 47 additions & 0 deletions charts/temporal/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -485,3 +522,13 @@ cassandra:
type: ClusterIP
mysql:
enabled: false


# -- enable Keda autoscaler
keda: false

# -- Keda metrics
kedaMetrics: {}

# -- hpa scaling behavior
hpaBehavior: {}

0 comments on commit 5ef1485

Please sign in to comment.