Reputation: 792
Bit of a helm novice here, in short I want to reference the current Kubernetes context within my helm chart template. Is this possible? Example:
if the upgrade was run via:
/var/jenkins_home/helm291 upgrade -i --kube-context Dev
And the template contained a deployment.yaml with the following:
...
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
env:
{{- if contains "Dev" .Release.Kube_Context}}
Is there some variable I am missing that can check the Kube Context (aka replace Release.Kube_Context)? Am I approaching this the wrong way (specifying environment configuration)?
Upvotes: 0
Views: 2477
Reputation: 1382
There is no way of doing it and it's also a bad practice to do it in the templates. Templates should be generic - you modify environment specific things in values.yaml files. You can use the --kube-context flag instead if you are running it from Jenkins
Upvotes: 2
Reputation: 1016
You can export the context values you need and then execute helm, so they will be available as environmental vars.
For example, if you need the token access:
export TOKEN=$(kubectl config view -o jsonpath='{.users[?(@.name == "dev-user")].user.auth-provider.config.id-token}'); /var/jenkins_home/helm291 upgrade -i --kube-context Dev
Upvotes: 2