Skip to content

Instantly share code, notes, and snippets.

@shubhamsre
Forked from kvudata/label-ns.yaml
Created June 18, 2020 21:58
Show Gist options
  • Save shubhamsre/4f5a97e5858c933750a76196a0fc342e to your computer and use it in GitHub Desktop.
Save shubhamsre/4f5a97e5858c933750a76196a0fc342e 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment