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

Clean up dynamic client pre-flight check #82652

Merged
merged 1 commit into from
Oct 10, 2019
Merged

Clean up dynamic client pre-flight check #82652

merged 1 commit into from
Oct 10, 2019

Conversation

ricardomaraschini
Copy link
Contributor

@ricardomaraschini ricardomaraschini commented Sep 12, 2019

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This patch moves pre-request validations to a function and implements tests for it.

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

@k8s-ci-robot
Copy link
Contributor

Welcome @ricardomaraschini!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 12, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @ricardomaraschini. 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 added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 12, 2019
@ricardomaraschini
Copy link
Contributor Author

/assign deads2k

@yliaog
Copy link
Contributor

yliaog commented Sep 12, 2019

/cc

@@ -691,6 +691,30 @@ func (r *Request) Stream() (io.ReadCloser, error) {
}
}

// requestPreflightCheck looks for common programmer errors on Request.
//
// We return an error if an attempt to POST is made using an "empty" namespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have cluster scoped resources like Nodes, ClusterRoles, and many others. This comment suggests that this change would prevent those from working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, maybe the comment is not clear enough. What I meant is that if r.namespaceSet == true then len(r.namespace) cant be zero(empty). This logic was already there, but in a different way[1].

[1] https://github.com/kubernetes/kubernetes/pull/82652/files#diff-a47b7155403b5094bbe75cf02d4da303L710

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardomaraschini could you rewrite the comment to make that more obvious, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. It is done, ptal.

@deads2k
Copy link
Contributor

deads2k commented Sep 26, 2019

/hold

I have reservations based on comment and where I see the code plumbed: https://github.com/kubernetes/kubernetes/pull/82652/files#r328611767

/ok-to-test

I'm expecting failures.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 26, 2019
@ricardomaraschini
Copy link
Contributor Author

/test pull-kubernetes-integration

Copy link
Contributor

@alejandrox1 alejandrox1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/priority important-longterm
/milestone v1.17

@@ -691,6 +691,30 @@ func (r *Request) Stream() (io.ReadCloser, error) {
}
}

// requestPreflightCheck looks for common programmer errors on Request.
//
// We return an error if an attempt to POST is made using an "empty" namespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardomaraschini could you rewrite the comment to make that more obvious, please?

@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Sep 26, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.17 milestone Sep 26, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Sep 26, 2019
@deads2k
Copy link
Contributor

deads2k commented Sep 27, 2019

/hold cancel

The updated comment makes it more clear. I still haven't reviewed yet, but it no longer looks dangerous.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 27, 2019
@@ -702,19 +729,6 @@ func (r *Request) request(fn func(*http.Request, *http.Response)) error {
metrics.RequestLatency.Observe(r.verb, r.finalURLTemplate(), time.Since(start))
}()

if r.err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave this in place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have restored this to its original place on request() instead of Do() and DoRaw(). Coming up on the next commit.

}
}

if err := r.requestPreflightCheck(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the previous location for this better. The only benefit I'm seeing here is gettnig ahead of the ratelimiter, but it opens us up to having to remember this construct if we ever have another Do or DoRaw. You can make the error typed if you like, but this duplicated construct doesn't look like a net improvement..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the default approach. Coming up with the next commit.

Migrated code that checks for common programmer errors to a separated
function and added test coverage for it. Wrong comment stating that a
typed error is returned was also removed.
@ricardomaraschini
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-100-performance

@ricardomaraschini
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce-big

@deads2k
Copy link
Contributor

deads2k commented Oct 1, 2019

this factorization is equivalent and cleaner, thanks.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 1, 2019
@ricardomaraschini
Copy link
Contributor Author

/assign @alejandrox1

@ricardomaraschini
Copy link
Contributor Author

/assign @wojtek-t

@alejandrox1
Copy link
Contributor

This looks good. Thank you @ricardomaraschini
/assign @liggitt @lavalamp
for final approval

@liggitt liggitt changed the title Return RequestConstructionError when appropriate. Clean up dynamic client pre-flight check Oct 10, 2019
@liggitt
Copy link
Member

liggitt commented Oct 10, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, ricardomaraschini

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 10, 2019
@ricardomaraschini
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce

@k8s-ci-robot k8s-ci-robot merged commit 5ae180c into kubernetes:master Oct 10, 2019
@k8s-ci-robot
Copy link
Contributor

@ricardomaraschini: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce ad5fafd link /test pull-kubernetes-e2e-gce

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.

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.

ohsewon pushed a commit to ohsewon/kubernetes that referenced this pull request Oct 16, 2019
…nstruction-error

Clean up dynamic client pre-flight check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants