Implement kubectl debug profiles: general, baseline, and restricted#114280
Conversation
|
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Sun Dec 4 21:52:06 UTC 2022. |
|
Hi @sding3. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
/ok-to-test |
There was a problem hiding this comment.
This looks like it changed his behavior
There was a problem hiding this comment.
This is intentional to ensure that debug container in pod copy is added before the profile application. The way that the container list modification was defered caused 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.
I had placed this change in its own git commit and supplied a git commit message to explain the reason behind the change: 0545b223eb5edd447f7a143a8e57bb2500d8ae64
There was a problem hiding this comment.
Same above. Is this change related to new debug profiles?
There was a problem hiding this comment.
Yes, we need this to ensure the generated debug container is added the the container list prior to the o.Applier.Apply occurs on line 692 below or otherwise the generated debug container isn't available to o.Applier.
There was a problem hiding this comment.
I'm worried this has gotten a little too tricky. Can we just append immediately?
c, ok := containerByName[name]
if !ok {
...
copied.Spec.Containers = append(copied.Spec.Containers, corev1.Container{...})
c = &copied.Spec.Containers[len(copied.Spec.Containers)-1]
}
Yep, that will be my top priority after this PR. |
|
LGTM label has been added. DetailsGit tree hash: 9a99e9c99044a43a3c014af9e6c418ebb5883f57 |
|
LGTM label has been added. DetailsGit tree hash: 1445acc71d5102439c526f69227af3f47097bdc6 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aimuz, ardaguclu, sding3, verb The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Is this feature available now or when can we expect this to come? |
…ubernetes#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>
What type of PR is this?
/kind feature
What this PR does / why we need it:
Implements "general", "baseline", and "restricted" debugging profiles for kubectl debug as specified in KEP-1441.
Which issue(s) this PR fixes:
xref kubernetes/kubectl#1108
Special notes for your reviewer:
I had picked up where @knight42 had left off in #110526
Does this PR introduce a user-facing change?