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

kubectl wait must handle errors returned by watch #69389

Merged
merged 1 commit into from
Oct 25, 2018

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Oct 3, 2018

Watch can return type "ERROR" and a metav1.Status object. We need to
handle that during wait.

@deads2k i think we should probably have the dynamic watch handle error below
us and return a metav1.Status. I need to investigate more.

The kubectl wait command must handle when a watch returns an error vs closing by printing out the error and retrying the watch.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 3, 2018
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 3, 2018
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 3, 2018
if err := apierrors.FromObject(watchEvent.Object); err != nil {
return gottenObj, false, err
}
// TODO: this is terrible because I should be getting metav1.Status from the watch scheme - we could
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 think I'm going to move this into apierrors.FromObject, as much as it pains me, because that's at least guaranteed of having a chance to catch it. I don't like hardcoding apiVersion, but that's the api...

@jennybuckley
Copy link

/cc @wenjiaswe @jpbetz

@k8s-ci-robot
Copy link
Contributor

@jennybuckley: GitHub didn't allow me to request PR reviews from the following users: wenjiaswe.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @wenjiaswe @jpbetz

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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: smarterclayton

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 release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 8, 2018
@smarterclayton smarterclayton changed the title WIP - Sketch fix for watch errors kubectl wait must handle errors returned by watch Oct 8, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 8, 2018
@smarterclayton smarterclayton added the kind/bug Categorizes issue or PR as related to a bug. label Oct 8, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Oct 8, 2018
@smarterclayton
Copy link
Contributor Author

/retest

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

Two naming nits, overall this lgtm. I'll let @deads2k have final saying, it's his baby still ;)

@@ -300,7 +305,12 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
}

func isDeleted(event watch.Event) (bool, error) {
return event.Type == watch.Deleted, nil
switch event.Type {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename the function to isDeletedOrError currently the name and the code don't express the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only returns true on deleted.

@@ -389,6 +404,9 @@ func (w ConditionalWait) checkCondition(obj *unstructured.Unstructured) (bool, e
}

func (w ConditionalWait) isConditionMet(event watch.Event) (bool, error) {
if event.Type == watch.Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@@ -389,6 +404,9 @@ func (w ConditionalWait) checkCondition(obj *unstructured.Unstructured) (bool, e
}

func (w ConditionalWait) isConditionMet(event watch.Event) (bool, error) {
if event.Type == watch.Error {
return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be

if event.Type == watch.Error {
	err = apierrors.FromObject(event.Object)
	fmt.Fprintf(o.ErrOut, "error: An error occurred while waiting for the condition to be satisfied: %v", err)
	// this will chain back out, result in another get and an return false back up the chain
	return false, nil
}

And the condition check would appear more normal.

Same for above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

conditional wait doesn't have ErrOut, I was considering whether to do this or not. I'm fine with it

@deads2k
Copy link
Contributor

deads2k commented Oct 15, 2018

I'd like a minor tweak to the factorization and then lgtm.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 16, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 16, 2018
@smarterclayton
Copy link
Contributor Author

/retest

Watch can return type "ERROR" and a metav1.Status object. We need to
handle that during wait, and make it easy to handle the status object.
// IsDeleted returns true if the object is deleted. It prints any errors it encounters.
func (w Wait) IsDeleted(event watch.Event) (bool, error) {
switch event.Type {
case watch.Error:
Copy link
Contributor

Choose a reason for hiding this comment

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

David also meant this condition to look similar to the other one in isConditionMet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does?

Copy link
Contributor

Choose a reason for hiding this comment

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

How is this different than the other if not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other one calls checkCondition.

@smarterclayton
Copy link
Contributor Author

@soltysh not sure what you're asking on the last comment - hopefully that answers the obvious question (but not sure that there isn't something deeper you're asking)

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

Sorry, I was looking at the switch and didn't notice this is working as expected.
/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 25, 2018
@k8s-ci-robot k8s-ci-robot merged commit b6fd5d9 into kubernetes:master Oct 25, 2018
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. area/apiserver area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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

5 participants