Merge pull request #95066 from SataQiu/wrap-errors-2020092502

Wrap errors for NodeLabel, NodePorts, NodePreferAvoidPods and NodeResourcesBalancedAllocation plugins
This commit is contained in:
Kubernetes Prow Robot 2020-10-13 09:46:27 -07:00 committed by GitHub
commit e3d7d067ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 7 deletions

View File

@ -109,8 +109,8 @@ func (pl *NodeLabel) Filter(ctx context.Context, _ *framework.CycleState, pod *v
// Score invoked at the score extension point. // Score invoked at the score extension point.
func (pl *NodeLabel) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) { func (pl *NodeLabel) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName) nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil || nodeInfo.Node() == nil { if err != nil {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v, node is nil: %v", nodeName, err, nodeInfo.Node() == nil)) return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
} }
node := nodeInfo.Node() node := nodeInfo.Node()

View File

@ -87,7 +87,7 @@ func getPreFilterState(cycleState *framework.CycleState) (preFilterState, error)
c, err := cycleState.Read(preFilterStateKey) c, err := cycleState.Read(preFilterStateKey)
if err != nil { if err != nil {
// preFilterState doesn't exist, likely PreFilter wasn't invoked. // preFilterState doesn't exist, likely PreFilter wasn't invoked.
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err) return nil, fmt.Errorf("reading %q from cycleState: %w", preFilterStateKey, err)
} }
s, ok := c.(preFilterState) s, ok := c.(preFilterState)
@ -101,7 +101,7 @@ func getPreFilterState(cycleState *framework.CycleState) (preFilterState, error)
func (pl *NodePorts) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status { func (pl *NodePorts) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
wantPorts, err := getPreFilterState(cycleState) wantPorts, err := getPreFilterState(cycleState)
if err != nil { if err != nil {
return framework.NewStatus(framework.Error, err.Error()) return framework.AsStatus(err)
} }
fits := fitsPorts(wantPorts, nodeInfo) fits := fitsPorts(wantPorts, nodeInfo)

View File

@ -18,6 +18,7 @@ package nodeports
import ( import (
"context" "context"
"fmt"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -170,7 +171,7 @@ func TestPreFilterDisabled(t *testing.T) {
p, _ := New(nil, nil) p, _ := New(nil, nil)
cycleState := framework.NewCycleState() cycleState := framework.NewCycleState()
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, pod, nodeInfo) gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, pod, nodeInfo)
wantStatus := framework.NewStatus(framework.Error, `error reading "PreFilterNodePorts" from cycleState: not found`) wantStatus := framework.AsStatus(fmt.Errorf(`reading "PreFilterNodePorts" from cycleState: %w`, fmt.Errorf("not found")))
if !reflect.DeepEqual(gotStatus, wantStatus) { if !reflect.DeepEqual(gotStatus, wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus) t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
} }

View File

@ -47,7 +47,7 @@ func (pl *NodePreferAvoidPods) Name() string {
func (pl *NodePreferAvoidPods) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) { func (pl *NodePreferAvoidPods) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName) nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil { if err != nil {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v", nodeName, err)) return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
} }
node := nodeInfo.Node() node := nodeInfo.Node()

View File

@ -49,7 +49,7 @@ func (ba *BalancedAllocation) Name() string {
func (ba *BalancedAllocation) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) { func (ba *BalancedAllocation) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
nodeInfo, err := ba.handle.SnapshotSharedLister().NodeInfos().Get(nodeName) nodeInfo, err := ba.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
if err != nil { if err != nil {
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v", nodeName, err)) return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err))
} }
// ba.score favors nodes with balanced resource usage rate. // ba.score favors nodes with balanced resource usage rate.