Skip to content

Commit d843026

Browse files
authored
Merge pull request #51 from StackStorm/feat/partitionsensors
Allow st2sensorcontainer to be partitioned
2 parents f7498be + 12ab1ef commit d843026

File tree

5 files changed

+100
-56
lines changed

5 files changed

+100
-56
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Changelog
22

33
## In Development
4+
5+
## v0.10.0
46
* Bump versions of all dependencies (#50)
7+
* Allow st2sensorcontainer to be partitioned (#51)
58
* Replace single-node `etcd` coordination backend with 3-node etcd HA cluster, deployed as a Helm dependency (#52)
69
* Fixed improper job load order for enterprise edition failing due to missing RBAC roles & assignments (#53)
710

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,27 @@ In an HA deployment there must be a minimum of `2` replicas of st2notifier runni
112112
which in our case is `etcd`.
113113

114114
### [st2sensorcontainer](https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer)
115-
st2sensorcontainer manages StackStorm sensors: starts, stops and restarts them as a subprocesses.
116-
At the moment K8s configuration consists of Deployment with hardcoded `1` replica.
117-
Future plans are to re-work this setup and benefit from Docker-friendly [single-sensor-per-container mode #4179](https://github.com/StackStorm/st2/pull/4179)
118-
(since st2 `v2.9`) as a way of [Sensor Partitioning](https://docs.stackstorm.com/latest/reference/sensor_partitioning.html), distributing the computing load
119-
between many pods and relying on K8s failover/reschedule mechanisms, instead of running everything on `1` single instance of st2sensorcontainer.
115+
st2sensorcontainer manages StackStorm sensors: It starts, stops and restarts them as subprocesses.
116+
By default, deployment is configured with `1` replica containing all the sensors.
120117

118+
st2sensorcontainer also supports a more Docker-friendly single-sensor-per-container mode as a way of
119+
[Sensor Partitioning](https://docs.stackstorm.com/latest/reference/sensor_partitioning.html). This
120+
distributes the computing load between many pods and relies on K8s failover/reschedule mechanisms,
121+
instead of running everything on a single instance of st2sensorcontainer. The sensor(s) must be
122+
deployed as part of the custom packs image.
123+
124+
As an example, override the default Helm values as follows:
125+
126+
```
127+
st2:
128+
packs:
129+
sensors:
130+
- name: github
131+
ref: githubwebhook.GitHubWebhookSensor
132+
- name: circleci
133+
ref: circle_ci.CircleCIWebhookSensor
134+
```
135+
121136
### [st2actionrunner](https://docs.stackstorm.com/reference/ha.html#st2actionrunner)
122137
Stackstorm workers that actually execute actions.
123138
`5` replicas for K8s Deployment are configured by default to increase StackStorm ability to execute actions without excessive queuing.

templates/_helpers.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ stackstorm
2727
{{- define "enterpriseSuffix" -}}
2828
{{ if required "Missing context '.Values.enterprise.enabled'!" .Values.enterprise.enabled }}-enterprise{{ end }}
2929
{{- end -}}
30+
31+
# Generate '-' prefix only when the variable is defined
32+
{{- define "hyphenPrefix" -}}
33+
{{ if . }}-{{ . }}{{end}}
34+
{{- end -}}

templates/deployments.yaml

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -780,56 +780,56 @@ spec:
780780
{{ toYaml . | indent 8 }}
781781
{{- end }}
782782

783+
{{- range .Values.st2.packs.sensors }}
783784
---
784785
apiVersion: apps/v1
785786
kind: Deployment
786787
metadata:
787-
name: {{ .Release.Name }}-st2sensorcontainer{{ template "enterpriseSuffix" . }}
788+
name: {{ $.Release.Name }}-st2sensorcontainer{{ template "hyphenPrefix" .name }}{{ template "enterpriseSuffix" $ }}
788789
labels:
789-
app: st2sensorcontainer
790+
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
790791
tier: backend
791792
vendor: stackstorm
792-
support: {{ template "supportMethod" . }}
793-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
794-
release: {{ .Release.Name }}
795-
heritage: {{ .Release.Service }}
793+
support: {{ template "supportMethod" $ }}
794+
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
795+
release: {{ $.Release.Name }}
796+
heritage: {{ $.Release.Service }}
796797
spec:
797798
selector:
798799
matchLabels:
799-
app: st2sensorcontainer
800-
support: {{ template "supportMethod" . }}
801-
release: {{ .Release.Name }}
800+
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
801+
support: {{ template "supportMethod" $ }}
802+
release: {{ $.Release.Name }}
802803
# https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer
803804
# It is possible to run st2sensorcontainer in HA mode by running one process on each compute instance. Each sensor node needs to be
804805
# provided with proper partition information to share work with other sensor nodes so that the same sensor does not run on different nodes.
805806
# See Partitioning Sensors for information on how to partition sensors.
806-
# TODO: Re-work to use single-sensor-per-container mode instead of running 1 node. Proper implementation is possible with Helm templating (#4)
807807
replicas: 1
808808
template:
809809
metadata:
810810
labels:
811-
app: st2sensorcontainer
811+
app: st2sensorcontainer{{ template "hyphenPrefix" .name }}
812812
tier: backend
813813
vendor: stackstorm
814-
support: {{ template "supportMethod" . }}
815-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
816-
release: {{ .Release.Name }}
817-
heritage: {{ .Release.Service }}
814+
support: {{ template "supportMethod" $ }}
815+
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
816+
release: {{ $.Release.Name }}
817+
heritage: {{ $.Release.Service }}
818818
annotations:
819-
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") . | sha256sum }}
820-
checksum/packs: {{ include (print $.Template.BasePath "/configmaps_packs.yaml") . | sha256sum }}
819+
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") $ | sha256sum }}
820+
checksum/packs: {{ include (print $.Template.BasePath "/configmaps_packs.yaml") $ | sha256sum }}
821821
spec:
822-
{{- if .Values.enterprise.enabled }}
822+
{{- if $.Values.enterprise.enabled }}
823823
imagePullSecrets:
824-
- name: {{ .Release.Name }}-st2-license
824+
- name: {{ $.Release.Name }}-st2-license
825825
{{- end }}
826-
{{- if .Values.st2.packs.image.repository }}
826+
{{- if $.Values.st2.packs.image.repository }}
827827
initContainers:
828828
# Merge packs and virtualenvs from st2sensorcontainer with those from the st2.packs image
829829
# Custom packs
830830
- name: st2-custom-packs
831-
image: "{{ .Values.st2.packs.image.repository }}/{{ .Values.st2.packs.image.name }}:{{ .Values.st2.packs.image.tag }}"
832-
imagePullPolicy: {{ .Values.st2.packs.image.pullPolicy | quote }}
831+
image: "{{ $.Values.st2.packs.image.repository }}/{{ $.Values.st2.packs.image.name }}:{{ $.Values.st2.packs.image.tag }}"
832+
imagePullPolicy: {{ $.Values.st2.packs.image.pullPolicy | quote }}
833833
volumeMounts:
834834
- name: st2-packs-vol
835835
mountPath: /opt/stackstorm/packs-shared
@@ -843,8 +843,8 @@ spec:
843843
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
844844
# System packs
845845
- name: st2-system-packs
846-
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
847-
imagePullPolicy: {{ .Values.image.pullPolicy }}
846+
image: "{{ template "imageRepository" $ }}/st2actionrunner{{ template "enterpriseSuffix" $ }}:{{ $.Chart.AppVersion }}"
847+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
848848
volumeMounts:
849849
- name: st2-packs-vol
850850
mountPath: /opt/stackstorm/packs-shared
@@ -856,23 +856,38 @@ spec:
856856
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
857857
{{- end }}
858858
containers:
859-
- name: st2sensorcontainer{{ template "enterpriseSuffix" . }}
860-
image: "{{ template "imageRepository" . }}/st2sensorcontainer{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
861-
imagePullPolicy: {{ .Values.image.pullPolicy }}
862-
# TODO: Add liveness/readiness probes (#3)
863-
#livenessProbe:
864-
#readinessProbe:
859+
- name: st2sensorcontainer{{ template "hyphenPrefix" .name }}{{ template "enterpriseSuffix" $ }}
860+
image: "{{ template "imageRepository" $ }}/st2sensorcontainer{{ template "enterpriseSuffix" $ }}:{{ $.Chart.AppVersion }}"
861+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
862+
{{- with .readinessProbe }}
863+
# Probe to check if app is running. Failure will lead to a pod restart.
864+
readinessProbe:
865+
{{ toYaml . | indent 10 }}
866+
{{- end }}
867+
{{- with .livenessProbe }}
868+
livenessProbe:
869+
{{ toYaml . | indent 10 }}
870+
{{- end }}
871+
{{- if .ref }}
872+
command:
873+
- /opt/stackstorm/st2/bin/st2sensorcontainer
874+
- --config-file=/etc/st2/st2.conf
875+
- --config-file=/etc/st2/st2.docker.conf
876+
- --config-file=/etc/st2/st2.user.conf
877+
- --single-sensor-mode
878+
- --sensor-ref={{ .ref }}
879+
{{- end }}
865880
envFrom:
866881
- configMapRef:
867-
name: {{ .Release.Name }}-st2-urls
882+
name: {{ $.Release.Name }}-st2-urls
868883
volumeMounts:
869884
- name: st2-config-vol
870885
mountPath: /etc/st2/st2.docker.conf
871886
subPath: st2.docker.conf
872887
- name: st2-config-vol
873888
mountPath: /etc/st2/st2.user.conf
874889
subPath: st2.user.conf
875-
{{- if .Values.st2.packs.image.repository }}
890+
{{- if $.Values.st2.packs.image.repository }}
876891
- name: st2-packs-vol
877892
mountPath: /opt/stackstorm/packs
878893
readOnly: true
@@ -881,29 +896,30 @@ spec:
881896
readOnly: true
882897
{{- end }}
883898
resources:
884-
{{ toYaml .Values.st2sensorcontainer.resources | indent 10 }}
899+
{{ toYaml .resources | indent 10 }}
885900
volumes:
886901
- name: st2-config-vol
887902
configMap:
888-
name: {{ .Release.Name }}-st2-config
889-
{{- if .Values.st2.packs.image.repository }}
903+
name: {{ $.Release.Name }}-st2-config
904+
{{- if $.Values.st2.packs.image.repository }}
890905
- name: st2-packs-vol
891906
emptyDir: {}
892907
- name: st2-virtualenvs-vol
893908
emptyDir: {}
894909
{{- end }}
895-
{{- with .Values.st2sensorcontainer.nodeSelector }}
910+
{{- with .nodeSelector }}
896911
nodeSelector:
897912
{{ toYaml . | indent 8 }}
898913
{{- end }}
899-
{{- with .Values.st2sensorcontainer.affinity }}
914+
{{- with .affinity }}
900915
affinity:
901916
{{ toYaml . | indent 8 }}
902917
{{- end }}
903-
{{- with .Values.st2sensorcontainer.tolerations }}
918+
{{- with .tolerations }}
904919
tolerations:
905920
{{ toYaml . | indent 8 }}
906921
{{- end }}
922+
{{- end }}
907923

908924
---
909925
apiVersion: apps/v1

values.yaml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ st2:
8585
name: st2packs
8686
tag: latest
8787
pullPolicy: Always
88+
89+
# https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer
90+
# It is possible to run st2sensorcontainer in HA mode by running one process on each compute instance.
91+
# Each sensor node needs to be provided with proper partition information to share work with other sensor
92+
# nodes so that the same sensor does not run on different nodes.
93+
sensors:
94+
# Specify default container that executes all sensors.
95+
# To partition sensors with one sensor per node, override st2.packs.sensors.
96+
# NOTE: Do not modify this file.
97+
- name:
98+
livenessProbe: {}
99+
readinessProbe: {}
100+
# TODO: Find out recommended/default resources for this specific service (#5)
101+
resources: {}
102+
# Additional advanced settings to control pod/deployment placement
103+
affinity: {}
104+
nodeSelector: {}
105+
tolerations: []
88106
# Import data into StackStorm's Key/Value datastore (https://docs.stackstorm.com/datastore.html)
89107
keyvalue:
90108
#- name: st2_version
@@ -314,19 +332,6 @@ st2notifier:
314332
nodeSelector: {}
315333
tolerations: []
316334
affinity: {}
317-
# https://docs.stackstorm.com/reference/ha.html#st2sensorcontainer
318-
# It is possible to run st2sensorcontainer in HA mode by running one process on each compute instance. Each sensor node needs to be
319-
# provided with proper partition information to share work with other sensor nodes so that the same sensor does not run on different nodes.
320-
st2sensorcontainer:
321-
# TODO: Re-work to use single-sensor-per-container mode partitioning instead of running 1 single node of st2sensorcontainer. Proper implementation is now possible with Helm templating (#4)
322-
# NB! Number of replicas are hardcoded to 1, see above T0D0 about using single-sensor-per-container mode in future as way of Sensor Partitioning.
323-
# replicas: 1
324-
# TODO: Find out recommended/default resources for this specific service (#5)
325-
resources: {}
326-
# Additional advanced settings to control pod/deployment placement
327-
nodeSelector: {}
328-
tolerations: []
329-
affinity: {}
330335
# https://docs.stackstorm.com/reference/ha.html#st2actionrunner
331336
# Multiple st2actionrunner processes can run in active-active with only connections to MongoDB and RabbitMQ. Work gets naturally
332337
# distributed across runners via RabbitMQ. Adding more st2actionrunner processes increases the ability of StackStorm to execute actions.

0 commit comments

Comments
 (0)