Skip to main content

Working with Built-in Objects

1. Accessing Release Object (.Release.Name)

Property Value Description
.Release.Name string Name of the Helm release
.Release.Namespace string Kubernetes namespace where the release is installed
.Release.Revision integer Revision number of the release (1, 2, 3...)
.Release.IsInstall boolean True if this is an install operation
.Release.IsUpgrade boolean True if this is an upgrade operation
.Release.IsRollback boolean True if this is a rollback operation
.Release.Time time Timestamp of the release operation

Example: Using .Release.Name in a Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  releaseName: {{ .Release.Name }}
Note: The .Release.Name is particularly useful for generating unique resource names that are tied to the release name, ensuring no naming conflicts in multi-release environments.

2. Using Chart Object (.Chart.Name)

Property Value Description
.Chart.Name {{ .Chart.Name }} Chart name as defined in Chart.yaml

Example: Accessing Chart Name in Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Chart.Name }}-config
data:
  chartName: {{ .Chart.Name }}

3. Accessing Files Object (.Files.Get)

The .Files object in Helm provides access to files within a chart or from external sources. The .Files.Get method allows you to read the contents of a file as a string.

Method Description Example
.Files.Get Reads the content of a file as a string. .Files.Get "templates/config.yaml"

Example: Reading a Config File

{{ .Files.Get "templates/config.yaml" }}
Note: The path is relative to the root of the chart.
Warning: Be cautious when using .Files.Get with large files as it loads the entire content into memory.

4. Using Capabilities Object (.Capabilities.KubeVersion)

Property Value Description
.Capabilities.KubeVersion {Major: "1", Minor: "28", GitVersion: "v1.28.0", GitCommit: "e40d35967f3b1282c31a91409d5b6a3947f82e5c", GitTreeState: "clean", BuildDate: "2023-09-14T15:06:00Z", GoVersion: "go1.21.1", Compiler: "gc", Platform: "linux/amd64"} Provides detailed version information of the Kubernetes cluster where the chart is being deployed

Example: Accessing KubeVersion in a Template

{{- if semverCompare "1.28" .Capabilities.KubeVersion.Version -}}
Kubernetes version is at least 1.28
{{- end -}}
Note: The .Capabilities.KubeVersion object provides access to the Kubernetes version information, which can be used for conditional logic in templates.

5. Working with Template Object (.Template.Name)

Property Description Example
.Template.Name Provides the name of the current template being processed. {{ .Template.Name }}

Example: Using .Template.Name in a Template

{{- range .Files.Lines }}
{{- if eq .Template.Name "my-template.yaml" }}
  {{ . }}
{{- end }}
{{- end }}
Note: The .Template.Name property is useful for conditional logic within templates, allowing you to apply different behaviors based on the template's name.

6. Accessing Release Service (.Release.Service)

Property Description Example
.Release.Service Represents the Kubernetes service associated with the release .Release.Service

Example: Using .Release.Service in a Template

{{- if .Release.Service }}
Service Name: {{ .Release.Service.Name }}
Service Namespace: {{ .Release.Service.Namespace }}
{{- end }}
Note: The .Release.Service object provides access to the Kubernetes service created during the release process, allowing templates to reference and utilize service details.

7. Getting Release Namespace (.Release.Namespace)

Property Description Example
.Release.Namespace Namespace where the release is installed default

Example: Accessing Release Namespace

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
  namespace: {{ .Release.Namespace }}
spec:
  containers:
  - name: example-container
    image: nginx
Note: The .Release.Namespace value is automatically set during chart installation and reflects the namespace specified in the helm install command or the default namespace if none is provided.

8. Checking Release IsUpgrade (.Release.IsUpgrade)

Property Value Description
.Release.IsUpgrade false or true Boolean flag indicating if the release is an upgrade or a fresh install

Example: Using .Release.IsUpgrade in a Template

{{- if .Release.IsUpgrade }}
<h3>Upgrading Release</h3>
{{- else }}
<h3>Installing New Release</h3>
{{- end }}
Note: This property is available in the .Release object context and can be used to conditionally render templates based on whether the release is a fresh install or an upgrade.

9. Checking Release IsInstall (.Release.IsInstall)

Property Value Description
.Release.IsInstall false / true Boolean flag indicating if the current operation is an install (as opposed to an upgrade).
Set to true during initial installation.

Example: Using .Release.IsInstall in a Template

{{- if .Release.IsInstall }}
&#x09;# This block runs only on install
&#x09;apiVersion: v1
&#x09;kind: ConfigMap
&#x09;metadata:
&#x09;&#x09;name: {{ include "myapp.fullname" . }}-install-config
&#x09;data:
&#x09;&#x09;message: "Welcome to the fresh installation!"
{{- end }}

10. Using Chart Version (.Chart.Version)

Property Value Description
.Chart.Version 1.2.3 Current version of the Helm chart as defined in Chart.yaml

Example: Accessing Chart Version in Template

{{ .Chart.Version }}
Note: The .Chart.Version field is read-only and reflects the version specified in the chart's Chart.yaml file.

11. Accessing Capabilities APIVersions (.Capabilities.APIVersions)

The .Capabilities.APIVersions field in Helm charts provides access to the Kubernetes API versions available in the cluster. This is useful for writing conditional logic based on the supported API versions.

Field Description Example Value
.Capabilities.APIVersions A set of all API versions supported by the Kubernetes cluster ["v1", "apps/v1", "batch/v1"]

Example: Checking API Version Support

{{- if (has "batch/v1" .Capabilities.APIVersions) }}
apiVersion: batch/v1
kind: Job
metadata:
  name: example-job
spec:
  template:
    spec:
      containers:
      - name: job-container
        image: busybox
      restartPolicy: Never
{{- else }}
apiVersion: batch/v1beta1
kind: Job
metadata:
  name: example-job
spec:
  template:
    spec:
      containers:
      - name: job-container
        image: busybox
      restartPolicy: Never
{{- end }}

Was this article helpful?