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

[Question] Nested envFrom injection #4539

Closed
rafalix1337 opened this issue Mar 25, 2022 · 4 comments
Closed

[Question] Nested envFrom injection #4539

rafalix1337 opened this issue Mar 25, 2022 · 4 comments
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved.

Comments

@rafalix1337
Copy link

Hello,

I'm trying to add envs injection based on envFrom

A simplified structure looks something like that:

├── base
│   ├	─ backend
	│   ├── backend.properties
	│   ├── app1
	│   │   ├── app1_backend.properties
		├	── deployment.yaml
	│   │   ├── ingress.yaml
	│   │   ├── kustomization.yaml
	├── common.properties
	├── frontend
	│   ├── app1
    	│   ├── app1_frontend.properties
	│   │   ├── deployment.yaml
	│   │   ├── ingress.yaml
	│   │   ├── kustomization.yaml
	│   │   └── service.yaml
	│   ├── frontend.properties
	│   └── kustomization.yaml
	└── kustomization.yaml

I would like to generate properties on the main level(common), backend/frontend level, and particular app level.
So I was trying to add the following patch on main level and it works:

  - op: add
	path: /spec/template/spec/containers/0/envFrom
	value:
	- configMapRef:
		name: common-properties

and following code to nested directories(backend/frontend/particular app)

- op: add
  path: "/spec/template/spec/containers/0/envFrom/-"
  value:
    configMapRef:
      name: backend-properties

But it doesn't work with the following error:

add operation does not apply: doc is missing path: "/spec/template/spec/containers/0/envFrom/-": missing value

I have seen some examples on GitHub where that syntax was used: https://github.com/search?l=YAML&p=1&q=%2Fspec%2Ftemplate%2Fspec%2Fcontainers%2F0%2FenvFrom%2F-&type=Code (you have to be logged in to see results) And I'm not sure this stopped work on specific Kustomize version(I'm using the newest version - 4.5.3) or it never worked

I have already written some Kustomize patches and syntax with /- to resources usually worked fine to resources that already exist on the manifest.
It's possible to inject that envFrom on different levels?

@k8s-ci-robot k8s-ci-robot added the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Mar 25, 2022
@k8s-ci-robot
Copy link
Contributor

@rafalix1337: 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.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 25, 2022
@rafalix1337 rafalix1337 changed the title [Question] [Question] Nested envFrom injection Mar 25, 2022
@rafalix1337
Copy link
Author

I found a workaround to my problem, it's less comfortable than the way I was trying to but it's working :) I added my workaround solution and unsuccessful try in git repository. You can see: https://github.com/rafalix1337/kustomize-issue-71622398

Firstly, I was trying to add generating config maps and injecting envs on different levels like backend/frontend/specific app but this was causing an error. You can see code in the directory not_working_example

In the workaround, I left generating config maps on specific levels but the injecting envs I had to move to one place, in my case kustomization.yaml on the main level. You can see code in the directory working_example

@KnVerey
Copy link
Contributor

KnVerey commented Apr 13, 2022

Thanks for providing the full samples--it really helps! The problem with your not-working sample is that the /- means to append and will not work if the key in question doesn't already exist. One possible solution is to add envFrom: [] to each of your initial deployment definitions to ensure the key will always exist when you try to append. Alternatively, you can selectively change the jsonpatches to not have the - suffix when they are the first patch in the series.

If I've misunderstood, please reopen.

/kind support
/triage resolved
/close

@k8s-ci-robot k8s-ci-robot added kind/support Categorizes issue or PR as a support question. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Apr 13, 2022
@k8s-ci-robot
Copy link
Contributor

@KnVerey: Closing this issue.

In response to this:

Thanks for providing the full samples--it really helps! The problem with your not-working sample is that the /- means to append and will not work if the key in question doesn't already exist. One possible solution is to add envFrom: [] to each of your initial deployment definitions to ensure the key will always exist when you try to append. Alternatively, you can selectively change the jsonpatches to not have the - suffix when they are the first patch in the series.

If I've misunderstood, please reopen.

/kind support
/triage resolved
/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. triage/resolved Indicates an issue has been resolved or doesn't need to be resolved.
Projects
None yet
Development

No branches or pull requests

3 participants