Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## In Development
* BREAKING: Use the standardized labels recommended in the Helm docs. You can use `migrations/standardize-labels.sh` to prepare an existing cluster before running `helm update`. (#351) (by @cognifloyd)
* Switch st2 to `v3.8` as a new default stable version (#347)
* Cover the three most recent Kubernetes versions in Minikube and the single most recent in K3s. (#342) (by @mamercad)
* Update the GitHub badges. (#345) (by @mamercad)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ A helper container to switch into and run st2 CLI commands against the deployed
All resources like credentials, configs, RBAC, packs, keys and secrets are shared with this container.
```
# obtain st2client pod name
ST2CLIENT=$(kubectl get pod -l app=st2client -o jsonpath="{.items[0].metadata.name}")
ST2CLIENT=$(kubectl get pod -l app.kubernetes.io/name=st2client -o jsonpath="{.items[0].metadata.name}")

# run a single st2 client command
kubectl exec -it ${ST2CLIENT} -- st2 --version
Expand Down Expand Up @@ -320,12 +320,12 @@ This mirrors the how pack registration works. Make sure to review any upgrade no
## Tips & Tricks
Grab all logs for entire StackStorm cluster with dependent services in Helm release:
```
kubectl logs -l release=<release-name>
kubectl logs -l app.kubernetes.io/instance=<release-name>
```

Grab all logs only for stackstorm backend services, excluding st2web and DB/MQ/redis:
```
kubectl logs -l release=<release-name>,tier=backend
kubectl logs -l app.kubernetes.io/instance=<release-name>,app.kubernetes.io/component=backend
```

## Running jobs before/after install, upgrade, or rollback
Expand Down
72 changes: 72 additions & 0 deletions migrations/standardize-labels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# We switched to the standard labels recommend in Helm's "Best Practices" doc.
# https://helm.sh/docs/chart_best_practices/labels/#standard-labels
#
# This script adds those labels to all the resources in an existing release,
# so that helm upgrade will not create duplicate resources. The new label
# selectors do not match the old labels, so this script adds the new labels
# to the old resources. Thus, the new selectors will update them.

# These env vars need to be set to use this script:
# RELEASE_NAME (same as .Release.Name)
# NAMESPACE (same as .Release.Namespace)
#
# For example:
# RELEASE_NAME=st2 NAMESPACE=st2 migrations/standardize-labels.sh

RELEASE_NAME=${RELEASE_NAME:-st2}
NAMESPACE=${NAMESPACE:-default}
CHART_NAME=${CHART_NAME:-stackstorm-ha} # see Chart.yaml


function klabel_app_instance() {
kind=${1}
kubectl label "${kind}" \
-n "${NAMESPACE}" \
-l "vendor=stackstorm" \
-l "release=${RELEASE_NAME}" \
"app.kubernetes.io/instance=${RELEASE_NAME}"
}

function klabel_app_name() {
kind=${1}
app=${2}
kubectl label "${kind}" \
-n "${NAMESPACE}" \
-l "vendor=stackstorm" \
-l "release=${RELEASE_NAME}" \
-l "app=${app}" \
"app.kubernetes.io/name=${app}"
}

for kind in ConfigMap Secret Ingress Service ServiceAccount Deployment ReplicaSet Pod Job; do
klabel_app_instance ${kind}
done

klabel_app_name ConfigMap st2
klabel_app_name Secret st2
klabel_app_name Secret st2chatops

klabel_app_name Secret ${CHART_NAME} # for ServiceAccount
klabel_app_name ServiceAccount ${CHART_NAME}

klabel_app_name Ingress ingress

for app in st2actionrunner st2api st2auth st2chatops st2client st2garbagecollector st2notifier st2rulesengine st2scheduler st2stream st2timersengine st2web st2workflowengine; do
klabel_app_name Deployment ${app}
klabel_app_name ReplicaSet ${app}
klabel_app_name Pod ${app}
done

for app in st2api st2auth st2chatops st2stream st2web; do
klabel_app_name Service ${app}
done

for app in st2 st2-apply-rbac-definitions st2-register-content; do
klabel_app_name Job ${app}
klabel_app_name Pod ${app}
done

klabel_app_name ConfigMap st2tests
klabel_app_name Pod st2tests
2 changes: 1 addition & 1 deletion templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.data.ST2_AUTH_PA
username: {{ .Values.st2.username }}

4. Use st2 CLI:
export ST2CLIENT=$(kubectl get --namespace {{ .Release.Namespace }} pod -l app=st2client,release={{ .Release.Name }} -o jsonpath="{.items[0].metadata.name}")
export ST2CLIENT=$(kubectl get --namespace {{ .Release.Namespace }} pod -l app.kubernetes.io/name=st2client,app.kubernetes.io/instance={{ .Release.Name }} -o jsonpath="{.items[0].metadata.name}")
kubectl exec -it ${ST2CLIENT} --namespace {{ .Release.Namespace }} -- st2 --version

-----------------------------------------------------
Expand Down
19 changes: 11 additions & 8 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ Usage: "{{ include "stackstorm-ha.labels" (list $ "st2servicename") }}"
{{- define "stackstorm-ha.labels" -}}
{{- $root := index . 0 }}
{{- $name := index . 1 }}
{{- $valuesKey := regexReplaceAll "-.*" $name "" }}
{{- $appVersion := dig $valuesKey "image" "tag" ($root.Values.image.tag) ($root.Values|merge (dict)) }}
{{ include "stackstorm-ha.selectorLabels" . }}
{{- if list "st2web" "ingress" | has $name }}
tier: frontend
app.kubernetes.io/component: frontend
{{- else if eq $name "st2tests" }}
tier: tests
app.kubernetes.io/component: tests
{{- else }}
tier: backend
app.kubernetes.io/component: backend
{{- end }}
vendor: stackstorm
chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version }}
heritage: {{ $root.Release.Service }}
app.kubernetes.io/part-of: stackstorm
app.kubernetes.io/version: {{ tpl $appVersion $root | quote }}
helm.sh/chart: {{ $root.Chart.Name }}-{{ $root.Chart.Version }}
app.kubernetes.io/managed-by: {{ $root.Release.Service }}
{{- end -}}

{{/*
Expand All @@ -32,8 +35,8 @@ Usage: "{{ include "stackstorm-ha.selectorLabels" (list $ "st2servicename") }}"
{{- define "stackstorm-ha.selectorLabels" -}}
{{- $root := index . 0 }}
{{- $name := index . 1 }}
app: {{ $name }}
release: {{ $root.Release.Name }}
app.kubernetes.io/name: {{ $name }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
{{- end -}}

{{/*
Expand Down
Loading