Commit Graph

37 Commits

Author SHA1 Message Date
Arda Güçlü 3f05cfcd78 Migrate genericclioptions.IOStreams usage to genericiooptions
Kubernetes-commit: 00c30941260a27e6929aef84c7fdbc8f1508518c
2023-04-05 14:07:46 +03:00
Will Daly 14a012bb21 kubectl debug: add netadmin profile
Add the netadmin profile from KEP 1441
https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1441-kubectl-debug#debugging-profiles

Signed-off-by: Will Daly <widaly@microsoft.com>

Kubernetes-commit: f5095bf34dba15c702b4618bcd24aae6fc2f47b2
2022-12-15 09:22:52 -08:00
Arda Güçlü 6cb44356e3 kubectl debug: Use restClientGetter instead cmd.Factory
As the move towards using `restClientGetter` interface instead
gigantic `cmd.Factory`, this PR does that change.

Kubernetes-commit: f5b0d728c59fbcca571e4a21ca2f473149e72f03
2023-02-13 13:16:35 +03:00
Arda Güçlü c0da8f17bf kubectl debug: Initialize pod client and builder in complete
This PR initializes podclient and builder in complete function
instead run function.

Kubernetes-commit: d66b339868ea08ef4d3bda09fdf64abacaa3f41e
2023-02-13 13:03:50 +03:00
Arda Güçlü 2c98b95ac3 kubectl debug: Standartize add flag function
This PR standartize add flag function interface to align with
other kubectl commands.

Kubernetes-commit: 3ffdee7d2b2afb48d67828ac136f05ba9c6d8619
2023-02-13 12:36:18 +03:00
Arda Güçlü 2d1cd8a4fc (kubectl debug): Support debugging via files
Currently `kubectl debug` only supports passing names in command line.
However, users might want to pass resources in files by passing `-f` flag like
in all other kubectl commands.

This PR adds this ability.

Kubernetes-commit: e0fedec69d494cf02ac99a83733d7d92f6cc0c51
2023-02-10 10:21:15 +03:00
Shang Jian Ding 04703e5d61 Implement kubectl debug profiles: general, baseline, and restricted (#114280)
* feat(debug): add more profiles

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>

* feat(debug): implment serveral debugging profiles

Including `general`, `baseline` and `restricted`.

I plan to add more profiles afterwards, but I'd like to get early
reviews.

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>

* test: add some basic tests

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>

* chore: add some helper functions

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>

* ensure pod copies always get their probes cleared

not wanting probes to be present is something we want
for all the debug profiles; so an easy place to implement
this is at the time of pod copy generation.

* ensure debug container in pod copy is added before the profile application

The way that the container list modification was defered causes the
debug container to be added after the profile applier runs. We now
make sure to have the container list modification happen before
the profile applier runs.

* make switch over pod copy, ephemeral, or node more clear

* use helper functions

added a helper function to modify a container out of a list that
matches the provided container name.

also added a helper function that adds capabilities to container
security.

* add tests for the debug profiles

* document new debugging profiles in command line help text

* add file header to profiles_test.go

* remove URL to KEP from help text

* move probe removal to the profiles

* remove mustNewProfileApplier in tests

* remove extra whiteline from import block

* remove isPodCopy helper func

* switch baselineProfile to using the modifyEphemeralContainer helper

* rename addCap to addCapability, and don't do deep copy

* fix godoc on modifyEphemeralContainer

* export DebugOptions.Applier for extensibility

* fix unit test

* fix spelling on overriden

* remove debugStyle facilities

* inline setHostNamespace helper func

* remove modifyContainer, modifyEphemeralContainer, and remove probes

their logic have been in-lined at call sites

* remove DebugApplierFunc convenience facility

* fix baseline profile implementation

it shouldn't have SYS_PTRACE base on
https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1441-kubectl-debug#profile-baseline

* remove addCapability helper, in-lining at call sites

* address Arda's code review comments

1 use Bool instead of BoolPtr (now deprecated)
2 tweak for loop to continue when container name is not what we expect
3 use our knowledge on how the debug container is generated to simplify
  our modification to the security context
4 use our knowledge on how the pod for node debugging is generated to no
  longer explicit set pod's HostNework, HostPID and HostIPC fields to
  false

* remove tricky defer in generatePodCopyWithDebugContainer

* provide helper functions to make debug profiles more readable

* add note to remind people about updating --profile's help text when adding new profiles

* Implement helper functions with names that improve readability

* add styleUnsupported to replace debugStyle(-1)

* fix godoc on modifyContainer

* drop style prefix from debugStyle values

* put VisitContainers in podutils & use that from debug

* cite source for ContainerType and VisitContainers

* pull in AllContainers ContainerType value

* have VisitContainer take pod spec rather than pod

* in-line modifyContainer

* unexport helper funcs

* put debugStyle at top of file

* merge profile_applier.go into profile.go

* tweak dropCapabilities

* fix allowProcessTracing & add a test for it

* drop mask param from help funcs, since we can already unambiguous identify the container by name

* fix grammar in code comment

---------

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Co-authored-by: Jian Zeng <anonymousknight96@gmail.com>

Kubernetes-commit: d35da348c60a3c7505419741f2546ff8b0e38454
2023-02-09 11:18:22 -06:00
Paco Xu 360fa681c3 cleanup: EphemeralContainers feature gate related codes
Kubernetes-commit: 70e56fa71af5aa4f3d1448fcbc26e86309cd0cf3
2022-12-16 23:46:47 +08:00
Sean Sullivan d545780f6d Exports WarningPrinter field in DeleteOptions
Kubernetes-commit: 75ff830ab198348b0c727d05e54754d5f73a7286
2023-01-09 17:14:16 -08:00
Davanum Srinivas d3700ce217 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
Lee Verberne 3e07021378 Fix incorrect message when attaching to ephemeral containers
Kubernetes-commit: 8d4ec9ac9dcf45b66111075a1b67043c2885b263
2022-07-15 19:23:24 +02:00
Maciej Szulik 6707e9d96c Improve run and debug attach message upon failure
Kubernetes-commit: 43c2ae479f056f9e420062e11f3251b7095c3108
2022-06-24 09:07:44 +02:00
Jian Zeng f125772691 feat(kubectl): add debug profile applier
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>

Kubernetes-commit: fd0c15cce3d66bc2b32fc6943688425ec269d97d
2021-11-12 00:57:02 +08:00
jlsong01 ec9d0484e5 add a warning printer in cli-runtime to coordinate warning style
modified:   staging/src/k8s.io/kubectl/pkg/cmd/auth/auth.go

Kubernetes-commit: 272e245f06e425fc912b1e477e8b6763850b161e
2022-02-18 20:33:38 +08:00
Arda Güçlü 81a25f37b5 Set validate functions requiring no parameters for all commands
Validate function is used to validate command options and should not get
any additional parameter. To preserve compatibility across all
kubectl commands, this PR removes all parameters in validate functions.

Kubernetes-commit: 8fb423bfabe0d53934cc94c154c7da2dc3ce1332
2022-05-17 11:38:20 +03:00
Lee Verberne 3d7e4b3f7f Print kubectl debug messages received when starting a container (#108591)
* kubectl debug: print container messages

This provides feedback to the user, for example that the server is
unable to pull the debug container image.

* Label debug container updates as warnings

Co-authored-by: Eddie Zaneski <eddiezane@gmail.com>

Co-authored-by: Eddie Zaneski <eddiezane@gmail.com>

Kubernetes-commit: 90956e6d3e9df02d932f9954911b89a3fd1619fb
2022-03-10 02:41:45 +00:00
wawa0210 11174082b3 fix kubectl alpha debug node does not work on tainted nodes
Kubernetes-commit: 3ec63238c53ae3a7185db210e94494d850def3d4
2021-01-26 23:36:35 +08:00
Lee Verberne 7b8558da71 Add backwards compatibility for kubectl debug
The ephemeral containers API changed in 1.22. As a result, kubectl
debug (currently) cannot create ephemeral containers in clusters prior
to 1.22.

This change causes kubectl to retry the request using the old API when
it receives a specific error message from the server.

Kubernetes-commit: 06124c1d1c68ec4a30406bf585df2ec83231cb65
2021-06-28 18:19:50 +02:00
Lee Verberne 119802affe Warn user for runtime support of debug targeting
Add a warning message to `kubectl debug` when using the `--target`
option as many runtimes don't support it yet.

Kubernetes-commit: 968185e1f7c4aee739d5abe6133a690c70e87d5e
2021-04-13 15:50:26 +02:00
Lee Verberne 46887fb25e Address feedback for new /ephemeralcontainers API
* Use deep copies in `PrepareForUpdate()`
* Preserve select metadata from new pod
* Use patch to add ephemeral container `kubectl debug`
* Distinguish between pod vs /ephemeralcontainers NotFound

Kubernetes-commit: 97726a50c138557522def7f753ec8581d00f0b02
2021-04-14 18:40:42 +02:00
Lee Verberne 7fd8647b0d Switch ephemeralcontainers SR to Pod Kind
This changes the `/ephemeralcontainers` subresource of `/pods` to use
the `Pod` kind rather than `EphemeralContainers`.

When designing this API initially it seemed preferable to create a new
kind containing only the pod's ephemeral containers, similar to how
binding and scaling work.

It later became clear that this made admission control more difficult
because the controller wouldn't be presented with the entire Pod, so we
updated this to operate on the entire Pod, similar to how `/status`
works.

Kubernetes-commit: d22dc5cb72a627341f4004b5d58d275f3d8773b3
2021-04-09 13:53:13 +02:00
xiongzhongliang b0de341b90 Remove kubectl alpha debug command in 1.21
Kubernetes-commit: e650a8a38c30ff3707292c060613acdb0714b2ec
2021-01-16 20:17:22 +08:00
xiongzhongliang ceb5d08972 add -q as shorthand for --quiet
Kubernetes-commit: a7e15c7606d24f0ff11c5ddf05f3cbc6ab891e16
2020-12-31 19:18:17 +08:00
Lee Verberne 4dec993ea4 kubectl debug: allow set-image-only invocation
Kubernetes-commit: d6024ce18dd66de2ebe076afa5b33ae4fcfbee67
2020-11-05 13:40:11 +01:00
Lee Verberne 5ed93efa24 Remove alpha from kubectl debug
Kubernetes-commit: 30262e9b14e2369528fd27241adb16fae02f684d
2020-11-04 16:30:49 +01:00
Lee Verberne fdd6fda024 kubectl debug: Allow mutating image names
Kubernetes-commit: ee9f11b95f01b32dade5d8dc7329625c40ac0e63
2020-10-30 18:23:34 +01:00
Lee Verberne 6a3c6f9a42 kubectl debug: add tests for Complete,Validate
Kubernetes-commit: 3cfcf3a74fc24e6b4b3f58710fe454d1bc3644cc
2020-10-30 08:54:13 +01:00
wawa0210 c1aa9082c9 Keep the imagePullPolicy of kubectl alpha debug consistent with the default
Kubernetes-commit: 6709d4f93855d485f6a809237efbdc1951fbc30a
2020-09-19 11:46:41 +08:00
Lee Verberne 9e9322bdd6 Update the use message for kubectl debug
The command now supports type syntax similar to `kubectl get`.

Kubernetes-commit: 40904c7a7de4bcb050030eaf53dfb21c3f076ae9
2020-09-23 15:06:16 +02:00
Kiyoshi Muranaka 5457c2b27c Fix index out of range panic for kubectl alpha debug
Fix containerNameToRef func to get init containers and ephemeral containers properly.

Set EphemeralContainers in generatePodCopyWithDebugContainer func to nil which means
dropping ephemeral containers from a copy of pod so that it can be created successfully,
otherwise it is rejected by the API server.

Kubernetes-commit: bf3dfaf99942eab20fac1570ca0146d32cb93b57
2020-09-07 02:43:21 +09:00
Lee Verberne 63b6f85e5d kubectl debug: add support for debugging nodes
When called with a node target, `kubectl debug` will create a run-once
pod in the target node's namespaces.

Kubernetes-commit: 7e63cc8b9d592abbb8a659205555e67b57080837
2020-04-03 18:36:32 +02:00
Aylei c73a3aa1bf Add debug by copy support for kubectl alpha debug command
Signed-off-by: Aylei <rayingecho@gmail.com>

Update staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go

Co-Authored-By: Lee Verberne <lee@verb.is>

Apply suggestions from code review

Co-Authored-By: Lee Verberne <lee@verb.is>

Kubernetes-commit: cfece3edfe8a726fc5dc65ef89b89021316837c7
2020-04-13 01:58:36 +08:00
Davanum Srinivas 445ad1366b switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
wojtekt 5b27ac0ca2 Fix the flaky kubectl tests at scale
Kubernetes-commit: 98058a1b68da3726e1110dc8bba3838459d03b29
2020-04-23 22:05:55 +02:00
Kazuki Suda 736b43aee9 Fix missing a shorthand for container flag of kubectl alpha debug
Kubernetes-commit: fca1027dd6d69ca7c5b3dd54059c29b2c8d04762
2020-03-31 12:15:17 +09:00
Lee Verberne c401716d75 kubectl debug: support different kinds
This is a refactor ahead of adding support for supporting `kubectl debug` of nodes.

Kubernetes-commit: 8414d180feb9ddb0d4b9b80ea8e570dcacf98703
2020-04-03 14:31:18 +02:00
Lee Verberne c3d84a9e1c Add kubectl debug alpha command
This first version of `kubectl alpha debug` is an import of the existing
kubectl-debug plugin, which supports adding ephemeral containers to
running pods. This attempts to follow patterns used by other kubectl
commands such as run, exec and scale.

Kubernetes-commit: e5b655938e55e0404545ff73e9239593a27a3272
2020-01-31 15:29:31 +01:00