Skip to content

Commit ff5df44

Browse files
authored
Merge pull request #299 from cognifloyd/label-helper
Refactor: Add helpers/partials to build labels
2 parents 5ca4535 + 620a678 commit ff5df44

23 files changed

+295
-499
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## In Development
44
* Temporary workaround for #311 to use previous bitnami index from: https://github.com/bitnami/charts/issues/10539 (#312) (by @0xhaven)
5+
* Refactor label definitions to be more consistent by building labels and label selectors in partial helper templates. (#299) (by @cognifloyd)
56

67
## v0.100.0
78
* Switch st2 to `v3.7` as a new default stable version (#274)

templates/_helpers.tpl

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ Expand the name of the chart.
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
66
{{- end -}}
77

8+
{{/*
9+
Common labels
10+
Usage: "{{ include "stackstorm-ha.labels" (list $ "st2servicename") }}"
11+
*/}}
12+
{{- define "stackstorm-ha.labels" -}}
13+
{{- $root := index . 0 }}
14+
{{- $name := index . 1 }}
15+
{{ include "stackstorm-ha.selectorLabels" . }}
16+
{{- if list "st2web" "ingress" | has $name }}
17+
tier: frontend
18+
{{- else if eq $name "st2tests" }}
19+
tier: tests
20+
{{- else }}
21+
tier: backend
22+
{{- end }}
23+
vendor: stackstorm
24+
chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version }}
25+
heritage: {{ $root.Release.Service }}
26+
{{- end -}}
27+
28+
{{/*
29+
Selector labels
30+
Usage: "{{ include "stackstorm-ha.selectorLabels" (list $ "st2servicename") }}"
31+
*/}}
32+
{{- define "stackstorm-ha.selectorLabels" -}}
33+
{{- $root := index . 0 }}
34+
{{- $name := index . 1 }}
35+
app: {{ $name }}
36+
release: {{ $root.Release.Name }}
37+
{{- end -}}
38+
839
{{/*
940
Generate Docker image repository: Public Docker Hub 'stackstorm' for FOSS version
1041
*/}}

templates/configmaps_packs.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ metadata:
55
name: {{ .Release.Name }}-st2-pack-configs
66
annotations:
77
description: StackStorm pack configs defined in helm values, shipped in (or copied to) '/opt/stackstorm/configs/'
8-
labels:
9-
app: st2
10-
tier: backend
11-
vendor: stackstorm
12-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
13-
release: {{ .Release.Name }}
14-
heritage: {{ .Release.Service }}
8+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
159
data:
1610
{{ toYaml .Values.st2.packs.configs | indent 2 }}

templates/configmaps_post-start-script.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ metadata:
77
name: {{ $.Release.Name }}-{{ . }}-post-start-script
88
annotations:
99
description: Custom postStart lifecycle event handler script for {{ . }}
10-
labels:
11-
app: st2
12-
tier: backend
13-
vendor: stackstorm
14-
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
15-
release: {{ $.Release.Name }}
16-
heritage: {{ $.Release.Service }}
10+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
1711
data:
1812
# k8s calls this script in parallel with starting {{ . }} (ie the same time as ENTRYPOINT)
1913
# The pod will not be marked as "running" until this script completes successfully.

templates/configmaps_rbac.yaml

+3-21
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ metadata:
66
name: {{ .Release.Name }}-st2-rbac-roles
77
annotations:
88
description: Custom StackStorm RBAC roles, shipped in '/opt/stackstorm/rbac/roles/'
9-
labels:
10-
app: st2
11-
tier: backend
12-
vendor: stackstorm
13-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
14-
release: {{ .Release.Name }}
15-
heritage: {{ .Release.Service }}
9+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
1610
data:
1711
{{- range $filename, $contents := .Values.st2.rbac.roles }}
1812
{{/* to support removing default files, skip files with empty contents */}}
@@ -29,13 +23,7 @@ metadata:
2923
name: {{ .Release.Name }}-st2-rbac-assignments
3024
annotations:
3125
description: Custom StackStorm RBAC role assignments, shipped in '/opt/stackstorm/rbac/assignments/'
32-
labels:
33-
app: st2
34-
tier: backend
35-
vendor: stackstorm
36-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
37-
release: {{ .Release.Name }}
38-
heritage: {{ .Release.Service }}
26+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
3927
data:
4028
{{- range $filename, $contents := .Values.st2.rbac.assignments }}
4129
{{/* to support removing default files, skip files with empty contents */}}
@@ -52,13 +40,7 @@ metadata:
5240
name: {{ .Release.Name }}-st2-rbac-mappings
5341
annotations:
5442
description: StackStorm RBAC LDAP groups-to-roles mapping rules, shipped in '/opt/stackstorm/rbac/mappings/'
55-
labels:
56-
app: st2
57-
tier: backend
58-
vendor: stackstorm
59-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
60-
release: {{ .Release.Name }}
61-
heritage: {{ .Release.Service }}
43+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
6244
data:
6345
{{- if .Values.st2.rbac.mappings }}
6446
{{ toYaml .Values.st2.rbac.mappings | indent 2 }}

templates/configmaps_st2-conf.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ metadata:
55
name: {{ .Release.Name }}-st2-config
66
annotations:
77
description: Custom StackStorm config which will apply settings on top of default st2.conf
8-
labels:
9-
app: st2
10-
tier: backend
11-
vendor: stackstorm
12-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
13-
release: {{ .Release.Name }}
14-
heritage: {{ .Release.Service }}
8+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
159
data:
1610
# TODO: Bundle DB/MQ login secrets in dynamic ENV-based st2.secrets.conf, leave custom user-defined settings for st2.user.conf (?)
1711
# Docker/K8s-based st2 config file used for templating service names and common overrides on top of original st2.conf.

templates/configmaps_st2-urls.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ metadata:
55
name: {{ .Release.Name }}-st2-urls
66
annotations:
77
description: StackStorm service URLs, used across entire st2 cluster
8-
labels:
9-
app: st2
10-
tier: backend
11-
vendor: stackstorm
12-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
13-
release: {{ .Release.Name }}
14-
heritage: {{ .Release.Service }}
8+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
159
data:
1610
ST2_AUTH_URL: http://{{ .Release.Name }}-st2auth:9100/
1711
ST2_API_URL: http://{{ .Release.Name }}-st2api:9101/

templates/configmaps_st2web.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ metadata:
66
name: {{ .Release.Name }}-st2web-config
77
annotations:
88
description: Custom StackStorm Web config which will override defaults
9-
labels:
10-
app: st2
11-
tier: backend
12-
vendor: stackstorm
13-
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
14-
release: {{ .Release.Name }}
15-
heritage: {{ .Release.Service }}
9+
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
1610
data:
1711
# User-defined st2web config with custom settings to replace default config.js
1812
# See https://github.com/StackStorm/st2web#connecting-to-st2-server for more info

0 commit comments

Comments
 (0)