mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Merge pull request #86542 from zouyee/nodeinfocheck
introduce checker for the result of nodeInfo.Node()
This commit is contained in:
commit
175ee0a111
@ -101,6 +101,9 @@ func (pl *NodeLabel) Name() string {
|
||||
// and it may be desirable to avoid scheduling new pods on this node.
|
||||
func (pl *NodeLabel) Filter(ctx context.Context, _ *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
|
||||
node := nodeInfo.Node()
|
||||
if node == nil {
|
||||
return framework.NewStatus(framework.Error, "node not found")
|
||||
}
|
||||
nodeLabels := labels.Set(node.Labels)
|
||||
check := func(labels []string, presence bool) bool {
|
||||
for _, label := range labels {
|
||||
@ -121,8 +124,8 @@ func (pl *NodeLabel) Filter(ctx context.Context, _ *framework.CycleState, pod *v
|
||||
// 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) {
|
||||
nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName)
|
||||
if err != nil {
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v", nodeName, err))
|
||||
if err != nil || nodeInfo.Node() == nil {
|
||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("getting node %q from Snapshot: %v, node is nil: %v", nodeName, err, nodeInfo.Node() == nil))
|
||||
}
|
||||
|
||||
node := nodeInfo.Node()
|
||||
|
@ -244,3 +244,33 @@ func TestNodeLabelScore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeLabelFilterWithoutNode(t *testing.T) {
|
||||
var pod *v1.Pod
|
||||
t.Run("node does not exist", func(t *testing.T) {
|
||||
nodeInfo := schedulernodeinfo.NewNodeInfo()
|
||||
p, err := New(nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create plugin: %v", err)
|
||||
}
|
||||
status := p.(framework.FilterPlugin).Filter(context.TODO(), nil, pod, nodeInfo)
|
||||
if status.Code() != framework.Error {
|
||||
t.Errorf("Status mismatch. got: %v, want: %v", status.Code(), framework.Error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestNodeLabelScoreWithoutNode(t *testing.T) {
|
||||
t.Run("node does not exist", func(t *testing.T) {
|
||||
fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(nodeinfosnapshot.NewEmptySnapshot()))
|
||||
p, err := New(nil, fh)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create plugin: %+v", err)
|
||||
}
|
||||
_, status := p.(framework.ScorePlugin).Score(context.Background(), nil, nil, "")
|
||||
if status.Code() != framework.Error {
|
||||
t.Errorf("Status mismatch. got: %v, want: %v", status.Code(), framework.Error)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user