Skip to content

Commit fd2e6db

Browse files
authored
Merge pull request #221 from cognifloyd/sensor-defaults
Make st2.packs.sensors pull default values from st2sensorcontainer
2 parents c3725b0 + fad93b0 commit fd2e6db

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Allow providing scripts in values for use in lifecycle postStart hooks of all deployments. (#206) (by @cognifloyd)
2020
* Add preRegisterContentCommand in an initContainer for register-content job to run last-minute content customizations (#213) (by @cognifloyd)
2121
* Fix a bug when datastore cryto keys are not able to read by the rules engine. ``datastore_crypto_key`` volume is now mounted on the ``st2rulesengine`` pods (#223) (by @moti1992)
22+
* Minimize required sensor config by using default values from st2sensorcontainer for each sensor in st2.packs.sensors (#221) (by @cognifloyd)
2223

2324
## v0.60.0
2425
* Switch st2 version to `v3.5dev` as a new latest development version (#187)

templates/deployments.yaml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -988,13 +988,18 @@ spec:
988988
{{- end }}
989989

990990
{{- range .Values.st2.packs.sensors }}
991+
{{- $sensor := omit $.Values.st2sensorcontainer "name" "ref" "postStartScript" }}
992+
{{- range $key, $val := . }}
993+
{{- $_ := set $sensor $key $val }}
994+
{{- end }}
995+
{{- $name := print "st2sensorcontainer" (include "hyphenPrefix" $sensor.name) }}
991996
---
992997
apiVersion: apps/v1
993998
kind: Deployment
994999
metadata:
995-
name: {{ $.Release.Name }}-st2sensorcontainer{{ template "hyphenPrefix" .name }}
1000+
name: {{ $.Release.Name }}-{{ $name }}
9961001
labels:
997-
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
1002+
app: {{ $name }}
9981003
tier: backend
9991004
vendor: stackstorm
10001005
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
@@ -1003,7 +1008,7 @@ metadata:
10031008
spec:
10041009
selector:
10051010
matchLabels:
1006-
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
1011+
app: {{ $name }}
10071012
release: {{ $.Release.Name }}
10081013
# https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer
10091014
# It is possible to run st2sensorcontainer in HA mode by running one process on each compute instance. Each sensor node needs to be
@@ -1013,7 +1018,7 @@ spec:
10131018
template:
10141019
metadata:
10151020
labels:
1016-
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
1021+
app: {{ $name }}
10171022
tier: backend
10181023
vendor: stackstorm
10191024
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
@@ -1026,8 +1031,8 @@ spec:
10261031
{{- if $.Values.st2sensorcontainer.postStartScript }}
10271032
checksum/post-start-script: {{ $.Values.st2sensorcontainer.postStartScript | sha256sum }}
10281033
{{- end }}
1029-
{{- if .annotations }}
1030-
{{- toYaml .annotations | nindent 8 }}
1034+
{{- if $sensor.annotations }}
1035+
{{- toYaml $sensor.annotations | nindent 8 }}
10311036
{{- end }}
10321037
spec:
10331038
imagePullSecrets:
@@ -1044,26 +1049,26 @@ spec:
10441049
{{- include "packs-initContainers" $ | nindent 6 }}
10451050
{{- end }}
10461051
containers:
1047-
- name: st2sensorcontainer{{ template "hyphenPrefix" .name }}
1048-
image: '{{ template "imageRepository" $ }}/st2sensorcontainer:{{ tpl (.image.tag | default $.Values.image.tag) $ }}'
1052+
- name: {{ $name }}
1053+
image: '{{ template "imageRepository" $ }}/st2sensorcontainer:{{ tpl ($sensor.image.tag | default $.Values.image.tag) $ }}'
10491054
imagePullPolicy: {{ $.Values.image.pullPolicy }}
1050-
{{- with .readinessProbe }}
1055+
{{- with $sensor.readinessProbe }}
10511056
# Probe to check if app is running. Failure will lead to a pod restart.
10521057
readinessProbe:
10531058
{{- toYaml . | nindent 10 }}
10541059
{{- end }}
1055-
{{- with .livenessProbe }}
1060+
{{- with $sensor.livenessProbe }}
10561061
livenessProbe:
10571062
{{- toYaml . | nindent 10 }}
10581063
{{- end }}
1059-
{{- if .ref }}
1064+
{{- if $sensor.ref }}
10601065
command:
10611066
- /opt/stackstorm/st2/bin/st2sensorcontainer
10621067
- --config-file=/etc/st2/st2.conf
10631068
- --config-file=/etc/st2/st2.docker.conf
10641069
- --config-file=/etc/st2/st2.user.conf
10651070
- --single-sensor-mode
1066-
- --sensor-ref={{ .ref }}
1071+
- --sensor-ref={{ $sensor.ref }}
10671072
{{- end }}
10681073
envFrom:
10691074
- configMapRef:
@@ -1093,8 +1098,8 @@ spec:
10931098
command: ["/bin/bash", "/post-start.sh"]
10941099
{{- end }}
10951100
resources:
1096-
{{- toYaml .resources | nindent 10 }}
1097-
{{- if .serviceAccount.attach }}
1101+
{{- toYaml $sensor.resources | nindent 10 }}
1102+
{{- if $sensor.serviceAccount.attach }}
10981103
serviceAccountName: {{ template "stackstorm-ha.serviceAccountName" $ }}
10991104
{{- end }}
11001105
volumes:
@@ -1121,13 +1126,13 @@ spec:
11211126
{{- with $.Values.dnsConfig }}
11221127
dnsConfig: {{- toYaml . | nindent 8 }}
11231128
{{- end }}
1124-
{{- with .nodeSelector }}
1129+
{{- with $sensor.nodeSelector }}
11251130
nodeSelector: {{- toYaml . | nindent 8 }}
11261131
{{- end }}
1127-
{{- with .affinity }}
1132+
{{- with $sensor.affinity }}
11281133
affinity: {{- toYaml . | nindent 8 }}
11291134
{{- end }}
1130-
{{- with .tolerations }}
1135+
{{- with $sensor.tolerations }}
11311136
tolerations: {{- toYaml . | nindent 8 }}
11321137
{{- end }}
11331138
{{- end }}

values.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ st2:
100100
# It is possible to run st2sensorcontainer in HA mode by running one process on each compute instance.
101101
# Each sensor node needs to be provided with proper partition information to share work with other sensor
102102
# nodes so that the same sensor does not run on different nodes.
103+
# Defaults come from st2sensorcontainer (see below), with per-sensor overrides defined here.
103104
sensors:
104105
# Specify default container that executes all sensors.
105106
# To partition sensors with one sensor per node, override st2.packs.sensors.
@@ -482,8 +483,25 @@ st2actionrunner:
482483

483484
# https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer
484485
# Please see st2.packs.sensors for each sensor instance's config.
485-
# This contains settings that are common to all sensor pods.
486+
# This contains default settings for all sensor pods.
486487
st2sensorcontainer:
488+
resources:
489+
requests:
490+
memory: "100Mi"
491+
cpu: "50m"
492+
# Override default image settings (for now, only tag can be overridden)
493+
image: {}
494+
## Note that Helm templating is supported in this block!
495+
#tag: "{{ .Values.image.tag }}"
496+
livenessProbe: {}
497+
readinessProbe: {}
498+
annotations: {}
499+
# Additional advanced settings to control pod/deployment placement
500+
affinity: {}
501+
nodeSelector: {}
502+
tolerations: []
503+
serviceAccount:
504+
attach: false
487505
# postStartScript is optional. It has the contents of a bash script.
488506
# k8s will run the script in the st2 container in parallel with the ENTRYPOINT.
489507
# The pod will not be marked as "running" until this script completes successfully.

0 commit comments

Comments
 (0)