Skip to content
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

Fix #74900 - kubectl logs --selector supports --tail=-1 #74943

Merged
merged 1 commit into from Jul 1, 2019

Conversation

@JishanXing
Copy link
Contributor

commented Mar 5, 2019

What type of PR is this?
/kind bug

What this PR does / why we need it:
Fix #74900 - kubectl logs --selector supports --tail=-1

Which issue(s) this PR fixes:
#74900

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

kubectl logs --selector will support --tail=-1.
@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

commented Mar 5, 2019

Hi @JishanXing. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot requested review from adohe and dims Mar 5, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from 160c100 to 2a0c16c Mar 5, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch 2 times, most recently from 8204abc to e4f8447 Mar 26, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from e4f8447 to 3fce312 Apr 8, 2019
@@ -192,6 +192,7 @@ func (o *LogsOptions) ToLogOptions() (*corev1.PodLogOptions, error) {
}

if len(o.Selector) > 0 && o.Tail == -1 {
} else if len(o.Selector) > 0 && o.Tail < -1 {

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 8, 2019

Contributor

This is not a good solution, you should be checking whether a flag was changed, through its .Changed attribute in Complete method and set a bool flag to tell the difference.

This comment has been minimized.

Copy link
@JishanXing

JishanXing Apr 10, 2019

Author Contributor

Hi soltysh,

Thanks for your reviewing. Please help review again. Thanks.

if len(o.Selector) > 0 && o.Tail == -1 && o.TailSpecified {
logOptions.TailLines = nil <====if user specify -1, it means show all lines
} else if len(o.Selector) > 0 && o.Tail < -1 {
logOptions.TailLines = &o.Tail <===== tail must greater than -1
} else if o.Tail != -1 {
logOptions.TailLines = &o.Tail
}

I also append the fix idea and testcases in #74900

Regards,
Jishan

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 10, 2019

Contributor

I think you have the condition backwards.

This comment has been minimized.

Copy link
@JishanXing

JishanXing Apr 12, 2019

Author Contributor

Hi soltysh,

Thanks for your review.
I changed the code according to your suggestion. It will pass the -1 to the server side, so we need change the API's validation too.
if o.TailSpecified {
logOptions.TailLines = &o.Tail
}
Please help review again. Thanks.

@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from 3fce312 to ae614a0 Apr 10, 2019
@k8s-ci-robot k8s-ci-robot added size/S and removed size/XS labels Apr 10, 2019
@@ -192,6 +192,7 @@ func (o *LogsOptions) ToLogOptions() (*corev1.PodLogOptions, error) {
}

if len(o.Selector) > 0 && o.Tail == -1 {
} else if len(o.Selector) > 0 && o.Tail < -1 {

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 10, 2019

Contributor

I think you have the condition backwards.

@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch 2 times, most recently from 4ca40eb to 38556ae Apr 12, 2019
@@ -124,8 +124,8 @@ func validateResourceName(value string, fldPath *field.Path) field.ErrorList {

func ValidatePodLogOptions(opts *v1.PodLogOptions) field.ErrorList {
allErrs := field.ErrorList{}
if opts.TailLines != nil && *opts.TailLines < 0 {

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 15, 2019

Contributor

You can't change the validation on the API side, leave it as it was before.

@@ -5192,8 +5192,8 @@ func ValidateSecurityContext(sc *core.SecurityContext, fldPath *field.Path) fiel

func ValidatePodLogOptions(opts *core.PodLogOptions) field.ErrorList {
allErrs := field.ErrorList{}
if opts.TailLines != nil && *opts.TailLines < 0 {

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 15, 2019

Contributor

Ditto.

if len(o.Selector) > 0 && o.Tail == -1 {
logOptions.TailLines = &selectorTail
} else if o.Tail != -1 {
if o.TailSpecified {

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 15, 2019

Contributor

The first condition should be left untouched. You can eventually change it to !o.TailSpecified

if logsOptions.TailLines != nil && *logsOptions.TailLines < 0 {
return fmt.Errorf("TailLines must be greater than or equal to 0")
if logsOptions.TailLines != nil && *logsOptions.TailLines < -1 {
return fmt.Errorf("TailLines must be greater than or equal to -1")

This comment has been minimized.

Copy link
@soltysh

soltysh Apr 15, 2019

Contributor

the flag name is --tail and that's what should be in the error.

@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch 4 times, most recently from db8ece6 to 9ee2bdc Apr 16, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch 2 times, most recently from ef33567 to 967476a May 10, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch 2 times, most recently from 606b500 to 659b317 May 28, 2019
Copy link
Contributor

left a comment

/ok-to-test
/lgtm
/approve

@soltysh

This comment has been minimized.

Copy link
Contributor

commented May 30, 2019

/priority important-longterm

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

commented May 30, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JishanXing, soltysh

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from 659b317 to 500fa7f Jun 2, 2019
@k8s-ci-robot k8s-ci-robot removed the lgtm label Jun 2, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from 500fa7f to f4fba60 Jun 2, 2019
@JishanXing JishanXing force-pushed the JishanXing:bug-fix branch from f4fba60 to d2896d6 Jun 2, 2019
@k8s-ci-robot k8s-ci-robot added size/S and removed size/XS labels Jun 2, 2019
Copy link
Contributor

left a comment

/lgtm
@JishanXing please update release notes since this is a user facing change

@JishanXing

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

/retest

@k8s-ci-robot k8s-ci-robot merged commit bf86300 into kubernetes:master Jul 1, 2019
23 checks passed
23 checks passed
cla/linuxfoundation JishanXing authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-conformance-image-test Skipped.
pull-kubernetes-cross Skipped.
pull-kubernetes-dependencies Job succeeded.
Details
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-csi-serial Skipped.
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gce-iscsi Skipped.
pull-kubernetes-e2e-gce-iscsi-serial Skipped.
pull-kubernetes-e2e-gce-storage-slow Skipped.
pull-kubernetes-godeps Skipped.
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped.
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-node-e2e-containerd Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
pull-publishing-bot-validate Skipped.
tide In merge pool.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.