Skip to content

Commit

Permalink
Merge pull request #299 from cognifloyd/label-helper
Browse files Browse the repository at this point in the history
Refactor: Add helpers/partials to build labels
  • Loading branch information
cognifloyd committed Jun 5, 2022
2 parents 5ca4535 + 620a678 commit ff5df44
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 499 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

## v0.100.0
* Switch st2 to `v3.7` as a new default stable version (#274)
Expand Down
31 changes: 31 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ Expand the name of the chart.
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
Usage: "{{ include "stackstorm-ha.labels" (list $ "st2servicename") }}"
*/}}
{{- define "stackstorm-ha.labels" -}}
{{- $root := index . 0 }}
{{- $name := index . 1 }}
{{ include "stackstorm-ha.selectorLabels" . }}
{{- if list "st2web" "ingress" | has $name }}
tier: frontend
{{- else if eq $name "st2tests" }}
tier: tests
{{- else }}
tier: backend
{{- end }}
vendor: stackstorm
chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version }}
heritage: {{ $root.Release.Service }}
{{- end -}}

{{/*
Selector labels
Usage: "{{ include "stackstorm-ha.selectorLabels" (list $ "st2servicename") }}"
*/}}
{{- define "stackstorm-ha.selectorLabels" -}}
{{- $root := index . 0 }}
{{- $name := index . 1 }}
app: {{ $name }}
release: {{ $root.Release.Name }}
{{- end -}}

{{/*
Generate Docker image repository: Public Docker Hub 'stackstorm' for FOSS version
*/}}
Expand Down
8 changes: 1 addition & 7 deletions templates/configmaps_packs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ metadata:
name: {{ .Release.Name }}-st2-pack-configs
annotations:
description: StackStorm pack configs defined in helm values, shipped in (or copied to) '/opt/stackstorm/configs/'
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
{{ toYaml .Values.st2.packs.configs | indent 2 }}
8 changes: 1 addition & 7 deletions templates/configmaps_post-start-script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ metadata:
name: {{ $.Release.Name }}-{{ . }}-post-start-script
annotations:
description: Custom postStart lifecycle event handler script for {{ . }}
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
release: {{ $.Release.Name }}
heritage: {{ $.Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
# k8s calls this script in parallel with starting {{ . }} (ie the same time as ENTRYPOINT)
# The pod will not be marked as "running" until this script completes successfully.
Expand Down
24 changes: 3 additions & 21 deletions templates/configmaps_rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ metadata:
name: {{ .Release.Name }}-st2-rbac-roles
annotations:
description: Custom StackStorm RBAC roles, shipped in '/opt/stackstorm/rbac/roles/'
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
{{- range $filename, $contents := .Values.st2.rbac.roles }}
{{/* to support removing default files, skip files with empty contents */}}
Expand All @@ -29,13 +23,7 @@ metadata:
name: {{ .Release.Name }}-st2-rbac-assignments
annotations:
description: Custom StackStorm RBAC role assignments, shipped in '/opt/stackstorm/rbac/assignments/'
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
{{- range $filename, $contents := .Values.st2.rbac.assignments }}
{{/* to support removing default files, skip files with empty contents */}}
Expand All @@ -52,13 +40,7 @@ metadata:
name: {{ .Release.Name }}-st2-rbac-mappings
annotations:
description: StackStorm RBAC LDAP groups-to-roles mapping rules, shipped in '/opt/stackstorm/rbac/mappings/'
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
{{- if .Values.st2.rbac.mappings }}
{{ toYaml .Values.st2.rbac.mappings | indent 2 }}
Expand Down
8 changes: 1 addition & 7 deletions templates/configmaps_st2-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ metadata:
name: {{ .Release.Name }}-st2-config
annotations:
description: Custom StackStorm config which will apply settings on top of default st2.conf
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
# TODO: Bundle DB/MQ login secrets in dynamic ENV-based st2.secrets.conf, leave custom user-defined settings for st2.user.conf (?)
# Docker/K8s-based st2 config file used for templating service names and common overrides on top of original st2.conf.
Expand Down
8 changes: 1 addition & 7 deletions templates/configmaps_st2-urls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ metadata:
name: {{ .Release.Name }}-st2-urls
annotations:
description: StackStorm service URLs, used across entire st2 cluster
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
ST2_AUTH_URL: http://{{ .Release.Name }}-st2auth:9100/
ST2_API_URL: http://{{ .Release.Name }}-st2api:9101/
Expand Down
8 changes: 1 addition & 7 deletions templates/configmaps_st2web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ metadata:
name: {{ .Release.Name }}-st2web-config
annotations:
description: Custom StackStorm Web config which will override defaults
labels:
app: st2
tier: backend
vendor: stackstorm
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
labels: {{- include "stackstorm-ha.labels" (list $ "st2") | nindent 4 }}
data:
# User-defined st2web config with custom settings to replace default config.js
# See https://github.com/StackStorm/st2web#connecting-to-st2-server for more info
Expand Down
Loading

0 comments on commit ff5df44

Please sign in to comment.