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

Env variable not added to multiple deployments with /- in the path if there is no other env variable defined before #5650

Open
e9169 opened this issue Apr 8, 2024 · 5 comments
Assignees
Labels
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

@e9169
Copy link

e9169 commented Apr 8, 2024

What happened?

When trying to add env variables to several Kubernetes Deployments at the same time, it failed because one of the Deployments manifest didn't have environment variables defined before. Using '/-' don't add it if there are no envs defined in advance, instead it throws the error:

doc is missing path: "/spec/template/spec/containers/0/env/-": missing value

What did you expect to happen?

I expect that, if an item, an env variable in this case, doesn't exist and I end the path with '/-', that it's actually appended at the end. At the end of none, should be the first and only env variable in there.

How can we reproduce it (as minimally and precisely as possible)?

#kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: argocd
resources:
- github.com/argoproj-labs/argocd-autopilot/manifests/base?ref=v0.4.17

patches:
- patch: |-
    - op: add
      path: /spec/template/spec/containers/0/env/-
      value:
        name: test
        value: test

  target:
    group: apps
    version: v1
    kind: Deployment

Expected output

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: argocd
  name: argocd-deployment
spec:
  template:
    spec:
      containers:
      - name: nginx
         env:
         - name: test
            value: test

Actual output

doc is missing path: "/spec/template/spec/containers/0/env/-": missing value

Kustomize version

v5.0.4-0.20230601165947-6ce0bf390ce3

Operating system

MacOS

@e9169 e9169 added the kind/bug Categorizes issue or PR as related to a bug. label Apr 8, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 8, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@varshaprasad96
Copy link
Member

Just to clarify the issue, this happens because the env key is not defined in your deployment. Which basically means that the deployment yaml looks like:

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: argocd
  name: argocd-deployment
spec:
  template:
    spec:
      containers:
      - name: nginx

I don't see an issue in us appending the env variable directly if none is specified. But it needs investigation on whether it can be implemented in Kustomize.

@varshaprasad96
Copy link
Member

/assign @garomonegro

@k8s-ci-robot
Copy link
Contributor

@varshaprasad96: GitHub didn't allow me to assign the following users: garomonegro.

Note that only kubernetes-sigs members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @garomonegro

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.

@garomonegro
Copy link

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

4 participants