-
Notifications
You must be signed in to change notification settings - Fork 41.9k
kubectl debug: Add --keep-* flag to control the removal of probes, labels, annotations, and initContainers from copy pod #123149
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
kubectl debug: Add --keep-* flag to control the removal of probes, labels, annotations, and initContainers from copy pod #123149
Conversation
|
/sig cli |
|
|
||
| switch style { | ||
| case podCopy: | ||
| removeLabelsAndProbes(pod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that but I think we need to manage this with on/off flag as we did in https://github.com/openshift/oc/blob/cf7b09cd29f1c0f56b2c6cd8193092c57c7730ff/pkg/cli/debug/debug.go#L252-L255 and default would be to removal of probes. WDYT? @verb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment and I agree that.
oc debug seems to be implemented to be able to control the removal of probes, labels, annotations and initContainers.
On the other hands in kubectl debug, labels will be removed in all profiles and probes will be removed in some profiles(general and baseline).
So I'm wondering which should be targeted for removal control(only probes, probes and labels or all?).
How do you think?
Current implementations of kubectl debug are as below.
probes
removeLabelsAndProbes() which remove probes already has been implemented and used in some profiles(general and baseline).
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/debug/profiles.go
Lines 245 to 254 in 91ee300
| // removeLabelsAndProbes removes labels from the pod and remove probes | |
| // from all containers of the pod. | |
| func removeLabelsAndProbes(p *corev1.Pod) { | |
| p.Labels = nil | |
| for i := range p.Spec.Containers { | |
| p.Spec.Containers[i].LivenessProbe = nil | |
| p.Spec.Containers[i].ReadinessProbe = nil | |
| p.Spec.Containers[i].StartupProbe = nil | |
| } | |
| } |
labels
removeLabelsAndProbes() also implemented to remove labels, but copy pod labels will be removed when copy pod is created before removeLabelsAndProbes() will be called.
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go
Lines 580 to 589 in 91ee300
| // generatePodCopyWithDebugContainer takes a Pod and returns a copy and the debug container name of that copy | |
| func (o *DebugOptions) generatePodCopyWithDebugContainer(pod *corev1.Pod) (*corev1.Pod, string, error) { | |
| copied := &corev1.Pod{ | |
| ObjectMeta: metav1.ObjectMeta{ | |
| Name: o.CopyTo, | |
| Namespace: pod.Namespace, | |
| Annotations: pod.Annotations, | |
| }, | |
| Spec: *pod.Spec.DeepCopy(), | |
| } |
annotations and initContainers
There seems to be not implemented the logic to remove annotations and initContainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I've added --keep-* flags to be able to control the removal of probes, labels, annotations and initContainers like oc debug.
446744b to
d252ebc
Compare
d252ebc to
0dd901d
Compare
30858a2 to
4b3544e
Compare
|
/remove-kind bug |
|
/retest |
|
PTAL? |
|
@ardaguclu |
ardaguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spending time and effort on this PR. That would be great, if we can add some integration tests cases also in here https://github.com/kubernetes/kubernetes/blob/master/test/cmd/debug.sh
| useHostNamespaces(pod) | ||
|
|
||
| case podCopy: | ||
| p.keeps.removeLabels(pod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a behavioral change for legacyProfile because we were not removing as default and now we are.
I think, we can leave it as is and even keep flags don't change it. As it is a legacy profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean copy pod applied legacyProfile should keep annotations, probes and initContainers and doesn’t keep labels(it is not kept now as mentioned here) regardless of --keep-* flags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is true. Because it is a legacy profile anyway and we shouldn't change the current behavior, unless it is fully broken, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
So should we add additional flags descriptions like "it does not work in legacyProfile" related that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's don't add it for now. I think, adding more text just for a a legacy profile seems to be unnecessary. Isn't the recommended path is using the other profiles other than legacy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can say that if you want to manage these resources, please use the other recommended paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's don't add it for now.
Ok, I've got it.
Isn't the recommended path is using the other profiles other than legacy?
By the way, how many users recognize it recommended to use other profiles than legacy profile and the existence of debugging profile?
- The official document doesn't seem to mention debugging profiles.(It's mentioned only in KEP now as I know.)
- "kubectl debug --help" doesn't seem to show any recommended paths regarding profiles and show default profile is legacy.
So IMO, I think many users don't know the existence of debugging profile and recommendation.
Shouldn't we add any description about debugging profile somewhere?
In addition, it is said that in KEP:
Default Profile and Automation Selection
In order to provide a seamless experience and encourage use of PodSecurity, the "auto" profile will automatically choose a profile that's compatible with the current security profile by examining the pod-security.kubernetes.io/enforce annotation on the namespace and selecting the most permissive of "general", "baseline", and "restricted" that the controller will allow.This will become the default behavior, but in order to maintain backwards compatibility the "legacy" profile will be the default profile until the 1.25 release. When --profile is not specified kubectl debug will print a warning about the upcoming change in behavior.
Though auto profile is WIP(#120687) now, shouldn't we print any warning or recommendation about profile as a first step?
These are outside the scope of this PR, but I was a little curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that legacy name is self explanatory but I see your comments and it all makes sense. We should reconsider what is the path for legacy profile.
|
@ardaguclu
I've added test pod manifest( |
|
/retest |
ardaguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests look great. Thanks.
|
@ardaguclu |
ardaguclu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last comment and after that I think we are good to go
|
|
||
| if o.Applier == nil { | ||
| applier, err := NewProfileApplier(o.Profile) | ||
| kflags := keepFlags{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that keepFlags is better naming and sorry, if I wasn't clear enough: Could you please export this, it's functions and it's fields?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please export this, it's functions and it's fields?.
It's ok.
Could you tell me the reason?
As you said here, they are not used by anywhere so I thought we need not to export...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please export this, it's functions and it's fields?.
It's ok. Could you tell me the reason? As you said here, they are not used by anywhere so I thought we need not to export...
Basically, in case some other tools depend on kubectl debug functionality, they would be able to customize the behavior. Otherwise, keep flag functionality will be black box. We can also may want to intentionally unexport them. However, they would fully be relying on the flags and it may better to export them in my opinion. Hope that it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another reason would be ProfileApplier is exported function and can be customizable. On the other hand, it only gets an unexported type which drastically hurts the usability of ProfileApplier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your explanation.
I've understood.
301dc1b to
e56ce82
Compare
|
@ardaguclu |
| return fmt.Errorf("the %s profile doesn't support objects of type %T", ProfileLegacy, target) | ||
| // KeepFlags holds the flag set that determine which fields to keep in the copy pod. | ||
| type KeepFlags struct { | ||
| labels bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly fields to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I overlooked it...
I've fixed.
e56ce82 to
b63fa13
Compare
|
Great, thanks! |
|
LGTM label has been added. Git tree hash: 0a826e71ead3de72941f4581360fe22684c131a5
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ardaguclu, mochizuki875 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 |
|
@ardaguclu |
|
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
What type of PR is this?
/kind feature
/cleanup
What this PR does / why we need it:
When using
--copy-tooption with some debugging profile(legacy, restricted, netadmin sysadmin), the probe configuration remains in the copy pod .Therefore, if the probe condition is not met by debugging operation on the copy pod, the main container will be restarted.
This may prevent debugging.
So in this PR, I've added flags(
--keep-liveness,--keep-readiness,--keep-startup) to control the removal of probes from copy pod.In addition, I've added
--keep-labels,--keep-annotationsand--keep-init-containersto control the removal of labels, annotations and initContainers too.Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: