mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Merge pull request #106766 from kerthcet/feature/add-test-to-multipoint
add test to cover multipoint with scoring extension
This commit is contained in:
commit
8d8d3f03c0
@ -1263,25 +1263,26 @@ func (f *frameworkImpl) SharedInformerFactory() informers.SharedInformerFactory
|
|||||||
return f.informerFactory
|
return f.informerFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *frameworkImpl) pluginsNeeded(plugins *config.Plugins) map[string]config.Plugin {
|
func (f *frameworkImpl) pluginsNeeded(plugins *config.Plugins) sets.String {
|
||||||
pgMap := make(map[string]config.Plugin)
|
pgSet := sets.String{}
|
||||||
|
|
||||||
if plugins == nil {
|
if plugins == nil {
|
||||||
return pgMap
|
return pgSet
|
||||||
}
|
}
|
||||||
|
|
||||||
find := func(pgs *config.PluginSet) {
|
find := func(pgs *config.PluginSet) {
|
||||||
for _, pg := range pgs.Enabled {
|
for _, pg := range pgs.Enabled {
|
||||||
pgMap[pg.Name] = pg
|
pgSet.Insert(pg.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, e := range f.getExtensionPoints(plugins) {
|
for _, e := range f.getExtensionPoints(plugins) {
|
||||||
find(e.plugins)
|
find(e.plugins)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse MultiPoint separately since they are not returned by f.getExtensionPoints()
|
// Parse MultiPoint separately since they are not returned by f.getExtensionPoints()
|
||||||
find(&plugins.MultiPoint)
|
find(&plugins.MultiPoint)
|
||||||
return pgMap
|
|
||||||
|
return pgSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileName returns the profile name associated to this framework.
|
// ProfileName returns the profile name associated to this framework.
|
||||||
|
@ -338,6 +338,8 @@ var registry = func() Registry {
|
|||||||
r.Register(pluginNotImplementingScore, newPluginNotImplementingScore)
|
r.Register(pluginNotImplementingScore, newPluginNotImplementingScore)
|
||||||
r.Register(duplicatePluginName, newDuplicatePlugin)
|
r.Register(duplicatePluginName, newDuplicatePlugin)
|
||||||
r.Register(testPlugin, newTestPlugin)
|
r.Register(testPlugin, newTestPlugin)
|
||||||
|
r.Register(queueSortPlugin, newQueueSortPlugin)
|
||||||
|
r.Register(bindPlugin, newBindPlugin)
|
||||||
return r
|
return r
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -757,12 +759,19 @@ func TestNewFrameworkMultiPointExpansion(t *testing.T) {
|
|||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fw, err := NewFramework(registry, &config.KubeSchedulerProfile{Plugins: tc.plugins})
|
fw, err := NewFramework(registry, &config.KubeSchedulerProfile{Plugins: tc.plugins})
|
||||||
if (err != nil && tc.wantErr == "") || (err == nil && tc.wantErr != "") || (err != nil && !strings.Contains(err.Error(), tc.wantErr)) {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error, got %v, expect: %s", err, tc.wantErr)
|
if tc.wantErr == "" || !strings.Contains(err.Error(), tc.wantErr) {
|
||||||
|
t.Fatalf("Unexpected error, got %v, expect: %s", err, tc.wantErr)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if tc.wantErr != "" {
|
||||||
|
t.Fatalf("Unexpected error, got %v, expect: %s", err, tc.wantErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if tc.wantErr == "" {
|
if tc.wantErr == "" {
|
||||||
if diff := cmp.Diff(tc.wantPlugins, fw.ListPlugins()); diff != "" {
|
if diff := cmp.Diff(tc.wantPlugins, fw.ListPlugins()); diff != "" {
|
||||||
t.Errorf("Unexpected eventToPlugin map (-want,+got):%s", diff)
|
t.Fatalf("Unexpected eventToPlugin map (-want,+got):%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1083,6 +1092,33 @@ func TestRunScorePlugins(t *testing.T) {
|
|||||||
},
|
},
|
||||||
err: true,
|
err: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "single Score plugin with MultiPointExpansion",
|
||||||
|
plugins: &config.Plugins{
|
||||||
|
MultiPoint: config.PluginSet{
|
||||||
|
Enabled: []config.Plugin{
|
||||||
|
{Name: scorePlugin1},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Score: config.PluginSet{
|
||||||
|
Enabled: []config.Plugin{
|
||||||
|
{Name: scorePlugin1, Weight: 3},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pluginConfigs: []config.PluginConfig{
|
||||||
|
{
|
||||||
|
Name: scorePlugin1,
|
||||||
|
Args: &runtime.Unknown{
|
||||||
|
Raw: []byte(`{ "scoreRes": 1 }`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// scorePlugin1 Score returns 1, weight=3, so want=3.
|
||||||
|
want: framework.PluginToNodeScores{
|
||||||
|
scorePlugin1: {{Name: "node1", Score: 3}, {Name: "node2", Score: 3}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -1110,7 +1146,7 @@ func TestRunScorePlugins(t *testing.T) {
|
|||||||
t.Errorf("Expected status to be success.")
|
t.Errorf("Expected status to be success.")
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(res, tt.want) {
|
if !reflect.DeepEqual(res, tt.want) {
|
||||||
t.Errorf("Score map after RunScorePlugin: %+v, want: %+v.", res, tt.want)
|
t.Errorf("Score map after RunScorePlugin. got: %+v, want: %+v.", res, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user