-
Notifications
You must be signed in to change notification settings - Fork 673
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
feature(eviction): add event when EvictPod failed #1536
base: master
Are you sure you want to change the base?
Conversation
/retest |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
t.Run(test.description, func(t *testing.T) { | ||
fakeClient := fake.NewClientset(test.pods...) | ||
fakeClient.PrependReactor("create", "pods/eviction", func(action core.Action) (handled bool, ret runtime.Object, err error) { | ||
if test.wantErrMsg == fmt.Sprintf(notFoundText, test.evictedPod.Name, test.evictedPod.Name) { |
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 about to pass k8serrors.XXX
directly? I.e.
[]struct {
description string
node *v1.Node
evictedPod *v1.Pod
pods []runtime.Object
wantErr error
}{
...
{
description: "test pod eviction - pod absent (not found error)",
node: node1,
evictedPod: pod1,
pods: []runtime.Object{test.BuildTestPod("p2", 400, 0, "node1", nil), test.BuildTestPod("p3", 450, 0, "node1", nil)},
wantErr: k8serrors.NewNotFound(v1.Resource("pods"), pod1.Name),
},
}
...
fakeClient.PrependReactor("create", "pods/eviction", func(action core.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, test.wantErr
})
The original wantErr bool can be turned into wantErr != 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.
Because we return using the fmt.Error
, we cannot directly use k8serrors.XXX
, but we can simplify it to directly use fmt.Error
to return
descheduler/pkg/descheduler/evictions/evictions.go
Lines 213 to 221 in da52983
err := client.PolicyV1().Evictions(eviction.Namespace).Evict(ctx, eviction) | |
if apierrors.IsTooManyRequests(err) { | |
return fmt.Errorf("error when evicting pod (ignoring) %q: %v", pod.Name, err) | |
} | |
if apierrors.IsNotFound(err) { | |
return fmt.Errorf("pod not found when evicting %q: %v", pod.Name, err) | |
} | |
return err |
if test.expectedError != nil { | ||
return true, nil, test.expectedError | ||
} | ||
return true, nil, 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.
The whole function body can be reduced to return true, nil, test.expectedError
.
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.
done
04775aa
to
44f3adf
Compare
/test pull-descheduler-test-e2e-k8s-master-1-30 |
/kind feature
When it comes to eviction, what we really care about are the errors that occur during evictions. So I tend to include events when an eviction fails. Besides metrics and application logs, events are also a valuable source of information. Typically, operations personnel respond to events to manage the cluster effectively.