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

Question - use a RAW values.yaml for a Helm release #445

Closed
0x53fa29jhezc opened this issue Nov 11, 2020 · 4 comments · Fixed by #446
Closed

Question - use a RAW values.yaml for a Helm release #445

0x53fa29jhezc opened this issue Nov 11, 2020 · 4 comments · Fixed by #446

Comments

@0x53fa29jhezc
Copy link

0x53fa29jhezc commented Nov 11, 2020

Hey guys,
like flux so far but I struggle a bit at the moment with integrating big value.yaml config files

For example for bitnami MongoDB Chart the production-values.yaml is very long (500 lines).
I do not want to copy paste this into the helm release yaml file

What is the best way to do that?

there is this section with

spec:
  valuesFrom:
  - kind: ConfigMap
    name: prod-env-values
    valuesKey: values-prod.yaml

BUT I do not want to create a ConfigMap for every Helm chart. In my opinion this would be a bit confusing to have the values somewhere outside the git repo

is there kustomize magic which merges the "production-values.yaml" (without changing it) into helm-release-yaml?

@stefanprodan
Copy link
Member

stefanprodan commented Nov 11, 2020

If you want to use the values-production.yaml file from inside the chart then do:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: mongodb
spec:
  chart:
    spec:
      chart: mongodb
      sourceRef:
        kind: HelmRepository
        name: bitnami
      valuesFile: "values-production.yaml"

BUT I do not want to create a ConfigMap for every Helm chart. In my opinion this would be a bit confusing to have the values somewhere outside the git repo

All Kubernetes manifests should be in the Git repository, you can place the raw production-values.yaml inside the repo and use Kustomize to generate the configmap:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- mongo-namespace.yaml
- mongo-helm-release.yaml

configMapGenerator:
- name: mongo-config
  files:
    - values.yaml=configs/production-values.yaml

Then in mongo-helm-release.yaml:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: mongodb
spec:
  chart:
    spec:
      chart: mongodb
      sourceRef:
        kind: HelmRepository
        name: bitnami
  valuesFrom:
  - kind: ConfigMap
    name: mongo-config

@0x53fa29jhezc
Copy link
Author

0x53fa29jhezc commented Nov 11, 2020

Thank you very much!

works with the additional option

generatorOptions:
  disableNameSuffixHash: true

otherwise there will be a suffix mongo-config-234234234 and the config map can not be found in the release

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- mongo-namespace.yaml
- mongo-helm-release.yaml

configMapGenerator:
- name: mongo-config
  files:
    - values.yaml=configs/production-values.yaml

generatorOptions:
  disableNameSuffixHash: true

@potto007
Copy link

potto007 commented Feb 2, 2021

I know you had this conversation a few months ago, but just wanted to add:

You don't have to use generatorOptions: disableNameSuffixHash: true - if you want to use immutable configMaps, you just need to add an extra file to the directory where the configMap is being attached to your resource(s):

create a file called kustomizeconfig.yaml with contents resembling the following:

nameReference:
- kind: ConfigMap
  version: v1
  fieldSpecs:
  - path: spec/valuesFrom/name
    kind: HelmRelease

reference: https://toolkit.fluxcd.io/guides/helmreleases/#refer-to-values-in-configmaps-generated-with-kustomize

@nlamirault
Copy link

nlamirault commented Apr 12, 2021

I try with this configuration :

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../namespace
- ./cert-manager.yaml
configMapGenerator:
  - name: cert-manager-values
    files:
      - values.yaml=cert-manager-values.yaml
configurations:
  - kustomizeconfig.yaml
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: cert-manager
  namespace: cert-manager
spec:
  chart:
    spec:
      # renovate: registryUrl=https://charts.jetstack.io/
      chart: cert-manager
      version: v1.3.0
      sourceRef:
        kind: HelmRepository
        name: jetstack
        namespace: flux-system
  interval: 5m0s
  releaseName: cert-manager
  targetNamespace: cert-manager
  valuesFrom:
    - kind: ConfigMap
      name: cert-manager-values
nameReference:
- kind: ConfigMap
  version: v1
  fieldSpecs:
  - path: spec/valuesFrom/name
    kind: HelmRelease
installCRDs: true
# extraArgs:
#   - --enable-certificate-owner-ref=true
#   - --dns01-recursive-nameservers=1.1.1.1:53
#   - --dns01-recursive-nameservers-only
prometheus:
  enabled: true
  servicemonitor:
    enabled: true
    labels:
      release: kube-prometheus-stack

Then build :

kustomize build kubernetes/base/cert-manager/cert-manager/
apiVersion: v1
kind: Namespace
metadata:
  name: cert-manager
---
apiVersion: v1
data:
  values.yaml: |

    installCRDs: true
    prometheus:
      enabled: true
      servicemonitor:
        enabled: true
        labels:
          release: kube-prometheus-stack
kind: ConfigMap
metadata:
  name: cert-manager-values-2f6c4747hh
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: cert-manager
  namespace: cert-manager
spec:
  chart:
    spec:
      chart: cert-manager
      sourceRef:
        kind: HelmRepository
        name: jetstack
        namespace: flux-system
      version: v1.3.0
  interval: 5m0s
  releaseName: cert-manager
  targetNamespace: cert-manager
  valuesFrom:
  - kind: ConfigMap
    name: cert-manager-values

With this fix :

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: cert-manager
  # namespace: cert-manager
...

It works :

kustomize build kubernetes/base/cert-manager/cert-manager/
apiVersion: v1
kind: Namespace
metadata:
  name: cert-manager
---
apiVersion: v1
data:
  values.yaml: |

    installCRDs: true
    prometheus:
      enabled: true
      servicemonitor:
        enabled: true
        labels:
          release: kube-prometheus-stack
kind: ConfigMap
metadata:
  name: cert-manager-values-2f6c4747hh
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: cert-manager
spec:
  chart:
    spec:
      chart: cert-manager
      sourceRef:
        kind: HelmRepository
        name: jetstack
        namespace: flux-system
      version: v1.3.0
  interval: 5m0s
  releaseName: cert-manager
  targetNamespace: cert-manager
  valuesFrom:
  - kind: ConfigMap
    name: cert-manager-values-2f6c4747hh

Perhaps due to : kubernetes-sigs/kustomize#1301 @stefanprodan @potto007 ?

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

Successfully merging a pull request may close this issue.

4 participants