Skip to content

Commit b2e8872

Browse files
feat: add more predefined triggers. allow for total flexibility (#67)
1 parent 3f9002d commit b2e8872

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

charts/application-core/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 2.0.1
18+
version: 3.0.0
1919

2020
maintainers:
2121
- name: Dominic DePasquale

charts/application-core/templates/scaledobject.yaml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.autoscaling.enabled (eq .Values.autoscaling.type "scaledobject" ) }}
1+
{{- if and (and .Values.autoscaling.enabled (eq .Values.autoscaling.type "scaledobject" )) (coalesce .Values.autoscaling.targetMemoryUtilizationPercentage .Values.autoscaling.targetCPUUtilizationPercentage .Values.autoscaling.triggers .Values.autoscaling.kafka .Values.autoscaling.prometheus .Values.autoscaling.cron ) }}
22
{{- $fullName := include "application-core.fullname" . -}}
33
apiVersion: keda.sh/v1alpha1
44
kind: ScaledObject
@@ -16,18 +16,19 @@ spec:
1616
apiVersion: apps/v1
1717
kind: Deployment
1818
name: {{ include "application-core.fullname" . }}
19-
pollingInterval: 30
20-
cooldownPeriod: 300
19+
pollingInterval: {{ default 30 .Values.autoscaling.pollingInterval }}
20+
cooldownPeriod: {{ default 300 .Values.autoscaling.cooldownPeriod }}
2121
minReplicaCount: {{ .Values.autoscaling.minReplicas }}
2222
maxReplicaCount: {{ .Values.autoscaling.maxReplicas }}
2323
triggers:
24-
{{- if and .Values.autoscaling.targetCPUUtilizationPercentage (not .Values.autoscaling.kafka )}}
24+
{{- if not .Values.autoscaling.triggers -}}
25+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage}}
2526
- type: cpu
2627
metricType: Utilization
2728
metadata:
2829
value: {{ .Values.autoscaling.targetCPUUtilizationPercentage | quote }}
2930
{{- end }}
30-
{{- if and .Values.autoscaling.targetMemoryUtilizationPercentage (not .Values.autoscaling.kafka )}}
31+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage}}
3132
- type: memory
3233
metricType: Utilization
3334
metadata:
@@ -52,4 +53,33 @@ spec:
5253
kind: {{ default "ClusterTriggerAuthentication" .authenticationRefKind }}
5354
{{- end }}
5455
{{- end }}
56+
{{- if .Values.autoscaling.prometheus }}
57+
- type: prometheus
58+
metadata:
59+
{{- with .Values.autoscaling.prometheus }}
60+
serverAddress: {{ .serverAddress }}
61+
query: {{ .query }}
62+
threshold: {{ .threshold }}
63+
activationThreshold: {{ default 0 .activationThreshold | quote }}
64+
ignoreNullValues: {{ default "true" .ignoreNullValues | quote }}
65+
unsafeSsl: "false"
66+
authenticationRef:
67+
name: {{ default "keda-prom-creds" .authenticationRef }}
68+
kind: {{ default "ClusterTriggerAuthentication" .authenticationRefKind }}
69+
{{- end }}
70+
{{- end }}
71+
{{- if .Values.autoscaling.cron }}
72+
- type: cron
73+
metadata:
74+
{{- with .Values.autoscaling.cron }}
75+
timezone: {{ default "UTC" .timezone }}
76+
start: {{ .start }}
77+
end: {{ .end }}
78+
desiredReplicas: {{ .desiredReplicas }}
79+
{{- end }}
80+
{{- end }}
81+
{{- end }}
82+
{{- if .Values.autoscaling.triggers }}
83+
{{- toYaml .Values.autoscaling.triggers | nindent 4 }}
84+
{{- end }}
5585
{{- end }}

charts/application-core/values.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,45 @@ autoscaling:
132132
type: "scaledobject" # Can be 'hpa'
133133
minReplicas: 1
134134
maxReplicas: 10
135-
targetCPUUtilizationPercentage: 80
136-
targetMemoryUtilizationPercentage: 80
135+
136+
# targetCPUUtilizationPercentage: 80
137+
# targetMemoryUtilizationPercentage: 80
138+
137139
# kafka:
138140
# topic: this-topic
139141
# bootstrapServers: this.web.address:9092
140142
# username: thisusername
141143

144+
# prometheus:
145+
# serverAddress: http://prometheus.monitoring.svc.cluster.local:9090
146+
# query: |-
147+
# sum(rate(http_requests_total{job="nginx-ingress"}[1m])) by (namespace)
148+
# threshold: 10.3
149+
150+
# cron:
151+
# timezone: Asia/Kolkata
152+
# start: 30 * * * *
153+
# end: 45 * * * *
154+
# desiredReplicas: "10"
155+
156+
# Alternatively, just specify the entire trigger list yourself
157+
158+
# triggers:
159+
# - type: prometheus
160+
# metadata:
161+
# # Required fields:
162+
# serverAddress: http://<prometheus-host>:9090
163+
# query: sum(rate(http_requests_total{deployment="my-deployment"}[2m])) # Note: query must return a vector/scalar single element response
164+
# threshold: '100.50'
165+
# activationThreshold: '5.5'
166+
# - type: cron
167+
# metadata:
168+
# # Required
169+
# timezone: Asia/Kolkata # The acceptable values would be a value from the IANA Time Zone Database.
170+
# start: 30 * * * * # Every hour on the 30th minute
171+
# end: 45 * * * * # Every hour on the 45th minute
172+
# desiredReplicas: "10"
173+
142174
serviceProfile:
143175
create: false
144176
routes:

0 commit comments

Comments
 (0)