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

ConfigMapGenerator drops quotes from quoted fields #3412

Closed
thomb89 opened this issue Dec 30, 2020 · 10 comments · Fixed by #3460
Closed

ConfigMapGenerator drops quotes from quoted fields #3412

thomb89 opened this issue Dec 30, 2020 · 10 comments · Fixed by #3460
Assignees
Labels
area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@thomb89
Copy link

thomb89 commented Dec 30, 2020

the problem occured today, so only version 3.9.1 should be affected.

When a ConfigMap in merged with the configMapGenerator the output will result in invalid values for the data field.
The surrounding quotation marks are stripped away (which converts some strings to int64), or in the case of an empty string it is converted to null

setting the flag --enable_kyaml=false fixed the issue

Files that can reproduce the issue

Example:

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - configmap.yaml

configMapGenerator:
  - name: test
    behavior: merge
    literals:
      - 'SOMETHING=""'
      - 'SMTP_PORT="993"'

resources.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  SOMETHING: 'not relevant'
  SMTP_PORT: '587'
  MYSQL_PORT: '3306'

Expected output

apiVersion: v1
data:
  MYSQL_PORT: "3306"
  SMTP_PORT: "993"
  SOMETHING: ""
kind: ConfigMap
metadata:
  name: test

Actual output

apiVersion: v1
data:
  MYSQL_PORT: 3306
  SMTP_PORT: 993
  SOMETHING: null
kind: ConfigMap
metadata:
  name: test

Kustomize version: kustomize/v3.9.1

Platform

  • macos
  • ubuntu 20.04 with the snap package
@monopole monopole changed the title ConfigMapGenerator with behavior: merge will convert strings into invalid values ConfigMapGenerator drops quotes from quoted fields Dec 30, 2020
@monopole
Copy link
Contributor

Thanks. If setting the flag is a problem, use https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv3.8.9 instead which defaults the flag to false.

Changing SOMETHING: "" to null is certainly a problem.

See also:

https://github.com/kubernetes-sigs/kustomize/blob/master/api/krusty/configmaps_test.go#L13

https://github.com/kubernetes-sigs/kustomize/blob/master/api/krusty/configmaps_test.go#L63

Need to check a round trip of a configmap

@eigood
Copy link

eigood commented Dec 31, 2020

Changing "3306" to 3306 is also a problem, because that's a number, and when you then send the CM to the environment, it'll complain?

@ephesused
Copy link
Contributor

Another test case, this time for booleans:

kustomization.yaml

configMapGenerator:
  - name: test-map
    literals:
      - INITIAL=true
  - name: test-map
    behavior: merge
    literals:
      - MERGED=false

Results:

[root@fc4d153db0d5 project_root]# build/kustomize-execs/release-v3.9.1/kustomize --enable_kyaml=false build testdata/kust-generator-merge/
apiVersion: v1
data:
  INITIAL: "true"
  MERGED: "false"
kind: ConfigMap
metadata:
  name: test-map-2k29mchd54
[root@fc4d153db0d5 project_root]# build/kustomize-execs/release-v3.9.1/kustomize build testdata/kust-generator-merge/
apiVersion: v1
data:
  INITIAL: true
  MERGED: false
kind: ConfigMap
metadata:
  name: test-map-h98ttf6fdk
[root@fc4d153db0d5 project_root]#

@Shell32-Natsu Shell32-Natsu added area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jan 5, 2021
@babygoat
Copy link

babygoat commented Jan 6, 2021

This issue also occurs when configMapGenerator constructs configmap from .properties file as suggested in the documentation. Only the merge operation will incur the issue but replace will not.

Files to reproduce

base/kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

configMapGenerator:
  - name: test-configmap
    behavior: "create"
    envs:
    - base.properties

base/base.properties

VAR1=100

replace-overlay/kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../base/

configMapGenerator:
  - name: test-configmap
    behavior: "replace"
    envs:
    - replace.properties

replace-overlay/replace.properties

VAR2=100

merge-overlay/kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../base/

configMapGenerator:
  - name: test-configmap
    behavior: "merge"
    envs:
    - merge.properties

merge-overlay/merge.properties

VAR2=100

kustomize@3.8.9 gives

> kustomize build replace-overlay/
apiVersion: v1
data:
  VAR2: "100"
kind: ConfigMap
metadata:
  name: test-configmap-cg9m2dk2f8

> kustomize build merge-overlay/
apiVersion: v1
data:
  VAR1: "100"
  VAR2: "100"
kind: ConfigMap
metadata:
  name: test-configmap-gfmbdmd4b

kustomize@3.9.1 gives

> kustomize build replace-overlay/
apiVersion: v1
data:
  VAR2: "100"
kind: ConfigMap
metadata:
  name: test-configmap-cg9m2dk2f8

> kustomize build merge-overlay/     # issue occurs
apiVersion: v1
data:
  VAR1: 100
  VAR2: 100
kind: ConfigMap
metadata:
  name: test-configmap-mt5bhhcf7g

@snuggie12
Copy link

I have a similar quoting issue trying to use jmespath but it's on 3.8.4 and 3.9.1 with or without the kyaml option.

kustomization.yaml:

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

configMapGenerator:
  - name: grafana-extra-env
    literals:
      - GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH=contains(groups[*], 'infra@foo.com') && 'Admin' || 'Viewer'

kustomize 3.8.4, 3.9.1 with kyaml enabled or disabled (NOTE the final single quote is missing)

apiVersion: v1
data:
  GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH: contains(groups[*], 'infra@foo.com') && 'Admin' || 'Viewer
kind: ConfigMap
metadata:
  name: grafana-extra-env-gdm7dbb4d6

@monopole
Copy link
Contributor

I'll fix this today

@t3mi
Copy link

t3mi commented Mar 3, 2021

@monopole Please reopen as the issue still exists. Reproduction could be grabbed from comment.

@myhau
Copy link

myhau commented Jun 7, 2021

I can confirm that this is still an issue for us in 4.1.3.

@nickjj
Copy link

nickjj commented Dec 22, 2021

I'm also seeing this with 4.4.1.

If you have a regular config map and don't use the generators you can have HEY: "'some value'" and if you inject that config map into a container using envFrom and configMapRef you will end up with a value of HEY="some value" in your container. This is the expected behavior.

If you use Kustomize and the config map generator with the same set up you end up with HEY=some value which causes issues. It happens when loading the value from a literal.

Edit:

For anyone reading this in the future, there is a good workaround for having a basic set up. Instead of using literals you can do:

configMapGenerator:
- name: "yay"
  env: ".env"

Then your .env can be:

SOMETHING=nice
WITH_QUOTES="yep this works"

This will generate the same result of what you would get without using Kustomize and hand rolled your own config map using the style of variables at the start of this reply.

@snukone
Copy link

snukone commented Aug 9, 2023

This is still an issue - commented details in #4845

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.