fluxcd / flux2

Open and extensible continuous delivery solution for Kubernetes. Powered by GitOps Toolkit.
https://fluxcd.io
Apache License 2.0
6.43k stars 595 forks source link

flux build helmrelease #2808

Open akamac opened 2 years ago

akamac commented 2 years ago

It would be great if flux cli could render kubernetes manifests from HelmRelease locally, so it is possible to run static analysis checks against generated files before committing them into repo.

MrMarkW commented 1 year ago

Does anyone know of a way of generating the output of a Flux HelmRelease using other tools or a multi-step process?

vvbogdanov87 commented 1 year ago

In addition to flux build helmrelease, it would be nice to have flux diff helmrelease. While the former is handy during the local development stage, the latter could be used in CI/CD to generate PR diff.

vvbogdanov87 commented 1 year ago

@MrMarkW If It is not too late, here is the process:

  1. Build Flux Kustomization:

    flux build kustomization <kustomization_name> --path dev > out/kustomization_out.yaml

    In my case kustomization_out.yaml contains 2 YAML manifests HelmRepository and HelmRelease.

  2. Take Helm repository URL and name from HelmRelease and add the Helm repo:

    helm repo add <helm_repo_name> <helm_repo_url>
  3. Take the values section from HelmRelease and add it to values.yaml file. After that you will be able to render the chart locally:

    helm template <name> <helm_repo_name>/<helm_chart_name> -f out/values.yaml > out/helm_out.yaml
  4. If you have postRenderers section in HelmRelease, you can create kustomization.yaml file similar to this one:

    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    resources:
    - helm_out.yaml
    patchesStrategicMerge:
    - patch_1.yaml
    - patch_2.yaml
    - patch_3.yaml

    After that move patches from the postRenderers section to the patch files and render the final result:

    kustomize build out

    These steps can be scripted. But I don't see why Flux couldn't do the same. Because it is what it already does.

raffis commented 1 year ago

I just created https://github.com/DoodleScheduling/flux-build and came across this issue now, this seems exactly what you are looking for.

cwrau commented 1 year ago

Would be great to have this functionality in the official flux cli, for "simple" HelmRelease I've built https://aur.archlinux.org/packages/helmrelease-tools which is quite simple and works surprisingly well 👍

wibed commented 1 year ago

selfish bump

stefanprodan commented 1 year ago

We haven't forgot about this, to enable this feature in the CLI we first have to rewrite helm-controller. This rewrite is tracked in the roadmap under Helm GA. Hopefully we'll have it ready by end of Q3 then we can work on flux build/diff hr.

rbcb-bedag commented 6 months ago

any news on this ? For now: @cwrau how would your tool "helmrelease-tools" work in the described steps by @vvbogdanov87 ? thx

cwrau commented 6 months ago

any news on this ? For now: @cwrau how would your tool "helmrelease-tools" work in the described steps by @vvbogdanov87 ? thx

Maybe I should write a README or usage note 😅

But you can use hr helmrelease.yaml to render it, the other tools, like hrDiff should explain themselves 😁 You can also pipe into it There is tab completion And you can do hr hr.yaml $localHelmFolder to use a local version of the chart

wernerwws commented 5 months ago

It is also possible to use process substitution <(cmd), which treats the output of a command as a file to filter out the .spec.values from the HelmRelease to use it in helm template:

helm template <releasename> <helmrepo>/<helmchart> --values <(yq .spec.values < release.yaml) > manifests.yaml

pkit commented 1 month ago

It's not clear how to even debug all the spurious StatefulSet errors without it. Essentially making flux unusable for StatefulSet deploys (from HelmRelease).