-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Conversation
022bede
to
14a2497
Compare
pkg/kubectl/cmd/wait/wait.go
Outdated
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 |
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 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...
/cc @wenjiaswe @jpbetz |
@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:
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. |
14a2497
to
638100a
Compare
[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 |
638100a
to
e2ec695
Compare
e2ec695
to
70d51b3
Compare
/retest |
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.
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 { |
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.
Can you rename the function to isDeletedOrError
currently the name and the code don't express the same thing.
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 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 { |
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.
Same here.
pkg/kubectl/cmd/wait/wait.go
Outdated
@@ -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 |
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 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
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.
conditional wait doesn't have ErrOut
, I was considering whether to do this or not. I'm fine with it
I'd like a minor tweak to the factorization and then lgtm. |
70d51b3
to
50ee2e1
Compare
50ee2e1
to
2aed55c
Compare
/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.
2aed55c
to
5a8afa0
Compare
// 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: |
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.
David also meant this condition to look similar to the other one in isConditionMet
.
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.
It does?
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.
How is this different than the other if not?
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.
The other one calls checkCondition.
@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) |
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, I was looking at the switch and didn't notice this is working as expected.
/lgtm
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.