[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm: apply templating to Ingress host and environment variable values #17073

Merged

Conversation

dylanpiergies
Copy link
Contributor

Description

Pass select Helm values through the tpl template function so they are rendered as template code.

Motivation and Context

Passing certain values through the tpl function can help improve reusability by enabling to use parameters such as the Helm release name when rendering manifests. For example, we can create a configuration including values such as:

environment:
  MINIO_BROWSER_REDIRECT_URL: "http://{{ printf \"%s-console\" (include \"minio.fullname\" .) }}.example.com"
ingress:
  hosts:
  - "{{ include \"minio.fullname\" . }}.example.com"
consoleIngress:
  hosts:
  - "{{ printf \"%s-console\" (include \"minio.fullname\" .) }}.example.com"

How to test this PR?

Install the chart with values of the form of those suggested above. Verify that Ingresses are created with names based on the minio.fullname template.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Fixes a regression (If yes, please add commit-id or PR # here)
  • Unit tests added/updated
  • Internal documentation updated
  • Create a documentation update request here

Pass some additional values through the `tpl` function:
* Environment variable values
* `ingress.hosts` elements
* `consoleIngress.hosts` elements
@dylanpiergies dylanpiergies changed the title Pass select Helm chart values to the tpl function helm: Pass select chart values to the tpl function Apr 27, 2023
@dylanpiergies dylanpiergies changed the title helm: Pass select chart values to the tpl function helm-chart: Pass select chart values to the tpl function Apr 27, 2023
@harshavardhana
Copy link
Member

@dnskr would you mind taking a look on these changes?

@dnskr
Copy link
Contributor
dnskr commented Apr 30, 2023

The changes look good and useful to me.

Minor comments:

  • I would prefer more accurate PR name and the description to make review process easier.
    For example, helm: apply templating to Ingress host and environment variable values
  • There is a convenient way to test the changes without installing the chart with helm template command.

Testing

helm template test helm/minio --set ingress.enabled=true --set ingress.hosts[0]="example-\{\{ include \"minio.fullname\" \. \}\}.com" --show-only templates/ingress.yaml
---
# Source: minio/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-minio
  ...
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: test-minio
                port:
                  number: 9000
      host: "example-test-minio.com"
helm template test helm/minio --set consoleIngress.enabled=true --set consoleIngress.hosts[0]="example-\{\{ randNumeric 5 \}\}.com" --show-only templates/console-ingress.yaml
---
# Source: minio/templates/console-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-minio-console
  ...
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: test-minio-console
                port:
                  number: 9001
      host: "example-86120.com"
helm template test helm/minio --set mode=distributed --set environment.CHECK="\{\{ randAlpha 5 \}\}" --show-only templates/statefulset.yaml
---
# Source: minio/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: test-minio
  ...
spec:
  replicas: 16
  template:
    metadata:
      name: test-minio
      ...
    spec:
      ...
      containers:
        - name: minio
          env:
            - name: CHECK
              value: "obIzk"
...
helm template test helm/minio --set mode=standalone --set environment.CHECK="\{\{ randAlpha 5 \}\}" --show-only templates/deployment.yaml
---
# Source: minio/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-minio
  ...
spec:
  replicas: 1
  template:
    metadata:
      name: test-minio
      ...
    spec:
      ...
      containers:
        - name: minio
          env:
            - name: CHECK
              value: "cyfRl"
...

@dylanpiergies dylanpiergies changed the title helm-chart: Pass select chart values to the tpl function helm: apply templating to Ingress host and environment variable values May 2, 2023
@harshavardhana harshavardhana merged commit 8203cb9 into minio:master May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants