mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +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 {
|
for _, pl := range f.preBindPlugins {
|
||||||
status = f.runPreBindPlugin(ctx, pl, state, pod, nodeName)
|
status = f.runPreBindPlugin(ctx, pl, state, pod, nodeName)
|
||||||
if !status.IsSuccess() {
|
if !status.IsSuccess() {
|
||||||
msg := fmt.Sprintf("error while running %q prebind plugin for pod %q: %v", pl.Name(), pod.Name, status.Message())
|
err := fmt.Errorf("error while running %q prebind plugin for pod %q: %w", pl.Name(), pod.Name, status.AsError())
|
||||||
klog.Error(msg)
|
klog.Error(err)
|
||||||
return framework.NewStatus(framework.Error, msg)
|
return framework.AsStatus(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -18,6 +18,7 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1138,6 +1139,7 @@ func TestPostFilterPlugins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPreBindPlugins(t *testing.T) {
|
func TestPreBindPlugins(t *testing.T) {
|
||||||
|
injectedStatusErr := errors.New("injected status")
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
plugins []*TestPlugin
|
plugins []*TestPlugin
|
||||||
@ -1166,7 +1168,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Unschedulable)},
|
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",
|
name: "ErrorPreBindPlugin",
|
||||||
@ -1176,7 +1178,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
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",
|
name: "UnschedulablePreBindPlugin",
|
||||||
@ -1186,7 +1188,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.UnschedulableAndUnresolvable)},
|
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",
|
name: "SuccessErrorPreBindPlugins",
|
||||||
@ -1200,7 +1202,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
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",
|
name: "ErrorSuccessPreBindPlugin",
|
||||||
@ -1214,7 +1216,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Success)},
|
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",
|
name: "SuccessSuccessPreBindPlugin",
|
||||||
@ -1242,7 +1244,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Error)},
|
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",
|
name: "UnschedulableAndSuccessPreBindPlugin",
|
||||||
@ -1256,7 +1258,7 @@ func TestPreBindPlugins(t *testing.T) {
|
|||||||
inj: injectedResult{PreBindStatus: int(v1alpha1.Success)},
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -149,7 +148,7 @@ func (s *Status) AsError() error {
|
|||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
return s.err
|
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.
|
// 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()})
|
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()})
|
||||||
errS := errors.New("scheduler")
|
errS := errors.New("scheduler")
|
||||||
errB := errors.New("binder")
|
errB := errors.New("binder")
|
||||||
|
preBindErr := errors.New("on PreBind")
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -256,12 +257,12 @@ func TestSchedulerScheduleOne(t *testing.T) {
|
|||||||
sendPod: podWithID("foo", ""),
|
sendPod: podWithID("foo", ""),
|
||||||
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
|
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
|
||||||
registerPluginFuncs: []st.RegisterPluginFunc{
|
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),
|
expectErrorPod: podWithID("foo", testNode.Name),
|
||||||
expectForgetPod: podWithID("foo", testNode.Name),
|
expectForgetPod: podWithID("foo", testNode.Name),
|
||||||
expectAssumedPod: 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",
|
eventReason: "FailedScheduling",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user