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

feature request: Patch "all containers" or regex #3

Closed
flbla opened this issue Mar 5, 2021 · 5 comments · Fixed by #4
Closed

feature request: Patch "all containers" or regex #3

flbla opened this issue Mar 5, 2021 · 5 comments · Fixed by #4

Comments

@flbla
Copy link

flbla commented Mar 5, 2021

I would like to be able to patch all containers without knowing there name (or with a regex)

my use case is to be able to copy data from a init container to all containers in pod without knowing name of containers:

webhook:
  patch: |
    spec:
      initContainers:
      - name: ca
        image: alpine
        command: ["sh", "-c", "cp -r /etc/ssl/certs /volume"]
        volumeMounts:
        - mountPath: /volume
          name: cacerts
      containers:
      - name: *
        volumeMounts:
        - mountPath: /etc/ssl
          name: cacerts
      volumes:
      - name: cacerts
        emptyDir: {}

I tried with a "*" it doesn't work

@bohlenc
Copy link
Owner

bohlenc commented Mar 5, 2021

Hi @flbla
Interesting use case! Have you tried omitting "- name" completely, like so:

- volumeMounts:
  - mountPath: /etc/ssl
    name: cacerts

I will have a shot at it too. I'll come back to you later!

@flbla
Copy link
Author

flbla commented Mar 5, 2021

Hi @bohlenc
yes, it failed with an error:

time="2021-03-05T13:17:55Z" level=error msg="could not create json patch: could not apply strategic merge patch: map: map[volumeMounts:[map[mountPath:/etc/ssl name:cacerts]]] does not contain declared merge key: name"

webhook:
  patch: |
    spec:
      initContainers:
      - name: ca
        image: alpine
        command: ["sh", "-c", "cp -r /etc/ssl/certs /volume"]
        volumeMounts:
        - mountPath: /volume
          name: cacerts
      containers:
      - volumeMounts:
        - mountPath: /etc/ssl
          name: cacerts
      volumes:
      - name: cacerts
        emptyDir: {}

thanks! :)

@bohlenc
Copy link
Owner

bohlenc commented Mar 5, 2021

Yeah, forgot that "name" is the merge key for containers.

I think about adding something alone these lines: if a field that is declared as "merge key" is specified as "*" in a patch -> patch all available elements. That would cover your specific use-case but would also be broadly applicable to many other scenarios, e.g. adding to volumes etc.

@bohlenc
Copy link
Owner

bohlenc commented Mar 7, 2021

I just merged code (see #4) to support this use-case. Let me know if that works for you.

@flbla
Copy link
Author

flbla commented Mar 8, 2021

it works perfectly :)
thank you @bohlenc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants