Search code examples
kuberneteskubernetes-helm

Include system username in helm charts in helm version 2.14.1


I am using helm version 2.14.1. I have created helm charts for an application that will be deployed by users to test their code on kubernetes cluster. I want to add labels for username values, so I can retrieve deployments by users (deployments by user labels). Is there a way to include system username in helm charts just like we do in Java with System.getProperty("user.name"). My helm template is like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "common.fullname" . }}--{{ Release.name }}
  labels:
    application: {{ include "common.name" . }}
    branch: "{{ Release.name }}"
    username: "{{ System.user.name }}"   # need to fetch the logged in user from system here
spec:
...

Is there a standard way to achieve this or is there anyway I can allow users to input there usernames from command line while using helm install or helm template commands?

EDIT: Although, the --set works for me in setting the values for my chart, I also need to set the same value in the dependencies. Something like this:

values.yaml

username: "" 

dependency1:
 username: {{ .Values.username }} 

dependency2:
 username: {{ .Values.username }}

...

Of course the above implementation doesn't work. I need to reference the set value in the dependencies as well


Solution

  • I have resolved this. Thanks for help @MichaelAlbers and @WytrzymałyWiktor. So the solution is as below.

    helm template path/to/chart --set global.username=username
    

    And then in all the templates refer to this value as {{ .Values.global.username }}. This works for any dependency chart as well.