tests for nodes with different nodeName and name

This commit is contained in:
AxeZhan 2024-06-08 18:58:23 +08:00
parent fdca80f8dc
commit d8d31947dc

View File

@ -1805,8 +1805,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
name string name string
registerPlugins []tf.RegisterPluginFunc registerPlugins []tf.RegisterPluginFunc
extenders []tf.FakeExtender extenders []tf.FakeExtender
nodes []string nodes []*v1.Node
pvcs []v1.PersistentVolumeClaim pvcs []v1.PersistentVolumeClaim
pvs []v1.PersistentVolume
pod *v1.Pod pod *v1.Pod
pods []*v1.Pod pods []*v1.Pod
wantNodes sets.Set[string] wantNodes sets.Set[string]
@ -1819,7 +1820,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("FalseFilter", tf.NewFalseFilterPlugin), tf.RegisterFilterPlugin("FalseFilter", tf.NewFalseFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("2").UID("2").Obj(), pod: st.MakePod().Name("2").UID("2").Obj(),
name: "test 1", name: "test 1",
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -1841,7 +1845,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1), tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("ignore").UID("ignore").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").Obj(),
wantNodes: sets.New("node1", "node2"), wantNodes: sets.New("node1", "node2"),
name: "test 2", name: "test 2",
@ -1854,7 +1861,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("MatchFilter", tf.NewMatchFilterPlugin), tf.RegisterFilterPlugin("MatchFilter", tf.NewMatchFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("node2").UID("node2").Obj(), pod: st.MakePod().Name("node2").UID("node2").Obj(),
wantNodes: sets.New("node2"), wantNodes: sets.New("node2"),
name: "test 3", name: "test 3",
@ -1867,7 +1877,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3", "2", "1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
},
pod: st.MakePod().Name("ignore").UID("ignore").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").Obj(),
wantNodes: sets.New("3"), wantNodes: sets.New("3"),
name: "test 4", name: "test 4",
@ -1880,7 +1894,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3", "2", "1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
},
pod: st.MakePod().Name("2").UID("2").Obj(), pod: st.MakePod().Name("2").UID("2").Obj(),
wantNodes: sets.New("2"), wantNodes: sets.New("2"),
name: "test 5", name: "test 5",
@ -1894,7 +1912,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("ReverseNumericMap", newReverseNumericMapPlugin(), 2), tf.RegisterScorePlugin("ReverseNumericMap", newReverseNumericMapPlugin(), 2),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3", "2", "1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
},
pod: st.MakePod().Name("2").UID("2").Obj(), pod: st.MakePod().Name("2").UID("2").Obj(),
wantNodes: sets.New("1"), wantNodes: sets.New("1"),
name: "test 6", name: "test 6",
@ -1908,7 +1930,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3", "2", "1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
},
pod: st.MakePod().Name("2").UID("2").Obj(), pod: st.MakePod().Name("2").UID("2").Obj(),
name: "test 7", name: "test 7",
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -1936,7 +1962,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
st.MakePod().Name("2").UID("2").Node("2").Phase(v1.PodRunning).Obj(), st.MakePod().Name("2").UID("2").Node("2").Phase(v1.PodRunning).Obj(),
}, },
pod: st.MakePod().Name("2").UID("2").Obj(), pod: st.MakePod().Name("2").UID("2").Obj(),
nodes: []string{"1", "2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
},
name: "test 8", name: "test 8",
wErr: &framework.FitError{ wErr: &framework.FitError{
Pod: st.MakePod().Name("2").UID("2").Obj(), Pod: st.MakePod().Name("2").UID("2").Obj(),
@ -1959,13 +1988,19 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1), tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pvcs: []v1.PersistentVolumeClaim{ pvcs: []v1.PersistentVolumeClaim{
{ {
ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", UID: types.UID("existingPVC"), Namespace: v1.NamespaceDefault}, ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", UID: types.UID("existingPVC"), Namespace: v1.NamespaceDefault},
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "existingPV"}, Spec: v1.PersistentVolumeClaimSpec{VolumeName: "existingPV"},
}, },
}, },
pvs: []v1.PersistentVolume{
{ObjectMeta: metav1.ObjectMeta{Name: "existingPV"}},
},
pod: st.MakePod().Name("ignore").UID("ignore").Namespace(v1.NamespaceDefault).PVC("existingPVC").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").Namespace(v1.NamespaceDefault).PVC("existingPVC").Obj(),
wantNodes: sets.New("node1", "node2"), wantNodes: sets.New("node1", "node2"),
name: "existing PVC", name: "existing PVC",
@ -1979,7 +2014,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin), tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("ignore").UID("ignore").PVC("unknownPVC").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").PVC("unknownPVC").Obj(),
name: "unknown PVC", name: "unknown PVC",
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2003,7 +2041,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin), tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pvcs: []v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", UID: types.UID("existingPVC"), Namespace: v1.NamespaceDefault, DeletionTimestamp: &metav1.Time{}}}}, pvcs: []v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", UID: types.UID("existingPVC"), Namespace: v1.NamespaceDefault, DeletionTimestamp: &metav1.Time{}}}},
pod: st.MakePod().Name("ignore").UID("ignore").Namespace(v1.NamespaceDefault).PVC("existingPVC").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").Namespace(v1.NamespaceDefault).PVC("existingPVC").Obj(),
name: "deleted PVC", name: "deleted PVC",
@ -2028,7 +2069,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("TrueMap", newTrueMapPlugin(), 2), tf.RegisterScorePlugin("TrueMap", newTrueMapPlugin(), 2),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"2", "1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
},
pod: st.MakePod().Name("2").Obj(), pod: st.MakePod().Name("2").Obj(),
name: "test error with priority map", name: "test error with priority map",
wErr: fmt.Errorf("running Score plugins: %w", fmt.Errorf(`plugin "FalseMap" failed with: %w`, errPrioritize)), wErr: fmt.Errorf("running Score plugins: %w", fmt.Errorf(`plugin "FalseMap" failed with: %w`, errPrioritize)),
@ -2045,8 +2089,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(1, "hostname", v1.DoNotSchedule, &metav1.LabelSelector{ {ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(1, "kubernetes.io/hostname", v1.DoNotSchedule, &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{ MatchExpressions: []metav1.LabelSelectorRequirement{
{ {
Key: "foo", Key: "foo",
@ -2073,8 +2120,12 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1), tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(2, "hostname", v1.DoNotSchedule, &metav1.LabelSelector{ {ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(2, "kubernetes.io/hostname", v1.DoNotSchedule, &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{ MatchExpressions: []metav1.LabelSelectorRequirement{
{ {
Key: "foo", Key: "foo",
@ -2101,7 +2152,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
},
pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(), pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2132,7 +2185,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
Predicates: []tf.FitPredicate{tf.FalsePredicateExtender}, Predicates: []tf.FitPredicate{tf.FalsePredicateExtender},
}, },
}, },
nodes: []string{"1", "2", "3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
},
pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(), pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2159,7 +2216,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "3", Labels: map[string]string{"kubernetes.io/hostname": "3"}}},
},
pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(), pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2184,7 +2243,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1), tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"1", "2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
},
pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(), pod: st.MakePod().Name("test-filter").UID("test-filter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: nil, wErr: nil,
@ -2199,7 +2261,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"1", "2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2225,7 +2290,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"1", "2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: fmt.Errorf(`running PreFilter plugin "FakePreFilter": %w`, errors.New("injected error status")), wErr: fmt.Errorf(`running PreFilter plugin "FakePreFilter": %w`, errors.New("injected error status")),
@ -2248,7 +2316,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node2"), wantNodes: sets.New("node2"),
// since this case has no score plugin, we'll only try to find one node in Filter stage // since this case has no score plugin, we'll only try to find one node in Filter stage
@ -2272,7 +2344,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wErr: &framework.FitError{ wErr: &framework.FitError{
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
@ -2302,7 +2378,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wErr: &framework.FitError{ wErr: &framework.FitError{
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
@ -2330,7 +2408,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wErr: &framework.FitError{ wErr: &framework.FitError{
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
@ -2376,7 +2457,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1), tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node2", "node3"), wantNodes: sets.New("node2", "node3"),
wantEvaluatedNodes: ptr.To[int32](3), wantEvaluatedNodes: ptr.To[int32](3),
@ -2392,7 +2477,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
framework.NewStatus(framework.Error, "this score function shouldn't be executed because this plugin returned Skip in the PreScore"), framework.NewStatus(framework.Error, "this score function shouldn't be executed because this plugin returned Skip in the PreScore"),
), "PreScore", "Score"), ), "PreScore", "Score"),
}, },
nodes: []string{"node1", "node2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
},
pod: st.MakePod().Name("ignore").UID("ignore").Obj(), pod: st.MakePod().Name("ignore").UID("ignore").Obj(),
wantNodes: sets.New("node1", "node2"), wantNodes: sets.New("node1", "node2"),
}, },
@ -2403,7 +2491,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin), tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("pod1").UID("pod1").Obj(), pod: st.MakePod().Name("pod1").UID("pod1").Obj(),
wantNodes: sets.New("node1", "node2", "node3"), wantNodes: sets.New("node1", "node2", "node3"),
wantEvaluatedNodes: ptr.To[int32](1), wantEvaluatedNodes: ptr.To[int32](1),
@ -2418,7 +2510,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
), ),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"node1", "node2", "node3"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "node1"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node2", Labels: map[string]string{"kubernetes.io/hostname": "node2"}}},
{ObjectMeta: metav1.ObjectMeta{Name: "node3", Labels: map[string]string{"kubernetes.io/hostname": "node3"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: sets.New("node1", "node2"), wantNodes: sets.New("node1", "node2"),
// since this case has no score plugin, we'll only try to find one node in Filter stage // since this case has no score plugin, we'll only try to find one node in Filter stage
@ -2437,7 +2533,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin), tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, },
nodes: []string{"1", "2"}, nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "1", Labels: map[string]string{"kubernetes.io/hostname": "1"}}}, {ObjectMeta: metav1.ObjectMeta{Name: "2", Labels: map[string]string{"kubernetes.io/hostname": "2"}}},
},
pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(), pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
wantNodes: nil, wantNodes: nil,
wErr: &framework.FitError{ wErr: &framework.FitError{
@ -2449,6 +2547,50 @@ func TestSchedulerSchedulePod(t *testing.T) {
}, },
}, },
}, },
{
registerPlugins: []tf.RegisterPluginFunc{
tf.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
tf.RegisterPreFilterPlugin(volumebinding.Name, frameworkruntime.FactoryAdapter(fts, volumebinding.New)),
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
},
nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"kubernetes.io/hostname": "host1"}}},
},
pvcs: []v1.PersistentVolumeClaim{
{
ObjectMeta: metav1.ObjectMeta{Name: "PVC1", UID: types.UID("PVC1"), Namespace: v1.NamespaceDefault},
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "PV1"},
},
},
pvs: []v1.PersistentVolume{
{
ObjectMeta: metav1.ObjectMeta{Name: "PV1", UID: types.UID("PV1")},
Spec: v1.PersistentVolumeSpec{
NodeAffinity: &v1.VolumeNodeAffinity{
Required: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: []v1.NodeSelectorRequirement{
{
Key: "kubernetes.io/hostname",
Operator: v1.NodeSelectorOpIn,
Values: []string{"host1"},
},
},
},
},
},
},
},
},
},
pod: st.MakePod().Name("pod1").UID("pod1").Namespace(v1.NamespaceDefault).PVC("PVC1").Obj(),
wantNodes: sets.New("node1"),
name: "hostname and nodename of the node do not match",
wErr: nil,
},
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
@ -2461,8 +2603,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
cache.AddPod(logger, pod) cache.AddPod(logger, pod)
} }
var nodes []*v1.Node var nodes []*v1.Node
for _, name := range test.nodes { for _, node := range test.nodes {
node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: name, Labels: map[string]string{"hostname": name}}}
nodes = append(nodes, node) nodes = append(nodes, node)
cache.AddNode(logger, node) cache.AddNode(logger, node)
} }
@ -2472,10 +2613,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
for _, pvc := range test.pvcs { for _, pvc := range test.pvcs {
metav1.SetMetaDataAnnotation(&pvc.ObjectMeta, volume.AnnBindCompleted, "true") metav1.SetMetaDataAnnotation(&pvc.ObjectMeta, volume.AnnBindCompleted, "true")
cs.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(ctx, &pvc, metav1.CreateOptions{}) cs.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(ctx, &pvc, metav1.CreateOptions{})
if pvName := pvc.Spec.VolumeName; pvName != "" {
pv := v1.PersistentVolume{ObjectMeta: metav1.ObjectMeta{Name: pvName}}
cs.CoreV1().PersistentVolumes().Create(ctx, &pv, metav1.CreateOptions{})
} }
for _, pv := range test.pvs {
_, _ = cs.CoreV1().PersistentVolumes().Create(ctx, &pv, metav1.CreateOptions{})
} }
snapshot := internalcache.NewSnapshot(test.pods, nodes) snapshot := internalcache.NewSnapshot(test.pods, nodes)
fwk, err := tf.NewFramework( fwk, err := tf.NewFramework(