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

Variable substitution failed: missing closing brace when using variable substitution in Kustomization #290

Closed
ilya-git opened this issue Feb 26, 2021 · 6 comments · Fixed by #291

Comments

@ilya-git
Copy link

Describe the bug

I have set up a simple variable substitution as described in the documentation from config map:

  postBuild:
    substituteFrom:
      - kind: ConfigMap
        name: env-config

Then I use it in helm release values:

values:
   secrets:
      userAssignedIdentityID: "${kubelet-identity-client-id}"

kubectl get configmap

apiVersion: v1
data:
  ...
  kubelet-identity-client-id: <a guid in here>
kind: ConfigMap

When Kustomization controller runs, I get the following error:

var substitution failed for 'my-app': variable substitution failed: missing closing brace

If I write a random name (var does not exist in config map) instead of kubelet-identity-client-id, then an empty string is written.

Expected behavior

No error or another error that describes what is the problem (the closing brace seems to be in place at least right now)

Additional context

  • Kubernetes version: 1.20.2
  • Git provider: Bitbucket
  • Container registry provider: Azure Container Registry

Below please provide the output of the following commands:

flux --version: 0.8.2
flux check

► checking prerequisites
✗ flux 0.8.2 <0.9.0 (new version is available, please upgrade)
✔ kubectl 1.20.0 >=1.18.0-0
✔ Kubernetes 1.20.2 >=1.16.0-0
► checking controllers
✔ helm-controller: healthy
► ghcr.io/fluxcd/helm-controller:v0.7.0
✔ kustomize-controller: healthy
► ghcr.io/fluxcd/kustomize-controller:v0.8.1
✔ notification-controller: healthy
► ghcr.io/fluxcd/notification-controller:v0.8.0
✔ source-controller: healthy
► ghcr.io/fluxcd/source-controller:v0.8.1
✔ all checks passed
@hiddeco
Copy link
Member

hiddeco commented Feb 26, 2021

This is likely because the variable name contains a hyphen (-), try to use underscores instead like you would in a Bourne-style shell.

@ilya-git
Copy link
Author

ilya-git commented Feb 26, 2021

Thanks a lot, I have actually just found exactly the same! It works with underscores, perhaps it's worth adding to documentation (all the limitations)? And maybe have a better error handling / validation of characters?

@ilya-git
Copy link
Author

ilya-git commented Feb 26, 2021

This is a super interesting and useful feature by the way, e.g. I use terraform to create all resources like public IP, then I create a config map and can reference the IP from config map instead of hardcoding it.

Really well though through 👍

@pmialon
Copy link

pmialon commented Sep 8, 2021

Hi,

I have a similar problem, I generate ConfigMap in my kustomization.

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
  - files:
      - application.yml=app-conf
    name: app-conf

but the file app-conf contain spring placeholders like this :

app.name=MyApp
app.description=${app.name} is a Spring Boot application

I have the same error message:
var substitution failed for 'my-app': variable substitution failed: missing closing brace

The only way I found is to entirely disable envsubst for this configmap.

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
  - files:
      - application.yml=app-conf
    name: app-conf
    options:
      annotations:
        kustomize.toolkit.fluxcd.io/substitute: disabled

@xvzf
Copy link

xvzf commented Jan 6, 2022

@pmialon did you find a solution?

@Tzrlk
Copy link

Tzrlk commented May 18, 2022

From the docs:

Note that if you want to avoid var substitutions in scripts embedded in ConfigMaps or container commands, you must use the format $var instead of ${var}. If you want to keep the curly braces you can use $${var} which will print out ${var}.

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.

5 participants