@@ -98,6 +98,8 @@ func TestCreateFromConfig(t *testing.T) {
98
98
],
99
99
"priorities" : [
100
100
{"name" : "RackSpread", "weight" : 3, "argument" : {"serviceAntiAffinity" : {"label" : "rack"}}},
101
+ {"name" : "LabelPreference1", "weight" : 3, "argument" : {"labelPreference" : {"label" : "l1", "presence": true}}},
102
+ {"name" : "LabelPreference2", "weight" : 3, "argument" : {"labelPreference" : {"label" : "l2", "presence": false}}},
101
103
{"name" : "PriorityOne", "weight" : 2},
102
104
{"name" : "PriorityTwo", "weight" : 1} ]
103
105
}` )
@@ -114,29 +116,36 @@ func TestCreateFromConfig(t *testing.T) {
114
116
t .Errorf ("Wrong hardPodAffinitySymmetricWeight, ecpected: %d, got: %d" , v1 .DefaultHardPodAffinitySymmetricWeight , hpa )
115
117
}
116
118
117
- // Verify that custom predicates are converted to framework plugins.
118
- if ! pluginExists (nodelabel .Name , "FilterPlugin" , conf ) {
119
- t .Error ("NodeLabel plugin not exist in framework." )
119
+ // Verify that node label predicate/priority are converted to framework plugins.
120
+ if _ , ok := findPlugin (nodelabel .Name , "FilterPlugin" , conf ); ! ok {
121
+ t .Fatalf ("NodeLabel plugin not exist in framework." )
120
122
}
121
- // Verify that the policy config is converted to plugin config for custom predicates.
123
+ nodeLabelScorePlugin , ok := findPlugin (nodelabel .Name , "ScorePlugin" , conf )
124
+ if ! ok {
125
+ t .Fatalf ("NodeLabel plugin not exist in framework." )
126
+ }
127
+ if nodeLabelScorePlugin .Weight != 6 {
128
+ t .Errorf ("Wrong weight. Got: %v, want: 6" , nodeLabelScorePlugin .Weight )
129
+ }
130
+ // Verify that the policy config is converted to plugin config for node label predicate/priority.
122
131
nodeLabelConfig := findPluginConfig (nodelabel .Name , conf )
123
132
encoding , err := json .Marshal (nodeLabelConfig )
124
133
if err != nil {
125
134
t .Errorf ("Failed to marshal %+v: %v" , nodeLabelConfig , err )
126
135
}
127
- want := `{"Name":"NodeLabel","Args":{"presentLabels":["zone"],"absentLabels":["foo"]}}`
136
+ want := `{"Name":"NodeLabel","Args":{"presentLabels":["zone"],"absentLabels":["foo"],"presentLabelsPreference":["l1"],"absentLabelsPreference":["l2"] }}`
128
137
if string (encoding ) != want {
129
138
t .Errorf ("Config for NodeLabel plugin mismatch. got: %v, want: %v" , string (encoding ), want )
130
139
}
131
140
}
132
141
133
- func pluginExists (name , extensionPoint string , schedConf * Config ) bool {
142
+ func findPlugin (name , extensionPoint string , schedConf * Config ) (schedulerapi. Plugin , bool ) {
134
143
for _ , pl := range schedConf .Framework .ListPlugins ()[extensionPoint ] {
135
144
if pl .Name == name {
136
- return true
145
+ return pl , true
137
146
}
138
147
}
139
- return false
148
+ return schedulerapi. Plugin {}, false
140
149
}
141
150
142
151
func findPluginConfig (name string , schedConf * Config ) schedulerapi.PluginConfig {
0 commit comments