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

Support for postRenderer in HelmRelease #831

Open
jkotiuk opened this issue Feb 5, 2025 · 2 comments
Open

Support for postRenderer in HelmRelease #831

jkotiuk opened this issue Feb 5, 2025 · 2 comments

Comments

@jkotiuk
Copy link

jkotiuk commented Feb 5, 2025

Hey,

Would it be possible to add support for HelmRelease PostRenderer?

The helm output would have to be piped through Kustomize to add those patches from postRenders section. Implementation could be based on a solution like this https://alysivji.github.io/helm-post-rendering-hook.html.

@allenporter
Copy link
Owner

Seems possible! So if I understand right, this would make a synthetic kustomization to pipe into kustomize? Is the logic for image documented? it seems like it needs to know all the various resource types, if i understand right, which we do have.

The doc is good, though if you wanted to accelerate with some sample tests cases of:
(1) a HelmRelease and
(2) a list of actual yaml files and kustomize commands to run it
(3) expected output
that could help make it easier for me to implement it.

@jkotiuk
Copy link
Author

jkotiuk commented Feb 6, 2025

What I was thinking was to extend "helm template" command with --post-render ./kustomize argument

args: list[str] = [

Extract patches from HelmRelease i.e patches=$(yq eval '[.spec.postRenderers[].kustomize.patches[]]' helmrelease.yaml)

Add kustomize that will be passed to --post-render

#!/bin/bash
cat <&0 > all.yaml

echo """apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - all.yaml
""" > kustomization.yaml

if [ -n "$patches" ]; then
  echo "patches:" >> kustomization.yaml
  echo "$patches" >> kustomization.yaml
fi

kustomize build .

then helm template test -n myns oci://registry-1.docker.io/bitnamicharts/nginx --post-renderer ./kustomize will render it

Sample HelmRelease I used for testing

apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: nginx
spec:
  postRenderers:
  - kustomize:
      patches:
      - patch: |-
          - op: add
            path: /spec/template/spec/containers/0/env/-
            value:
              name: MYENV_NAME
              valye: myenv_value
        target:
          kind: Deployment
      - patch: |-
          - op: replace
            path: /spec/template/spec/containers/0/startupProbe
            value:
              failureThreshold: 10
              initialDelaySeconds: 30
        target:
          kind: Deployment
  - kustomize:
      patches:
      - patch: |-
          - op: replace
            path: /spec/revisionHistoryLimit
            value: 2
        target:
          kind: Deployment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants