这是indexloc提供的服务,不要输入任何密码
Skip to content

Feature: Create a Template.BaseFolder function #401

@sei-areuter

Description

@sei-areuter

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..

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

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions