-
Notifications
You must be signed in to change notification settings - Fork 39.3k
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
do not filter kubectl get pods if -o json or yaml #39042
do not filter kubectl get pods if -o json or yaml #39042
Conversation
Hi @juanvallejo. 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 If you have questions or suggestions related to this bot's behavior, please file an issue against the kubernetes/test-infra repository. |
@k8s-bot ok to test |
@@ -187,7 +187,8 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ | |||
if err != nil { | |||
return err | |||
} | |||
if len(options.Filenames) > 0 || argsHasNames { | |||
output := cmdutil.GetFlagString(cmd, "output") | |||
if len(options.Filenames) > 0 || argsHasNames || output == "json" || output == "yaml" { |
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.
Probably would be better to default show-all to true, rather than force it to true.
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.e. kubectl get pods -o yaml --show-all=false should filter pods.
@smarterclayton thanks for the feedback, updated the default value (and flag description) of |
Jenkins unit/integration failed for commit e1ec3d80991937ce92a0eddb6844dbe487693153. Full PR test history. The magic incantation to run this job again is 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. I understand the commands that are listed here. |
e1ec3d8
to
e3ca1e7
Compare
@juanvallejo I think we only want to change the default if -o json or yaml is specified. I think you should be able to check if a flag value has been specified or not (different than checking the value). You can then keep your changes as before, but guard setting "true" on if it has not been explicitly set already. |
This patch sets the value of --show-all to true if the output format specified is 'json' or 'yaml'.
e3ca1e7
to
cade00e
Compare
@pwittrock Thanks for the feedback, updated original commit to check if |
Jenkins kops AWS e2e failed for commit cade00e. Full PR test history. The magic incantation to run this job again is 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. I understand the commands that are listed here. |
@k8s-bot kops aws e2e test this |
@k8s-bot unit test this |
@k8s-bot bazel test this |
if len(options.Filenames) > 0 || argsHasNames { | ||
cmd.Flag("show-all").Value.Set("true") | ||
output := cmdutil.GetFlagString(cmd, "output") | ||
if len(options.Filenames) > 0 || argsHasNames || output == "json" || output == "yaml" { |
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.
What happens if --output
is go-template*
or jsonpath*
? I believe it should apply to all too (no filtering). Also, I'd suggest to move the output check to a helper function like OutputsRawFormat(output string) bool
or something similar.
@fabianofranz thanks for the feedback, added a |
Jenkins GCI GCE e2e failed for commit 34c30ca. Full PR test history. cc @juanvallejo The magic incantation to run this job again is 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. I understand the commands that are listed here. |
@fabianofranz GCI GCE flaked on #39973 |
@k8s-bot gci gce e2e test this |
// always show resources when getting by name or filename | ||
// determine if args contains "all" | ||
for _, a := range args { | ||
if a == "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.
This will match situations where resources are named 'all'
kubectl get pods all
I'd either address this in a follow up for a quicker approval and submission, or fix it by matching the parsing logic for the 'all' keyword
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.
@pwittrock thanks for the feedback. I removed this and just use the boolean value of resource.MultipleTypesRequested
.
cc @fabianofranz this would mean that passing the all
alias or requesting mixed resource types would cause the value of show-all
to default to true
. wdyt?
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.
ug, it looks like that code has the same issue. I am not sure if there is a great solution:
kubernetes/pkg/kubectl/resource/builder.go
Line 808 in 6e5b455
func MultipleTypesRequested(args []string) 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.
Sorry if this was covered in another comment. What is the motivation for showing all when printing all resource types? This is unrelated to the output type.
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.
What is the motivation for showing all when printing all resource types? This is unrelated to the output type.
Although unrelated to the output type, I was thinking it would be a better user experience overall if all
implied that even resources that are hidden by default would also be displayed.
it looks like that code has the same issue. I am not sure if there is a great solution:
kubernetes/pkg/kubectl/resource/builder.go
Line 808 in 6e5b455
func MultipleTypesRequested(args []string) bool { |
Would it be a valid assumption that if all
comes before any other "kind", it can be implied that the user did mean "all resources", rather than pod/all
? If this is the case, could we only check to see if args[0] == "all"
, or would that be too fragile?
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.
Although unrelated to the output type, I was thinking it would be a better user experience overall if all implied that even resources that are hidden by default would also be displayed.
This might be a lot of things, since this is showing both all resource types and hidden resources.
Would it be a valid assumption that if all comes before any other "kind", it can be implied that the user did mean "all resources", rather than pod/all? If this is the case, could we only check to see if args[0] == "all", or would that be too fragile?
Maybe we should check there is only 1 argument, and it is all?
if len(args) == 1 && args[0] == "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.
Maybe we should check there is only 1 argument, and it is all?
Sounds good to me, I can go ahead and open a PR to patch this in the MultipleTypesRequested
helper
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.
This might be a lot of things, since this is showing both all resource types and hidden resources.
This makes sense, I'll remove the check for all
from the logic for the default value of show-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.
Maybe we should check there is only 1 argument, and it is all?
Remember you may be interesting in getting all + something that is not in all, in which case you would have for example kubectl get events,all
. Seems to break the proposed logic.
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.
Remember you may be interesting in getting all + something that is not in all, in which case you would have for example kubectl get events,all. Seems to break the proposed logic.
This is a good point, I am updating the logic for MultipleTypesRequested
in this PR, and while specifying something like $ kubectl get pods,all
does not fulfill the base case check of if len(args) == 1 && args[0] == "all"
, the rest of the logic for that function does correctly detect multiple types in cases like this one when it splits the string by ,
and finds more than one "resource" was specified. Although this would no longer be work for this PR (if we had just decided to check for "all" using len(args) == 1 && args[0] == "all"
rather than calling the entire MultipleTypesRequested
helper)
34c30ca
to
430283b
Compare
SGTM. Let me know when it is updated. (removing multiple resource types piece) |
Done! |
/lgtm |
Automatic merge from submit-queue (batch tested with PRs 36467, 36528, 39568, 40094, 39042) |
After looking at this and staring at it for a bit while fixing other bugs, I think I was wrong to want this. It makes behavior of get inconsistent and is surprising. Users should learn to use I'm going to open a PR to revert this behavior for 1.6 unless anyone objects. |
Since this has CLI API implications, I'd prefer to make a decision for 1.6 so we don't have to live with it. |
Instead, we should simply ensure we don't show the message for filtering for generic output. |
Fixes: #38327
This patch sets the value of --show-all to true if the output format
specified is 'json' or 'yaml'.
Release note:
@smarterclayton