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

crictl exec: allow running single command in multiple containers #1603

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Sep 20, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This patch adds the following filter flags to crictl exec:

--image value                    Exec command for all containers matching this container image filter
--label value [ --label value ]  Exec command for all containers matching this key=value label filter
--last value, -n value           Exec command for all last n containers, set to 0 for unlimited (default: 0)
--latest, -l                     Exec command for the most recently created container (default: false)
--name value                     Exec command for all containers matching this name filter regular expression pattern
--pod value, -p value            Exec command for all containers matching this pod ID filter
--state value                    Exec command for all containers matching this container state filter

If none of the above filters are set, then crictl will assume that the first provided argument is the container ID. If one of them is set, then crictl will filter and execute for all containers:

> sudo ./build/bin/linux/amd64/crictl exec --name pod ps aux
8f92b841d898828833d7dc55245e5df91c517cb0fce8a61f5def7cb9e432530c:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   2472  1344 ?        Ss   07:09   0:00 /bin/sleep 6000 6000
root          67  0.0  0.0   5536  2700 ?        Rs   07:38   0:00 ps aux
39f78a7b1835b8363a519424031ddbb370b743afad46cc401eeb73717c84e57d:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   2472  1500 ?        Ss   07:08   0:00 /bin/sleep 6000 6000
root         122  0.0  0.0   5536  2732 ?        Rs   07:38   0:00 ps aux

The container ID is printed when a filter command has been used to ensure existing backwards compatibility.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?

crictl exec: allow running single command in multiple containers by using one of the new `--image`, `--label`, `--last`, `--latest`, `--name`, `--pod` or `--state` flags.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 20, 2024
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 20, 2024
This patch adds the following filter flags to `crictl exec`:

```
--image value                    Exec command for all containers matching this container image filter
--label value [ --label value ]  Exec command for all containers matching this key=value label filter
--last value, -n value           Exec command for all last n containers, set to 0 for unlimited (default: 0)
--latest, -l                     Exec command for the most recently created container (default: false)
--name value                     Exec command for all containers matching this name filter regular expression pattern
--pod value, -p value            Exec command for all containers matching this pod ID filter
--state value                    Exec command for all containers matching this container state filter
```

If none of the above filters are set, then crictl will assume that the
first provided argument is the container ID. If one of them is set, then
crictl will filter and execute for all containers:

```
> sudo ./build/bin/linux/amd64/crictl exec --name pod ps aux
8f92b841d898828833d7dc55245e5df91c517cb0fce8a61f5def7cb9e432530c:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   2472  1344 ?        Ss   07:09   0:00 /bin/sleep 6000 6000
root          67  0.0  0.0   5536  2700 ?        Rs   07:38   0:00 ps aux
39f78a7b1835b8363a519424031ddbb370b743afad46cc401eeb73717c84e57d:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   2472  1500 ?        Ss   07:08   0:00 /bin/sleep 6000 6000
root         122  0.0  0.0   5536  2732 ?        Rs   07:38   0:00 ps aux
```

The container ID is printed when a filter command has been used to
ensure existing backwards compatibility.

Signed-off-by: Sascha Grunert <[email protected]>
@saschagrunert
Copy link
Member Author

@kubernetes-sigs/cri-tools-maintainers PTAL

@kwilczynski
Copy link
Member

What use case does this solve?

@saschagrunert
Copy link
Member Author

What use case does this solve?

Having a set of containers where the same command should be executed in, mostly for debugging and testing purposes.

@kwilczynski
Copy link
Member

What use case does this solve?

Having a set of containers where the same command should be executed in, mostly for debugging and testing purposes.

An idea:

Can we add an option, a command-line switch perhaps, to run whatever command has been given in parallel. This would take care of the use case, replacing the need to have either the xargs or parallel binaries available. Something that I often rely on while testing or troubleshooting something.

An ability to retry and ignore errors would also be nice.

@saschagrunert
Copy link
Member Author

An idea:

Can we add an option, a command-line switch perhaps, to run whatever command has been given in parallel. This would take care of the use case, replacing the need to have either the xargs or parallel binaries available. Something that I often rely on while testing or troubleshooting something.

An ability to retry and ignore errors would also be nice.

Sounds like great ideas! Would that work as follow-up on that PR?

@kwilczynski
Copy link
Member

An idea:
Can we add an option, a command-line switch perhaps, to run whatever command has been given in parallel. This would take care of the use case, replacing the need to have either the xargs or parallel binaries available. Something that I often rely on while testing or troubleshooting something.
An ability to retry and ignore errors would also be nice.

Sounds like great ideas! Would that work as follow-up on that PR?

Yeah, sure.

@kwilczynski
Copy link
Member

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kwilczynski, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 9413e9d into kubernetes-sigs:master Oct 8, 2024
34 checks passed
@saschagrunert saschagrunert deleted the exec branch October 8, 2024 09:16
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 8, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 9, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 9, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 9, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 9, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 10, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
saschagrunert added a commit to saschagrunert/cri-tools that referenced this pull request Oct 10, 2024
…lags

The flags can be used to further manipulate on the exec behavior.
Follow-up on:
kubernetes-sigs#1603 (comment)

Signed-off-by: Sascha Grunert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants