flux2 icon indicating copy to clipboard operation
flux2 copied to clipboard

Substitute issue

Open guidoffm opened this issue 2 years ago • 4 comments

Describe the bug

My kustomization contains

  postBuild:
    substitute:
      appConfig: '{"foo": "bar"}'

The content of appConfig is a string, not an object.

HelmRelease describe shows:

adapter.configuration.appConfig: Invalid type. Expected: string, given: object

Steps to reproduce

n/a

Expected behavior

Treat a string as string although it contains a JSON object

Screenshots and recordings

No response

OS / Distro

N/A

Flux version

v0.24.1

Flux check

► checking prerequisites ✔ Kubernetes 1.21.5-eks-bc4871b >=1.19.0-0 ► checking controllers ✔ helm-controller: deployment ready ► docker-hub-remote.bahnhub.tech.rz.db.de/fluxcd/helm-controller:v0.14.1 ✔ kustomize-controller: deployment ready ► docker-hub-remote.bahnhub.tech.rz.db.de/fluxcd/kustomize-controller:v0.18.2 ✔ notification-controller: deployment ready ► docker-hub-remote.bahnhub.tech.rz.db.de/fluxcd/notification-controller:v0.19.0 ✔ source-controller: deployment ready ► docker-hub-remote.bahnhub.tech.rz.db.de/fluxcd/source-controller:v0.19.2 ✔ all checks passed

Git provider

No response

Container Registry provider

No response

Additional context

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

guidoffm avatar Jan 12 '22 11:01 guidoffm

Found also out that line feeds are also eliminated from the substitue value. This prevents the usage of this feature for PEM encoded material.

guidoffm avatar Jan 20 '22 17:01 guidoffm

It looks like the parser interprets the string as a JSON Object, I'm not sure if that should be considered a bug, but I'm not sure what utility that behavior has for Flux either... can you try escaping the internal double quotes and enclosing your string in double quotes? I'm not sure this will matter, but I honestly don't know what caused the parser to consider it as a JSON object either, (whether it was the single quotes or just the fact that it is shaped like a json object)

kingdonb avatar Jan 26 '22 13:01 kingdonb

You can avoid all of these issues by base64 encoding strings with linebreaks or other special properties, and then decoding them at the point of usage (not sure if that helps)

kingdonb avatar Jan 26 '22 13:01 kingdonb

String substitution is generally not considered to be a one-size-fits-all tool, and is not intended to be used in places where it should preserve whitespace.

If you need to store complex multiline scalar or string values inside of your YAML, you will generally want to store it as a file (rather than inline, use a configmap or secret) and the file should be shaped like a patch, so that it can be used with patches or one of the kustomization.yaml directives related to patching. That path is much more resilient towards issues such as whitespace and string encodings.

kingdonb avatar Jan 27 '22 20:01 kingdonb