kustomize-controller icon indicating copy to clipboard operation
kustomize-controller copied to clipboard

"yes" and "no" cannot be used as values in postBuild.substitute variables in kustomization

Open jeevankuduvaravindran opened this issue 1 year ago • 6 comments

Describe the bug

When postBuild.substitute variables containing value of "yes" or "no", the variable is substituted gets the value of "true" and "false" respectively throwing the below error.

expected string, got &value.valueUnstructured{Value:true}

I don't understand why does a string datatype gets parsed to a boolean value?

Steps to reproduce

  • Create a flux kustomization with a postBuild.substitute variable set to "true" or "false"
postBuild:
    substitute:
      isNecessary: "yes"
  • Create any kubernetes yaml (like helmrelease ) with the same variable provided in the yaml (simplified yaml)
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: test-helm-release
  namespace: flux-config
spec:
  chart:
    spec:
      chart: ...
      version: "1.0.0" 
  values:
    isNecessary: ${isNecessary}
  • Describing the kustomization using kubectl shows that the value of the isNecessary variable set to "yes". But the value of the isNecessary variable in helmrelease is set to true.

Expected behavior

isNecessary variable in helmrelease spec.values should be set to "yes" instead of parsing it to true

Screenshots and recordings

No response

OS / Distro

N/A

Flux version

v2.1.0

Flux check

► checking prerequisites ✗ flux 2.1.0 <2.2.3 (new version is available, please upgrade) ✔ Kubernetes 1.27.3 >=1.25.0-0 ► checking controllers ✔ fluxconfig-agent: deployment ready ► mcr.microsoft.com/azurek8sflux/fluxconfig-agent:1.8.2 ► mcr.microsoft.com/azurek8sflux/fluent-bit-mdm:1.8.2 ✔ fluxconfig-controller: deployment ready ► mcr.microsoft.com/azurek8sflux/fluxconfig-controller:1.8.2 ► mcr.microsoft.com/azurek8sflux/fluent-bit-mdm:1.8.2 ✔ helm-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/helm-controller:v0.36.2 ✔ image-automation-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/image-automation-controller:v0.36.1 ✔ image-reflector-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/image-reflector-controller:v0.30.0 ✔ kustomize-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/kustomize-controller:v1.1.1 ✔ notification-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/notification-controller:v1.1.0 ✔ source-controller: deployment ready ► mcr.microsoft.com/oss/fluxcd/source-controller:v1.1.2 ► checking crds ✔ alerts.notification.toolkit.fluxcd.io/v1beta2 ✔ buckets.source.toolkit.fluxcd.io/v1beta2 ✔ fluxconfigs.clusterconfig.azure.com/v1alpha1 ✔ gitrepositories.source.toolkit.fluxcd.io/v1 ✔ helmcharts.source.toolkit.fluxcd.io/v1beta2 ✔ helmreleases.helm.toolkit.fluxcd.io/v2beta1 ✔ helmrepositories.source.toolkit.fluxcd.io/v1beta2 ✔ imagepolicies.image.toolkit.fluxcd.io/v1beta2 ✔ imagerepositories.image.toolkit.fluxcd.io/v1beta2 ✔ imageupdateautomations.image.toolkit.fluxcd.io/v1beta1 ✔ kustomizations.kustomize.toolkit.fluxcd.io/v1 ✔ ocirepositories.source.toolkit.fluxcd.io/v1beta2 ✔ providers.notification.toolkit.fluxcd.io/v1beta2 ✔ receivers.notification.toolkit.fluxcd.io/v1 ✔ 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

jeevankuduvaravindran avatar Feb 13 '24 18:02 jeevankuduvaravindran

I am experiencing the same problem too. I hope it gets resolved quickly.

ganeshg2491 avatar Feb 14 '24 09:02 ganeshg2491

yes/no in YAML are boolean aliases, Flux substitutions only work with string so this can't be fixed.

stefanprodan avatar Feb 14 '24 09:02 stefanprodan

You can work around this (and other things like numbers, etc.) by wrapping it in quotes which are also substituted, e.g.

spec:
  postBuild:
    substitute:
      isNecessary: "yes"
      q: '"'

And then where you use it:

spec:
  values:
    isNecessary: ${q}${isNecessary}${q}

Note that it has to be a quote symbol from a variable. Using literal quotes instead will not work, because they will be removed on kustomize build stage (before variables are expanded).

artem-nefedov avatar Feb 16 '24 19:02 artem-nefedov

@artem-nefedov this is such a great hack. I would love to have this in the Kustomization API docs.

stefanprodan avatar Feb 16 '24 21:02 stefanprodan

@artem-nefedov Thanks for that. This workaround should help us.

jeevankuduvaravindran avatar Feb 19 '24 09:02 jeevankuduvaravindran

Let's keep this opened until we have this procedure in Flux docs.

stefanprodan avatar Feb 19 '24 09:02 stefanprodan