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

double quote disappear #3485

Closed
hansanghoon opened this issue Jan 20, 2021 · 11 comments
Closed

double quote disappear #3485

hansanghoon opened this issue Jan 20, 2021 · 11 comments
Labels
area/api issues for api module area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@hansanghoon
Copy link

Describe the bug

vars variable is surrounded by double quotes ""
after build, double quotes disappear.

Files that can reproduce the issue

kustomization.yaml loads redis port using vars

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- redis.yaml
- quote.yaml
- web.yaml
vars:
- name: QUOTE_APP_URL
  objref:
    apiVersion: v1
    kind: Service
    name: quote-app-service
  fieldref:
    fieldpath: metadata.name
- name: QUOTE_APP_PORT
  objref:
    apiVersion: v1
    kind: Service
    name: quote-app-service
  fieldref:
    fieldpath: spec.ports.0.port
- name: REDIS_HOST
  objref:
    apiVersion: v1
    kind: Service
    name: redis
  fieldref:
    fieldpath: metadata.name
- name: REDIS_PORT
  objref:
    apiVersion: v1
    kind: Service
    name: redis
  fieldref:
    fieldpath: spec.ports.0.port

quote-patch.yaml patches deployment. put redis port into environment variable. REDIS_PORT var inside double quote.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: quote-app
spec:
  template:
    spec:
      containers:
      - name: app-container
        env:
        - name: REDIS_HOST
          value: $(REDIS_HOST)
        - name: REDIS_PORT
          value: "$(REDIS_PORT)"

Expected output

kustomize version 3.9.1 build output

...
    spec:
      containers:
      - env:
        - name: REDIS_HOST
          value: redis-dev
        - name: REDIS_PORT
          value: "6379"

Actual output

kustomize version 3.9.2 build output

...
    spec:
      containers:
      - env:
        - name: REDIS_HOST
          value: redis-dev
        - name: REDIS_PORT
          value: 6379
$ kustomize build --load_restrictor none overlay/dev/v1 | kubectl apply -f -

namespace/quote-dev unchanged
configmap/web-config-dev-9g62k48669 unchanged
service/quote-app-service-dev unchanged
service/redis-dev unchanged
service/web-dev unchanged
deployment.apps/redis-dev configured
deployment.apps/web-dev unchanged
Error from server (BadRequest): error when creating "STDIN": Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found 6, error found in #10 byte of ...|,"value":6379}],"ima|..., bigger context ...|value":"redis-dev"},{"name":"REDIS_PORT","value":6379}],"image":"callicoder/go-redis-app:1.0.0","ima|...

Kustomize version

3.9.1 works as expected
3.9.2 removes double quotes surrounding var

Platform

macOS, kustomize cli upgraded via homebrew. regression test performed by download release from this github

Additional context

@Shell32-Natsu Shell32-Natsu added area/api issues for api module area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 20, 2021
@epcim
Copy link
Contributor

epcim commented Jan 23, 2021

The same issue here

apiVersion: builtin
kind: HelmChartInflationGenerator
metadata:
  name: hass

chartName: home-assistant
chartRepoUrl: https://k8s-at-home.com/charts/
chartRelease: stable
chartVersion: 2.5.1

releaseName: hass
releaseNamespace: home

valuesLocal:
  ingress:
    enabled: true
    annotations:
      traefik.ingress.kubernetes.io/router.priority: "10"
      kubernetes.io/tls-acme: "true"

end up as

kubernetes.io/tls-acme: true
traefik.ingress.kubernetes.io/router.priority: 10

^^ both, on kubectl apply throws

error: unable to decode "ing.yaml": resource.metadataOnlyObject.ObjectMeta: v1.ObjectMeta.Annotations: ReadString: expects " or n, but found t, error found in #10 byte of ...|ls-acme":true,"traef|..., bigger context ...|:"traefik-cert-manager","kubernetes.io/tls-acme":true,"traefik.ingress.kubernetes.io/router.entrypoi|...

Some discussin here:

Required

  • backward compatibility
  • if desired, change behaviour on major version upgrade with option like \" to preserve "

@Shell32-Natsu
Copy link
Contributor

@monopole Is this the same with other quotes issues?

@tehmoon
Copy link

tehmoon commented Jan 25, 2021

Same here, had to downgrade because it was messing up with annotations. I did not find any workaround though.

@aariacarterweir
Copy link

Same here... bit weird

@hansanghoon
Copy link
Author

4.0.1 still has problem. I think this should have more priority as this will hinder people from upgrading.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 18, 2021
@hansanghoon
Copy link
Author

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- redis.yaml
- deployment.yaml
vars:
- name: REDIS_HOST
  objref:
    apiVersion: v1
    kind: Service
    name: redis
  fieldref:
    fieldpath: metadata.name
- name: REDIS_PORT
  objref:
    apiVersion: v1
    kind: Service
    name: redis
  fieldref:
    fieldpath: spec.ports.0.port

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: quote-app
spec:
  template:
    spec:
      containers:
      - name: app-container
        env:
        - name: REDIS_HOST
          value: $(REDIS_HOST)
        - name: REDIS_PORT
          value: "$(REDIS_PORT)"

redis.yaml

apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 6379

and build output

apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 6379
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: quote-app
spec:
  template:
    spec:
      containers:
      - env:
        - name: REDIS_HOST
          value: redis
        - name: REDIS_PORT
          value: 80
        name: app-container

problem still persist as we have integer value for environment variable. tested on windows 10 with kustomize cli(installed via chocolatey choco install kustomize).

\ kustomize version
{Version:kustomize/v4.1.2 GitCommit:a5914abad89e0b18129eaf1acc784f9fe7d21439 BuildDate:2021-04-15T20:38:06Z GoOs:windows GoArch:amd64}

@hansanghoon
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 18, 2021
@eddiezane
Copy link
Member

We are planning to deprecate vars and this will not be fixed.

Please see #2052.

/close

@k8s-ci-robot
Copy link
Contributor

@eddiezane: Closing this issue.

In response to this:

We are planning to deprecate vars and this will not be fixed.

Please see #2052.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@air3ijai
Copy link

air3ijai commented May 16, 2022

Same issue with port number and password which contains special characters. Solutions proposed in #3412 doesn't work in our case.

DB_PORT: ${DB_PORT} --> Error
DB_PORT: "${DB_PORT}" --> Error
DB_PORT: '${DB_PORT}' --> Error
DB_PORT: "'${DB_PORT}'" --> '443' --> Can't be interpreted correctly by container shell

Workaround we use:

kustomize

kubectl kustomize k8s/overlays/test | envsubst

secrets.yml

apiVersion: v1
kind: Secret
metadata:
  name: db
type: Opaque
stringData:
  DB_PORT: |
    ${DB_PORT}

result

apiVersion: v1
kind: Secret
metadata:
  name: db
  namespace: db
stringData:
  DB_PORT: |
    443

container

echo $DB_PORT
443

Another option to be considered is to use sed to replace the variable with the value and it should be quoted in the yml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api issues for api module area/kyaml issues for kyaml kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

9 participants