Skip to content

Instantly share code, notes, and snippets.

@kvudata
Created June 27, 2018 20:20
Show Gist options
  • Save kvudata/12ba57ae1e7f01799aaa7f36350a9b2e to your computer and use it in GitHub Desktop.
Save kvudata/12ba57ae1e7f01799aaa7f36350a9b2e to your computer and use it in GitHub Desktop.
Use Helm hook to add labels to a namespace before chart installation
# This hook depends on helm creating the target namespace if it doesn't exist
# before the hook is called. This is the case on Helm v2.9.1
apiVersion: batch/v1
kind: Job
metadata:
name: label-ns
namespace: kube-system
labels:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded
spec:
template:
spec:
containers:
- name: labeler
image: gcr.io/google_containers/hyperkube:v1.9.7
command:
- kubectl
- label
- ns
- {{ .Release.Namespace }}
- istio-injection=enabled
restartPolicy: Never
# use tiller service account since it should have permissions to do namespace labeling
serviceAccountName: tiller
@mconigliaro
Copy link

That tiller account doesn't exist in helm 3. I posted a complete example here: https://stackoverflow.com/a/76276158/115635

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment