-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
koord-scheduler: implemented PreBindExtensions to support one-time co…
…mmit patches Signed-off-by: Joseph <joseph.t.lee@outlook.com>
- Loading branch information
Showing
18 changed files
with
689 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package defaultprofile | ||
|
||
import ( | ||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" | ||
|
||
"github.com/koordinator-sh/koordinator/pkg/scheduler/plugins/defaultprebind" | ||
) | ||
|
||
func AppendDefaultPlugins(profiles []kubeschedulerconfig.KubeSchedulerProfile) { | ||
for i := range profiles { | ||
p := &profiles[i] | ||
|
||
if p.Plugins == nil { | ||
continue | ||
} | ||
|
||
hasDisabled := false | ||
for _, disabled := range p.Plugins.PreBind.Disabled { | ||
if disabled.Name == "*" || disabled.Name == defaultprebind.Name { | ||
hasDisabled = true | ||
break | ||
} | ||
} | ||
|
||
found := false | ||
for _, enabled := range p.Plugins.PreBind.Enabled { | ||
if enabled.Name == defaultprebind.Name { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found && !hasDisabled { | ||
p.Plugins.PreBind.Enabled = append(p.Plugins.PreBind.Enabled, kubeschedulerconfig.Plugin{ | ||
Name: defaultprebind.Name, | ||
}) | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
pkg/scheduler/frameworkext/defaultprofile/profile_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package defaultprofile | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" | ||
|
||
"github.com/koordinator-sh/koordinator/pkg/scheduler/plugins/defaultprebind" | ||
) | ||
|
||
func TestAppendDefaultPlugins(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
profiles []kubeschedulerconfig.KubeSchedulerProfile | ||
wantProfiles []kubeschedulerconfig.KubeSchedulerProfile | ||
}{ | ||
{ | ||
name: "empty profile", | ||
profiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{}, | ||
}, | ||
wantProfiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{}, | ||
}, | ||
}, | ||
{ | ||
name: "append defaultPreBindExtension plugin", | ||
profiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{}, | ||
}, | ||
}, | ||
wantProfiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{ | ||
PreBind: kubeschedulerconfig.PluginSet{ | ||
Enabled: []kubeschedulerconfig.Plugin{ | ||
{ | ||
Name: defaultprebind.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "disable defaultPreBindExtension plugin", | ||
profiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{ | ||
PreBind: kubeschedulerconfig.PluginSet{ | ||
Disabled: []kubeschedulerconfig.Plugin{ | ||
{ | ||
Name: defaultprebind.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantProfiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{ | ||
PreBind: kubeschedulerconfig.PluginSet{ | ||
Disabled: []kubeschedulerconfig.Plugin{ | ||
{ | ||
Name: defaultprebind.Name, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "disable all prebind plugins", | ||
profiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{ | ||
PreBind: kubeschedulerconfig.PluginSet{ | ||
Disabled: []kubeschedulerconfig.Plugin{ | ||
{ | ||
Name: "*", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantProfiles: []kubeschedulerconfig.KubeSchedulerProfile{ | ||
{ | ||
Plugins: &kubeschedulerconfig.Plugins{ | ||
PreBind: kubeschedulerconfig.PluginSet{ | ||
Disabled: []kubeschedulerconfig.Plugin{ | ||
{ | ||
Name: "*", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
AppendDefaultPlugins(tt.profiles) | ||
assert.Equal(t, tt.wantProfiles, tt.profiles) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.