mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Wrap errors when running PreBind plugins
Signed-off-by: Aldo Culquicondor <acondor@google.com> Change-Id: I31bf35d7e96b1cebb285cf03ffad310d83224d9c Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
parent
34102140e2
commit
a482d7ef8e
@ -710,9 +710,9 @@ func (f *frameworkImpl) RunPreBindPlugins(ctx context.Context, state *framework.
|
||||
for _, pl := range f.preBindPlugins {
|
||||
status = f.runPreBindPlugin(ctx, pl, state, pod, nodeName)
|
||||
if !status.IsSuccess() {
|
||||
msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
|
||||
klog.Error(msg)
|
||||
return framework.NewStatus(framework.Error, msg)
|
||||
err := fmt.Errorf("error while running %q prebind plugin for pod %q: %w", pl.Name(), pod.Name, status.AsError())
|
||||
klog.Error(err)
|
||||
return framework.AsStatus(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -18,6 +18,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@ -1138,6 +1139,7 @@ func TestPostFilterPlugins(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPreBindPlugins(t *testing.T) {
|
||||
injectedStatusErr := errors.New("injected status")
|
||||
tests := []struct {
|
||||
name string
|
||||
plugins []*TestPlugin
|
||||
@ -1166,7 +1168,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Unschedulable)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "ErrorPreBindPlugin",
|
||||
@ -1176,7 +1178,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "UnschedulablePreBindPlugin",
|
||||
@ -1186,7 +1188,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.UnschedulableAndUnresolvable)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "SuccessErrorPreBindPlugins",
|
||||
@ -1200,7 +1202,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin 1" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin 1" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "ErrorSuccessPreBindPlugin",
|
||||
@ -1214,7 +1216,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Success)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "SuccessSuccessPreBindPlugin",
|
||||
@ -1242,7 +1244,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
{
|
||||
name: "UnschedulableAndSuccessPreBindPlugin",
|
||||
@ -1256,7 +1258,7 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Success)},
|
||||
},
|
||||
},
|
||||
wantStatus: v1alpha1.NewStatus(v1alpha1.Error, `error while running "TestPlugin" prebind plugin for pod "": injected status`),
|
||||
wantStatus: v1alpha1.AsStatus(fmt.Errorf(`error while running "TestPlugin" prebind plugin for pod "": %w`, injectedStatusErr)),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package v1alpha1
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
@ -149,7 +148,7 @@ func (s *Status) AsError() error {
|
||||
if s.err != nil {
|
||||
return s.err
|
||||
}
|
||||
return fmt.Errorf("%s: %s", s.code.String(), s.Message())
|
||||
return errors.New(s.Message())
|
||||
}
|
||||
|
||||
// NewStatus makes a Status out of the given arguments and returns its pointer.
|
||||
|
@ -211,6 +211,7 @@ func TestSchedulerScheduleOne(t *testing.T) {
|
||||
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()})
|
||||
errS := errors.New("scheduler")
|
||||
errB := errors.New("binder")
|
||||
preBindErr := errors.New("on PreBind")
|
||||
|
||||
table := []struct {
|
||||
name string
|
||||
@ -256,12 +257,12 @@ func TestSchedulerScheduleOne(t *testing.T) {
|
||||
sendPod: podWithID("foo", ""),
|
||||
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
|
||||
registerPluginFuncs: []st.RegisterPluginFunc{
|
||||
st.RegisterPreBindPlugin("FakePreBind", st.NewFakePreBindPlugin(framework.NewStatus(framework.Error, "prebind error"))),
|
||||
st.RegisterPreBindPlugin("FakePreBind", st.NewFakePreBindPlugin(framework.AsStatus(preBindErr))),
|
||||
},
|
||||
expectErrorPod: podWithID("foo", testNode.Name),
|
||||
expectForgetPod: podWithID("foo", testNode.Name),
|
||||
expectAssumedPod: podWithID("foo", testNode.Name),
|
||||
expectError: errors.New(`error while running "FakePreBind" prebind plugin for pod "foo": prebind error`),
|
||||
expectError: fmt.Errorf(`error while running "FakePreBind" prebind plugin for pod "foo": %w`, preBindErr),
|
||||
eventReason: "FailedScheduling",
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user