helm / helm/community

Feature: Create a Template.BaseFolder function

Open
#401 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
495
Forks
210
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am interested in creating a feature request for being able to determine which folder a file is in. Helm already has pretty similar functionality to this built-in with `{{ Template.BasePath }}` which tells you the path to your file. I think that having something similar with `{{ Template.BaseFolder }}` could buy users a lot of advantages when it comes to creating reusable code. I can provide a pretty quick example below.

If my directory was formatted as follows..
```bash
Chart.yaml
values.yaml
README.md
templates/
backend/
deployment.yaml
frontend/
deployment.yaml
```

Then I could setup my one deployment like this and have 2 unique deployments

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ Template.BaseFolder }}-deployment
labels:
{{- include "chart.labels" . | indent 4 }}
app: {{ Template.BaseFolder }}
spec:
replicas: {{ .Values.frontend.replicaCount }} # even this could be templated using index and setting your values.yaml up. But that is a little overkill
selector:
matchLabels:
app: {{ Template.BaseFolder }}
template:
metadata:
labels:
{{- include "chart.labels" . | indent 8 }}
app: {{ Template.BaseFolder }}
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
....
```

Then the output of these 2 deployments would be

```
frontend-deployment
backend-deployment
```

It should look something like the following from a python perspective

`{{ Template.BasePath}}.split('/')[-2]`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.