-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Support selectors for kubectl patch #121673
base: master
Are you sure you want to change the base?
Conversation
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tnozicka The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@ardaguclu @mpuckett159 gentle ping |
@@ -235,7 +240,9 @@ func (o *PatchOptions) RunPatch() error { | |||
NamespaceParam(o.namespace).DefaultNamespace(). | |||
FilenameParam(o.enforceNamespace, &o.FilenameOptions). | |||
Subresource(o.Subresource). | |||
ResourceTypeOrNameArgs(false, o.args...). | |||
ResourceTypeOrNameArgs(o.All, o.args...). |
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.
field and label selectors in patch
command sounds reasonable to me but I'm strongly reluctant to add all
in here. Because this flag already creates confusions to users in other commands and I don't think, we'd want to add more.
In addition to that all flag is also mutually exclusive with the other selectors
b.errs = append(b.errs, fmt.Errorf("setting 'all' parameter but found a non empty selector. ")) |
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.
Agreed don't want to add all because it is highly confusing to users as it does not actually mean "all."
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.
Well, it means "select all instances" so you don't have to create dummy selector when you want to select all instances of the object. Would you prefer the flag name to be different? If so which one and how'd you see the consistency with other commands and reusing the builders?
@@ -146,6 +148,9 @@ func NewCmdPatch(f cmdutil.Factory, ioStreams genericiooptions.IOStreams) *cobra | |||
cmd.Flags().BoolVar(&o.Local, "local", o.Local, "If true, patch will operate on the content of the file, not the server-side resource.") | |||
cmdutil.AddFieldManagerFlagVar(cmd, &o.fieldManager, "kubectl-patch") | |||
cmdutil.AddSubresourceFlags(cmd, &o.Subresource, "If specified, patch will operate on the subresource of the requested object.", supportedSubresources...) | |||
cmdutil.AddLabelSelectorFlagVar(cmd, &o.LabelSelector) |
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 add unit tests for these 2 flags in here
package patch |
and integration tests preferably in
Line 423 in 76ee378
kubectl patch "${kube_flags[@]}" pod pod-with-precision -p='{"metadata":{"annotations":{"patchkey": "patchvalue"}}}' |
I am hesitant to approve this. SIG-CLI generally does not prefer to add more flags to existing imperative commands as it encourages people to continue using them for use cases they are not designed for. Especially with these particular flags, because they encourage users to make sweeping changes to large amounts of objects at once, when these commands are only meant to be introductory tools, or for quick testing and proof of concept scenarios. We have been trying to curb the expansion of these flags for some time. I don't want to close this immediately to allow for some discussions. |
I have to admit I am a bit surprised to hear
I don't think it's about encouraging modifying multiple objects at once but more about operating a real clusters where there is a lot of instances of those objects and sometimes you need to make changes that aren't exposed in higher level objects or are maintenance based. Obviously, there are some commands that allow avoiding doing the patches manually, like
|
Sorry I meant to add this link to my previous comment. Please see this blog post for SIG-CLI's position regarding patch and other commands like it. https://kubernetes.io/docs/concepts/overview/working-with-objects/object-management/ As well as this presentation that some of the SIG-CLI leads and myself gave regarding this issue at the most recent KubeCon. https://youtu.be/RggqaCSdOGA?si=tjj9g_vfA9M5NNjq&t=558 I know that this is not generally what people like to hear, but unfortunately it is very common for a lot of reasons, and there isn't much we can do to prevent people from using these commands in the ways you've described above without removing the commands entirely from the code base, which is not something that project is willing to do. Thank you for providing the links and examples though, this is helpful for us to find more pain points that lead to people relying on imperative commands rather than using the preferred declarative workflow for production systems. |
Thanks for the links, now I know where the view is coming from. While I am the first person to tell people to use GitOps and prefer
While I agree that we should tell people to deploy apps using I suppose mostly you could do bulk patch with for o in $( kubectl get my-resource -o name ); do
kubectl get my-resource/"${o}" -o yaml | yq 'del(.status.conditions)' | kubectl apply --server-side -f -
done but that needs extra binary, makes a ton of extra API calls on large clusters (terribly slow) and misses extra concepts like UID preconditions. /cc @soltysh |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
PR needs rebase. Instructions 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-sigs/prow repository. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR adds 3 selector flags for
kubectl patch
that are common on other commands:--label
to select object using labels--field-selector
to select objects by fields--all
to select all objects within a namespaceWhich issue(s) this PR fixes:
Fixes kubernetes/kubectl#909
Special notes for your reviewer:
Does this PR introduce a user-facing change?
/sig cli
/priority important-longterm