fluxcd / flux2

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

HelmRelease valuesFrom kind secret with comma separated values (cannot end with ,) #2625

Open tomasfabian opened 2 years ago

tomasfabian commented 2 years ago

Describe the bug

Hi, in case that the secret value contains a comma character we receive the following error message:

 helm-controller  unable to merge value from key 'brokers' in Secret 'default/kafka' into target path 'kafka.Brokers': key "net:9092" has no value (cannot end with ,)    

Steps to reproduce

Secret with a comma separated list of brokers:

Name:         kafka
Namespace:    default
Labels:       managed-by=kafkaConnection-operator
Annotations:  <none> 
Type:  Opaque
Data
====
brokers:  107 bytes

brokers value:

kafka01.net:9092,kafka02.net:9092,kafka03.net:9092

Example HelmRelease yaml:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: my-app
  namespace: default
spec:
  interval: 1m
  chart:
    spec:
      chart: my-chart
      version: "0.1.0-alpha"
      sourceRef:
        kind: HelmRepository
        name: harbor-chart-repo
        namespace: default
  valuesFrom:
    - kind: Secret
      targetPath: kafka.brokers
      name: kafka
      valuesKey: brokers
      optional: false

Expected behavior

The secret value shouldn't be "parsed" with an error outcome.

Screenshots and recordings

No response

OS / Distro

N/A

Flux version

v0.17.1

Flux check

N/A

Git provider

No response

Container Registry provider

No response

Additional context

No response

Code of Conduct

hiddeco commented 2 years ago

You need to escape the comma, as otherwise the parsing logic (which equals --set as helm itself has when targetPath is used) will trip over the value. See also: https://helm.sh/docs/intro/using_helm/#the-format-and-limitations-of---set

The correct value would be: kafka01.net:9092\,kafka02.net:9092\,kafka03.net:9092

tomasfabian commented 2 years ago

Hi thanks for you reply @hiddeco.

The creation of the secret is not under our control. We are using the following kafka-topic-operator.

Thx

wuhuizuo commented 2 years ago

You need to escape the comma, as otherwise the parsing logic (which equals --set as helm itself has when targetPath is used) will trip over the value. See also: https://helm.sh/docs/intro/using_helm/#the-format-and-limitations-of---set

The correct value would be: kafka01.net:9092\,kafka02.net:9092\,kafka03.net:9092

may be it can be solved when flux2 using --set-file instead of --set.

I occured the issue also, but my content is a json.

nourspace commented 2 years ago

I was also hoping that valuesFrom could allow using a ConfigMap whose content is a regular values.yaml with comments etc.

MartinEmrich commented 3 months ago

Have the same issue, but I am trying to set a JSON document (which is also full of commas). After escaping them, I get the same error now at dots (.), which also seem to have special semantics with --set.

I basically want to insert a full JSON object subtree at the targetPath. I know that with the current approach, I will put the rendered string representation of the JSON document at that position, which might, depending on the implementation of the helm chart, not work either.

The JSON is provided externally, so would prefer to not modify it.

The current workaround:

Apparently removing targetPath does the trick, now the document is taken as is without that comma/dot-parsing, and merged into the values tree.