mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
tests for nodes with different nodeName and name
This commit is contained in:
parent
b1c9d7eb07
commit
f086227208
@ -1798,8 +1798,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
name string
|
||||
registerPlugins []tf.RegisterPluginFunc
|
||||
extenders []tf.FakeExtender
|
||||
nodes []string
|
||||
nodes []*v1.Node
|
||||
pvcs []v1.PersistentVolumeClaim
|
||||
pvs []v1.PersistentVolume
|
||||
pod *v1.Pod
|
||||
pods []*v1.Pod
|
||||
wantNodes sets.Set[string]
|
||||
@ -1812,7 +1813,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("FalseFilter", tf.NewFalseFilterPlugin),
|
||||
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(),
|
||||
name: "test 1",
|
||||
wErr: &framework.FitError{
|
||||
@ -1834,7 +1838,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: sets.New("node1", "node2"),
|
||||
name: "test 2",
|
||||
@ -1847,7 +1854,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("MatchFilter", tf.NewMatchFilterPlugin),
|
||||
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(),
|
||||
wantNodes: sets.New("node2"),
|
||||
name: "test 3",
|
||||
@ -1860,7 +1870,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: sets.New("3"),
|
||||
name: "test 4",
|
||||
@ -1873,7 +1887,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: sets.New("2"),
|
||||
name: "test 5",
|
||||
@ -1887,7 +1905,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("ReverseNumericMap", newReverseNumericMapPlugin(), 2),
|
||||
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(),
|
||||
wantNodes: sets.New("1"),
|
||||
name: "test 6",
|
||||
@ -1901,7 +1923,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
name: "test 7",
|
||||
wErr: &framework.FitError{
|
||||
@ -1929,7 +1955,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
st.MakePod().Name("2").UID("2").Node("2").Phase(v1.PodRunning).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",
|
||||
wErr: &framework.FitError{
|
||||
Pod: st.MakePod().Name("2").UID("2").Obj(),
|
||||
@ -1952,13 +1981,19 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
|
||||
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},
|
||||
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(),
|
||||
wantNodes: sets.New("node1", "node2"),
|
||||
name: "existing PVC",
|
||||
@ -1972,7 +2007,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
|
||||
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(),
|
||||
name: "unknown PVC",
|
||||
wErr: &framework.FitError{
|
||||
@ -1996,7 +2034,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
|
||||
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{}}}},
|
||||
pod: st.MakePod().Name("ignore").UID("ignore").Namespace(v1.NamespaceDefault).PVC("existingPVC").Obj(),
|
||||
name: "deleted PVC",
|
||||
@ -2021,7 +2062,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("TrueMap", newTrueMapPlugin(), 2),
|
||||
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(),
|
||||
name: "test error with priority map",
|
||||
wErr: fmt.Errorf("running Score plugins: %w", fmt.Errorf(`plugin "FalseMap" failed with: %w`, errPrioritize)),
|
||||
@ -2038,8 +2082,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
|
||||
},
|
||||
nodes: []string{"node1", "node2"},
|
||||
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(1, "hostname", v1.DoNotSchedule, &metav1.LabelSelector{
|
||||
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("p").UID("p").Label("foo", "").SpreadConstraint(1, "kubernetes.io/hostname", v1.DoNotSchedule, &metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "foo",
|
||||
@ -2066,8 +2113,12 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
|
||||
tf.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
|
||||
},
|
||||
nodes: []string{"node1", "node2", "node3"},
|
||||
pod: st.MakePod().Name("p").UID("p").Label("foo", "").SpreadConstraint(2, "hostname", v1.DoNotSchedule, &metav1.LabelSelector{
|
||||
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("p").UID("p").Label("foo", "").SpreadConstraint(2, "kubernetes.io/hostname", v1.DoNotSchedule, &metav1.LabelSelector{
|
||||
MatchExpressions: []metav1.LabelSelectorRequirement{
|
||||
{
|
||||
Key: "foo",
|
||||
@ -2094,7 +2145,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: &framework.FitError{
|
||||
@ -2125,7 +2178,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: &framework.FitError{
|
||||
@ -2152,7 +2209,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: &framework.FitError{
|
||||
@ -2177,7 +2236,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("NumericMap", newNumericMapPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: nil,
|
||||
@ -2192,7 +2254,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: &framework.FitError{
|
||||
@ -2218,7 +2283,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: fmt.Errorf(`running PreFilter plugin "FakePreFilter": %w`, errors.New("injected error status")),
|
||||
@ -2241,9 +2309,14 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wantNodes: sets.New("node2"),
|
||||
// since this case has no score plugin, we'll only try to find one node in Filter stage
|
||||
wantEvaluatedNodes: ptr.To[int32](1),
|
||||
},
|
||||
{
|
||||
@ -2264,7 +2337,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wErr: &framework.FitError{
|
||||
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
|
||||
@ -2294,7 +2371,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wErr: &framework.FitError{
|
||||
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
|
||||
@ -2322,7 +2401,10 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wErr: &framework.FitError{
|
||||
Pod: st.MakePod().Name("test-prefilter").UID("test-prefilter").Obj(),
|
||||
@ -2368,7 +2450,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterScorePlugin("EqualPrioritizerPlugin", tf.NewEqualPrioritizerPlugin(), 1),
|
||||
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(),
|
||||
wantNodes: sets.New("node2", "node3"),
|
||||
wantEvaluatedNodes: ptr.To[int32](3),
|
||||
@ -2384,7 +2470,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"),
|
||||
), "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(),
|
||||
wantNodes: sets.New("node1", "node2"),
|
||||
},
|
||||
@ -2395,7 +2484,11 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
|
||||
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(),
|
||||
wantNodes: sets.New("node1", "node2", "node3"),
|
||||
wantEvaluatedNodes: ptr.To[int32](1),
|
||||
@ -2410,9 +2503,14 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
),
|
||||
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(),
|
||||
wantNodes: sets.New("node1", "node2"),
|
||||
// since this case has no score plugin, we'll only try to find one node in Filter stage
|
||||
wantEvaluatedNodes: ptr.To[int32](1),
|
||||
},
|
||||
{
|
||||
@ -2428,7 +2526,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
tf.RegisterFilterPlugin("TrueFilter", tf.NewTrueFilterPlugin),
|
||||
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(),
|
||||
wantNodes: nil,
|
||||
wErr: &framework.FitError{
|
||||
@ -2439,6 +2539,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 {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@ -2451,8 +2595,7 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
cache.AddPod(logger, pod)
|
||||
}
|
||||
var nodes []*v1.Node
|
||||
for _, name := range test.nodes {
|
||||
node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: name, Labels: map[string]string{"hostname": name}}}
|
||||
for _, node := range test.nodes {
|
||||
nodes = append(nodes, node)
|
||||
cache.AddNode(logger, node)
|
||||
}
|
||||
@ -2462,10 +2605,9 @@ func TestSchedulerSchedulePod(t *testing.T) {
|
||||
for _, pvc := range test.pvcs {
|
||||
metav1.SetMetaDataAnnotation(&pvc.ObjectMeta, volume.AnnBindCompleted, "true")
|
||||
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)
|
||||
fwk, err := tf.NewFramework(
|
||||
|
Loading…
Reference in New Issue
Block a user