Skip to content

Commit 161a865

Browse files
authored
Merge pull request #1617 from porter-dev/ym/temporal_autoscaler_triggers
Allow flexible custom autoscaling templating for Porter Apps to support Temporal autoscaling
2 parents 831da71 + 639a8d8 commit 161a865

File tree

6 files changed

+180
-10
lines changed

6 files changed

+180
-10
lines changed

applications/web/templates/scaled-object.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,31 @@ spec:
3434
- type: {{ .Values.keda.hpa.scaleDown.policy.type }}
3535
value: {{ .Values.keda.hpa.scaleDown.policy.value }}
3636
periodSeconds: {{ .Values.keda.hpa.scaleDown.policy.periodSeconds }}
37-
{{- if .Values.keda.trigger }}
37+
{{- if or (and .Values.keda.trigger .Values.keda.trigger.metricName) .Values.keda.porterTriggers .Values.keda.triggers }}
3838
triggers:
39+
{{- if and .Values.keda.trigger .Values.keda.trigger.metricName }}
3940
- type: prometheus
40-
metricType: {{ .Values.keda.trigger.metricType }}
41+
metricType: {{ .Values.keda.trigger.metricType | default "AverageValue" }}
4142
metadata:
4243
serverAddress: http://prometheus-server.monitoring.svc.cluster.local:80
4344
metricName: {{ .Values.keda.trigger.metricName }}
4445
query: {{ .Values.keda.trigger.metricQuery }}
4546
threshold: '{{ .Values.keda.trigger.metricThreshold }}'
4647
ignoreNullValues: {{ .Values.keda.trigger.ignoreNullValues | default "true" | quote }}
4748
{{- end }}
48-
{{- if .Values.keda.triggers }}
49-
triggers:
50-
{{- toYaml .Values.keda.triggers | nindent 4 }}
49+
{{- range .Values.keda.porterTriggers }}
50+
{{/* Porter-managed triggers: prefix authenticationRef.name with release name */}}
51+
{{- $authRef := .authenticationRef }}
52+
{{- $triggerCopy := omit . "authenticationRef" }}
53+
- {{- toYaml $triggerCopy | nindent 6 }}
54+
{{- if $authRef }}
55+
authenticationRef:
56+
name: {{ $fullName }}-{{ $authRef.name }}
57+
{{- end }}
58+
{{- end }}
59+
{{- range .Values.keda.triggers }}
60+
{{/* Raw KEDA triggers: pass through as-is */}}
61+
{{- toYaml . | nindent 4 }}
62+
{{- end }}
5163
{{- end }}
5264
{{- end }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{- if and .Values.keda.enabled .Values.keda.authentications -}}
2+
{{- $fullName := include "docker-template.fullname" . -}}
3+
{{- range $authName, $authConfig := .Values.keda.authentications }}
4+
---
5+
apiVersion: keda.sh/v1alpha1
6+
kind: TriggerAuthentication
7+
metadata:
8+
name: {{ $fullName }}-{{ $authName }}
9+
namespace: {{ $.Release.Namespace }}
10+
spec:
11+
{{- if $authConfig.apiKey }}
12+
secretTargetRef:
13+
- parameter: apiKey
14+
name: {{ $authConfig.apiKey.secretName }}
15+
key: {{ $authConfig.apiKey.secretKey }}
16+
{{- end }}
17+
{{- if $authConfig.secretRefs }}
18+
secretTargetRef:
19+
{{- range $authConfig.secretRefs }}
20+
- parameter: {{ .parameter }}
21+
name: {{ .secretName }}
22+
key: {{ .secretKey }}
23+
{{- end }}
24+
{{- end }}
25+
{{- end }}
26+
{{- end }}

applications/web/values.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,44 @@ keda:
174174
metricType: AverageValue
175175
metricQuery: ""
176176
metricThreshold: ""
177+
porterTriggers: []
178+
# Example: Porter-managed triggers (authenticationRef.name gets prefixed with release name)
179+
# - type: temporal
180+
# authenticationRef:
181+
# name: temporal-570667b8-f40c-4b84-a36d-7e805849a361
182+
# metadata:
183+
# endpoint: temporal.example.com:7233
184+
# namespace: default
185+
# taskQueue: my-workflow-queue
186+
# targetQueueSize: "5"
177187
triggers: []
188+
# Example: Raw KEDA triggers (passed through as-is)
189+
# - type: temporal
190+
# authenticationRef:
191+
# name: temporal-auth
192+
# metadata:
193+
# endpoint: temporal-frontend.temporal.svc.cluster.local:7233
194+
# namespace: default
195+
# taskQueue: my-workflow-queue
196+
# targetQueueSize: "5"
197+
198+
# Named authentication configurations that can be referenced by triggers
199+
authentications: {}
200+
# Example for Temporal Cloud API key:
201+
# temporal-auth:
202+
# apiKey:
203+
# secretName: temporal-secret
204+
# secretKey: api-key
205+
#
206+
# Example for custom secret refs:
207+
# custom-auth:
208+
# secretRefs:
209+
# - parameter: username
210+
# secretName: my-secret
211+
# secretKey: username
212+
# - parameter: password
213+
# secretName: my-secret
214+
# secretKey: password
178215

179216
health:
180217
livenessProbe:

applications/worker/templates/scaled-object.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,31 @@ spec:
3434
- type: {{ or .Values.keda.hpa.scaleDown.policy.type "Percent" }}
3535
value: {{ .Values.keda.hpa.scaleDown.policy.value }}
3636
periodSeconds: {{ .Values.keda.hpa.scaleDown.policy.periodSeconds }}
37-
{{- if .Values.keda.trigger }}
37+
{{- if or (and .Values.keda.trigger .Values.keda.trigger.metricName) .Values.keda.porterTriggers .Values.keda.triggers }}
3838
triggers:
39+
{{- if and .Values.keda.trigger .Values.keda.trigger.metricName }}
3940
- type: prometheus
4041
metricType: {{ .Values.keda.trigger.metricType | default "AverageValue" }}
4142
metadata:
42-
# Required fields:
4343
serverAddress: http://prometheus-server.monitoring.svc.cluster.local:80
4444
metricName: {{ .Values.keda.trigger.metricName }}
4545
query: {{ .Values.keda.trigger.metricQuery }}
4646
threshold: '{{ .Values.keda.trigger.metricThreshold }}'
4747
ignoreNullValues: {{ .Values.keda.trigger.ignoreNullValues | default "true" | quote }}
4848
{{- end }}
49-
{{- if .Values.keda.triggers }}
50-
triggers:
51-
{{- toYaml .Values.keda.triggers | nindent 4 }}
49+
{{- range .Values.keda.porterTriggers }}
50+
{{/* Porter-managed triggers: prefix authenticationRef.name with release name */}}
51+
{{- $authRef := .authenticationRef }}
52+
{{- $triggerCopy := omit . "authenticationRef" }}
53+
- {{- toYaml $triggerCopy | nindent 6 }}
54+
{{- if $authRef }}
55+
authenticationRef:
56+
name: {{ $fullName }}-{{ $authRef.name }}
57+
{{- end }}
58+
{{- end }}
59+
{{- range .Values.keda.triggers }}
60+
{{/* Raw KEDA triggers: pass through as-is */}}
61+
{{- toYaml . | nindent 4 }}
62+
{{- end }}
5263
{{- end }}
5364
{{- end }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{- if and .Values.keda.enabled .Values.keda.authentications -}}
2+
{{- $fullName := include "docker-template.fullname" . -}}
3+
{{- range $authName, $authConfig := .Values.keda.authentications }}
4+
---
5+
apiVersion: keda.sh/v1alpha1
6+
kind: TriggerAuthentication
7+
metadata:
8+
name: {{ $fullName }}-{{ $authName }}
9+
namespace: {{ $.Release.Namespace }}
10+
spec:
11+
{{- if $authConfig.apiKey }}
12+
secretTargetRef:
13+
- parameter: apiKey
14+
name: {{ $authConfig.apiKey.secretName }}
15+
key: {{ $authConfig.apiKey.secretKey }}
16+
{{- end }}
17+
{{- if $authConfig.secretRefs }}
18+
secretTargetRef:
19+
{{- range $authConfig.secretRefs }}
20+
- parameter: {{ .parameter }}
21+
name: {{ .secretName }}
22+
key: {{ .secretKey }}
23+
{{- end }}
24+
{{- end }}
25+
{{- end }}
26+
{{- end }}

applications/worker/values.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,65 @@ keda:
103103
metricName: ""
104104
metricQuery: ""
105105
metricThreshold: ""
106+
107+
# Porter-managed triggers: Porter will create TriggerAuthentication resources with the
108+
# release name prefix (e.g., {release-name}-temporal-auth) to avoid ownership conflicts.
109+
# Use this for triggers configured through the Porter app create flow.
110+
porterTriggers: []
111+
# Example Temporal trigger with authentication:
112+
# - type: temporal
113+
# authenticationRef:
114+
# name: temporal-auth # Will become {release-name}-temporal-auth
115+
# metadata:
116+
# endpoint: temporal-frontend.temporal.svc.cluster.local:7233
117+
# namespace: default
118+
# taskQueue: my-workflow-queue
119+
# targetQueueSize: "5"
120+
# queueTypes: workflow,activity
121+
#
122+
# Example Prometheus trigger:
123+
# - type: prometheus
124+
# authenticationRef:
125+
# name: prom-auth # Will become {release-name}-prom-auth
126+
# metadata:
127+
# serverAddress: http://prometheus-server.monitoring.svc.cluster.local
128+
# metricName: http_requests_total
129+
# threshold: '100'
130+
# query: sum(rate(http_requests_total[2m]))
131+
132+
# Raw KEDA triggers: These are passed through as-is without any modifications.
133+
# Use this when you create and manage TriggerAuthentication resources yourself via helm overrides.
134+
# The authenticationRef.name must exactly match your pre-created TriggerAuthentication resource.
106135
triggers: []
136+
# Example with user-managed authentication:
137+
# - type: temporal
138+
# authenticationRef:
139+
# name: my-custom-temporal-auth # Must pre-exist, used exactly as specified
140+
# metadata:
141+
# endpoint: temporal-frontend.temporal.svc.cluster.local:7233
142+
# namespace: default
143+
# taskQueue: my-workflow-queue
144+
# targetQueueSize: "5"
145+
# queueTypes: workflow,activity
146+
147+
# Named authentication configurations that can be referenced by porterTriggers.
148+
# Porter will create TriggerAuthentication resources with the release name prefix.
149+
authentications: {}
150+
# Example for Temporal Cloud API key:
151+
# temporal-auth:
152+
# apiKey:
153+
# secretName: temporal-secret
154+
# secretKey: api-key
155+
#
156+
# Example for custom secret refs:
157+
# custom-auth:
158+
# secretRefs:
159+
# - parameter: username
160+
# secretName: my-secret
161+
# secretKey: username
162+
# - parameter: password
163+
# secretName: my-secret
164+
# secretKey: password
107165

108166
health:
109167
enabled: false

0 commit comments

Comments
 (0)