Why is "{{.Release.namespace}}" rendered empty?

Agung Pratama picture Agung Pratama · Aug 9, 2018 · Viewed 11.5k times · Source

I understand that {{.Release.namespace}} will render the namespace where the application being installed by helm. In that case, helm template command will render it as empty string (since it doesn't know yet the release namespace).

However, what makes me surprise is helm upgrade --install command (i haven't tried other command such as helm install) also renders it empty on some cases.

Here is the example of my helm chart template:

apiVersion: v1
kind: Service
metadata:
  name: {{.Values.app.name}}-{{.Values.app.track}}-internal
  namespace: {{.Release.namespace}}
  annotations:
    testAnnotate: "{{.Release.namespace}}"
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  selector:
    app: {{.Values.app.name}}
    environment: {{.Values.app.env}}
    track: {{.Values.app.track}}
  type: ClusterIP

After invoke helm upgrade --install on that chart template (and installed it successfully), I then try to see the output of my resource

> kubectl get -o yaml svc java-maven-app-stable-internal -n data-devops
apiVersion: v1
kind: Service
metadata:
  annotations:
    testAnnotate: ""
  creationTimestamp: 2018-08-09T06:56:41Z
  name: java-maven-app-stable-internal
  namespace: data-devops
  resourceVersion: "62906341"
  selfLink: /api/v1/namespaces/data-devops/services/java-maven-app-stable-internal
  uid: 5e888e6a-9ba1-11e8-912b-42010a9400fa
spec:
  clusterIP: 10.32.76.208
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: java-maven-app
    environment: stg
    track: stable
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

As you can see, I put {{.Release.namespace}} on 2 places:

  • in metadata.namespace field
  • in metadata.annotations.testAnnotate field.

But it only renders the correct namespace on metadata.namespace field. Any idea why?

Answer

Jaakko Pallari picture Jaakko Pallari · Aug 14, 2018

The generated value .Release.Namespace is case-sensitive. The letter N in "namespace" should be capitalized.