Introduce new flag "--include-uninitialized" to kubectl - #50497
Conversation
|
Hi @dixudx. 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 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. I understand the commands that are listed here. |
4698d59 to
9cda6b1
Compare
| NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces). | ||
| FilenameParam(enforceNamespace, options). | ||
| SelectorParam(selector). | ||
| IncludeUninitializedParam(includeUninitialized). |
There was a problem hiding this comment.
I think the proposal #49035 (comment) intends to disable --include-uninitialized for batch commands. For example:
kubectl describe pods/foo: must include uninitializedkubectl describe pods: must NOT include uninitialized because it lists pods.
There was a problem hiding this comment.
@ahmetb As @caesarxuchao commented in #49035
Both should includes uninitialized objects. --include-uninitialized doesn't affect them at all.
So I keep it unchanged.
There was a problem hiding this comment.
If user explicitly set --include-uninitialized=false when kubectl describe pods, then we should skip uninitialized pods.
| Example: getExample, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| includeUninitialized := cmdutil.GetFlagBool(cmd, "include-uninitialized") | ||
| fmt.Printf("L122 %+v\n", includeUninitialized) |
| return err | ||
| } | ||
|
|
||
| includeUninitialized := cmdutil.GetFlagBool(cmd, "include-uninitialized") |
There was a problem hiding this comment.
See my comment at #49035 (comment) I think annotate works with individual resources (and doesn't work in batch mode) so it should not have this flag.
| return err | ||
| } | ||
|
|
||
| includeUninitialized := cmdutil.GetFlagBool(cmd, "include-uninitialized") |
There was a problem hiding this comment.
See my comment at #49035 (comment) I think label works with individual resources (and doesn't work in batch mode) so it should not have this flag.
| return err | ||
| } | ||
|
|
||
| includeUninitialized := cmdutil.GetFlagBool(cmd, "include-uninitialized") |
There was a problem hiding this comment.
See my comment at #49035 (comment) I think set works with individual resources (and doesn't work in batch mode) so it should not have this flag.
ditto for other set_*.go changes.
|
|
||
| export bool | ||
|
|
||
| includeUninitialized bool |
There was a problem hiding this comment.
I think you can group this next to selectAll above.
| Timeout: FlagInfo{prefix + FlagTimeout, "", "0", "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests."}, | ||
| CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"}, | ||
| Timeout: FlagInfo{prefix + FlagTimeout, "", "0", "The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests."}, | ||
| IncludeUninitialized: FlagInfo{prefix + FlagIncludeUninitialized, "", "false", "If true, will include the objects which have a non-empty initializer list"}, |
There was a problem hiding this comment.
If true, will include the objects which have a non-empty initializer list
I think this captures the implementation detail, and not necessarily user-friendly.
Also:
willword doesn't match the rest of the flags documentationobjectshould beobject(s)- sentence should be completed with a period (e.g. see kubectl get --help)
How about:
If true, include the object(s) that have not been realized yet. Such object(s) have a non-empty initializer list.
There was a problem hiding this comment.
Also question:
I see the default value is false. Does this mean kubectl get pods --include-uninitialized still means includeUnintialized=false? Should the user explicitly set =true or does this work like --all-namespaces already with this code?
There was a problem hiding this comment.
Does this mean
kubectl get pods --include-uninitializedstill meansincludeUnintialized=false?
No, they are totally different. kubectl get pods --include-uninitialized means includeUnintialized is set to True.
kubectl get pods --include-uninitialized is identical to kubectl get pods --include-uninitialized=true.
does this work like -
-all-namespacesalready with this code
Yes, you're right. This works like other cobra-based CLIs, including our kubectl commands, like you mentioned --all-namespaces.
9cda6b1 to
b948b85
Compare
|
Updated. PTAL. |
|
I'll take a look today. |
| // unless explicitly set --include-uninitialized=false | ||
| includeUninitialized = true | ||
| } | ||
| if o.selector != "" { |
There was a problem hiding this comment.
When both specified, does o.selector overwrite o.all?
There was a problem hiding this comment.
@caesarxuchao Yes, this is current implementation.
But we have to discuss on such combinations. I think o.all is the dominant one. When other flags combine with o.all, includeUninitialized should be set to true.
ping @ahmetb @smarterclayton @pwittrock, PTAL.
There was a problem hiding this comment.
I think it's strange if kubectl annotate pod -l foo=bar returns different results from kubectl annotate pod -l foo=bar --all. I think the current implementation is good.
| p.backOff.Sleep(backOffPeriod) | ||
| } | ||
| current, getErr = p.helper.Get(namespace, name, false) | ||
| current, getErr = p.helper.Get(namespace, name, false, false) |
There was a problem hiding this comment.
If name is specified, we should always return the object to the user, no matter if it's initialized. We shouldn't change Get().
| NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces). | ||
| FilenameParam(enforceNamespace, options). | ||
| SelectorParam(selector). | ||
| IncludeUninitializedParam(includeUninitialized). |
There was a problem hiding this comment.
If user explicitly set --include-uninitialized=false when kubectl describe pods, then we should skip uninitialized pods.
| selector := cmdutil.GetFlagString(cmd, "selector") | ||
| allNamespaces := cmdutil.GetFlagBool(cmd, "all-namespaces") | ||
| showKind := cmdutil.GetFlagBool(cmd, "show-kind") | ||
| showAll := cmdutil.GetFlagBool(cmd, "show-all") |
There was a problem hiding this comment.
I just noticed --show-all exists in many other commands. I don't know if it's alright we only special case kubectl get <resource> --show-all.
On the other hand, kubectl get is quite special, it doesn't accept --all.
It seems we can't update the help text of --show-all for only kubectl get.
@mengqiy @pwittrock do you know if --show-all is supposed to only affect pods? The helper text reads "When printing, show all resources (default hide terminated pods.)".
There was a problem hiding this comment.
Discussed with @pwittrock, let's don't specialize --show-all for kubectl get. That is, kubectl get pods --show-all doesn't include uninitialized objects. Users have to use kubectl get pods --include-uninitialized=true.
The root problem is that kubectl get doesn't have a --all flag, while many other kubectl commands have. We need to unify the flags, but that's another PR.
There was a problem hiding this comment.
@caesarxuchao What about selector? Seems we have not taken selector into consideration.
For selector, we should make it consistent with kubectl label. That is "Does not include the uninitialized objects by default, unless user explicitly set --include-uninitialized=true". Any comments?
| } | ||
|
|
||
| func (m *Helper) Get(namespace, name string, export bool) (runtime.Object, error) { | ||
| func (m *Helper) Get(namespace, name string, export, includeUninitialized bool) (runtime.Object, error) { |
There was a problem hiding this comment.
Let's leave this function as is. I don't see any use case to hide an uninitialized object if user specifically asks for it.
| Namespace: namespace, | ||
| Name: name, | ||
| Export: export, | ||
| IncludeUninitialized: includeUninitialized, |
There was a problem hiding this comment.
Same here. If name is specified, we always show user the object.
| Context clientcmdapi.Context | ||
| CurrentContext string | ||
| Timeout string | ||
| IncludeUninitialized bool |
There was a problem hiding this comment.
The config here is not specific for kubectl, so we shouldn't change it. Probably you should add it in helpers.go like other flags.
| } | ||
|
|
||
| var includeUninitialized bool | ||
| if o.all { |
There was a problem hiding this comment.
We need to update the flag comment of --all.
b948b85 to
562f099
Compare
562f099 to
4c1c366
Compare
| // unless explicitly set --include-uninitialized=false | ||
| includeUninitialized = true | ||
| } | ||
| if o.Selector != "" { |
There was a problem hiding this comment.
is Selector != "" when I do kubectl set pods/foo ...? Trying to understand what this clause is for.
There was a problem hiding this comment.
I think so, "foo" will be a name, not a selector in this case.
|
@dixudx @caesarxuchao I will review it today. |
4c1c366 to
a4f0b47
Compare
| NamespaceParam(cmdNamespace).DefaultNamespace(). | ||
| FilenameParam(enforceNamespace, &options.FilenameOptions). | ||
| SelectorParam(options.Selector). | ||
| IncludeUninitializedParam(includeUninitialized). |
There was a problem hiding this comment.
This is not a param if you're doing parsing yourself. It would just be IncludeUninitialized.
| return err | ||
| } | ||
|
|
||
| var includeUninitialized bool |
There was a problem hiding this comment.
This is a lot of duplicated code that is effectively the same. It needs to be unified - copying and pasting this code into many places (with some differences) is a maintenance problem.
93feafc to
eab8c1d
Compare
|
Add another testcase for @caesarxuchao @mengqiy @pwittrock PTAL. Thanks. |
eab8c1d to
d80ff0f
Compare
|
@dixudx consider adding spaces after the commas in the release note. |
| kube::log::status "Testing --include-uninitialized" | ||
|
|
||
| ### Create a deployment | ||
| kubectl create --request-timeout=1 -f hack/testdata/initializer-deployments.yaml 2>&1 "${kube_flags[@]}" || true |
There was a problem hiding this comment.
From help text:
--request-timeout='0': The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.
I don't understand why you give --request-timeout=1. And it's not clear to me that timeout is 1s or 1m or ...
There was a problem hiding this comment.
I think it's b/c I left a comment about it. If we don't specify a timeout, the test spend 30s here for the blocked initializer. Now I'm suspecting this 1s might cause flakes, I'm not sure making it another value like 5s would help prevent the flake at all.
There was a problem hiding this comment.
I don't understand why you give --request-timeout=1
@mengqiy I've added pending initializers in the yaml, which will keep blocking until timeout. Per discussion.
And it's not clear to me that timeout is 1s or 1m or ...
Just follow other commands in the test files. Actually --request-timeout=1 means 1sec.
Since the flag description of --request-timeout is quite confusing. We may consider to elaborate it.
|
/test pull-kubernetes-e2e-gce-bazel |
|
@dixudx Please squash some unnecessary commits. Don't block on this, it's code freeze today. |
|
RE. release note, I think we need to provide more information. We need to update the linked doc later. |
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: caesarxuchao, deads2k, dixudx, mengqiy Associated issue: 49035 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue (batch tested with PRs 51301, 50497, 50112, 48184, 50993) |
|
@dixudx: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubectl should return an error if "-l" and "--all" are both specified **What this PR does / why we need it**: Per discussion in [kubernetes#50497](kubernetes#50497 (comment)) **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: /assign @caesarxuchao @mengqiy **Release note**: ```release-note kubectl should return an error if "-l" and "--all" are both specified ```
…tialized Automatic merge from submit-queue (batch tested with PRs 51301, 50497, 50112, 48184, 50993) Introduce new flag "--include-uninitialized" to kubectl **What this PR does / why we need it**: Introduce `--include-uninitialized` as a global flag to kubectl **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes kubernetes#49035 **Special notes for your reviewer**: /assign @caesarxuchao @smarterclayton @ahmetb @deads2k **Release note**: ```release-note Add flag "--include-uninitialized" to kubectl annotate, apply, edit-last-applied, delete, describe, edit, get, label, set. "--include-uninitialized=true" makes kubectl commands apply to uninitialized objects, which by default are ignored if the names of the objects are not provided. "--all" also makes kubectl commands apply to uninitialized objects. Please see the [initializer](https://kubernetes.io/docs/admin/extensible-admission-controllers/) doc for more details. ```
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubectl should return an error if "-l" and "--all" are both specified **What this PR does / why we need it**: Per discussion in [kubernetes#50497](kubernetes#50497 (comment)) **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: /assign @caesarxuchao @mengqiy **Release note**: ```release-note kubectl should return an error if "-l" and "--all" are both specified ```
What this PR does / why we need it:
Introduce
--include-uninitializedas a global flag to kubectlWhich issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close that issue when PR gets merged): fixes #49035Special notes for your reviewer:
/assign @caesarxuchao @smarterclayton @ahmetb @deads2k
Release note: