refactor volume binder

This commit is contained in:
louisgong
2020-02-21 16:35:58 +08:00
parent a54e1a8a04
commit c6b94e4606
14 changed files with 71 additions and 157 deletions

View File

@@ -6,9 +6,9 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding",
visibility = ["//visibility:public"],
deps = [
"//pkg/controller/volume/scheduling:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library",
"//pkg/scheduler/volumebinder:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
],
@@ -36,7 +36,6 @@ go_test(
"//pkg/controller/volume/scheduling:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library",
"//pkg/scheduler/volumebinder:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
],
)

View File

@@ -21,14 +21,14 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
)
// VolumeBinding is a plugin that binds pod volumes in scheduling.
type VolumeBinding struct {
binder *volumebinder.VolumeBinder
binder scheduling.SchedulerVolumeBinder
}
var _ framework.FilterPlugin = &VolumeBinding{}
@@ -72,7 +72,7 @@ func (pl *VolumeBinding) Filter(ctx context.Context, cs *framework.CycleState, p
return nil
}
reasons, err := pl.binder.Binder.FindPodVolumes(pod, node)
reasons, err := pl.binder.FindPodVolumes(pod, node)
if err != nil {
return framework.NewStatus(framework.Error, err.Error())

View File

@@ -23,10 +23,9 @@ import (
"testing"
v1 "k8s.io/api/core/v1"
volumescheduling "k8s.io/kubernetes/pkg/controller/volume/scheduling"
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
)
func TestVolumeBinding(t *testing.T) {
@@ -44,7 +43,7 @@ func TestVolumeBinding(t *testing.T) {
name string
pod *v1.Pod
node *v1.Node
volumeBinderConfig *volumescheduling.FakeVolumeBinderConfig
volumeBinderConfig *scheduling.FakeVolumeBinderConfig
wantStatus *framework.Status
}{
{
@@ -57,7 +56,7 @@ func TestVolumeBinding(t *testing.T) {
name: "all bound",
pod: &v1.Pod{Spec: volState},
node: &v1.Node{},
volumeBinderConfig: &volumescheduling.FakeVolumeBinderConfig{
volumeBinderConfig: &scheduling.FakeVolumeBinderConfig{
AllBound: true,
},
wantStatus: nil,
@@ -66,32 +65,32 @@ func TestVolumeBinding(t *testing.T) {
name: "unbound/no matches",
pod: &v1.Pod{Spec: volState},
node: &v1.Node{},
volumeBinderConfig: &volumescheduling.FakeVolumeBinderConfig{
FindReasons: []volumescheduling.ConflictReason{volumescheduling.ErrReasonBindConflict},
volumeBinderConfig: &scheduling.FakeVolumeBinderConfig{
FindReasons: []scheduling.ConflictReason{scheduling.ErrReasonBindConflict},
},
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(volumescheduling.ErrReasonBindConflict)),
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonBindConflict)),
},
{
name: "bound and unbound unsatisfied",
pod: &v1.Pod{Spec: volState},
node: &v1.Node{},
volumeBinderConfig: &volumescheduling.FakeVolumeBinderConfig{
FindReasons: []volumescheduling.ConflictReason{volumescheduling.ErrReasonBindConflict, volumescheduling.ErrReasonNodeConflict},
volumeBinderConfig: &scheduling.FakeVolumeBinderConfig{
FindReasons: []scheduling.ConflictReason{scheduling.ErrReasonBindConflict, scheduling.ErrReasonNodeConflict},
},
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(volumescheduling.ErrReasonBindConflict), string(volumescheduling.ErrReasonNodeConflict)),
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, string(scheduling.ErrReasonBindConflict), string(scheduling.ErrReasonNodeConflict)),
},
{
name: "unbound/found matches/bind succeeds",
pod: &v1.Pod{Spec: volState},
node: &v1.Node{},
volumeBinderConfig: &volumescheduling.FakeVolumeBinderConfig{},
volumeBinderConfig: &scheduling.FakeVolumeBinderConfig{},
wantStatus: nil,
},
{
name: "predicate error",
pod: &v1.Pod{Spec: volState},
node: &v1.Node{},
volumeBinderConfig: &volumescheduling.FakeVolumeBinderConfig{
volumeBinderConfig: &scheduling.FakeVolumeBinderConfig{
FindErr: findErr,
},
wantStatus: framework.NewStatus(framework.Error, findErr.Error()),
@@ -102,7 +101,7 @@ func TestVolumeBinding(t *testing.T) {
t.Run(item.name, func(t *testing.T) {
nodeInfo := schedulernodeinfo.NewNodeInfo()
nodeInfo.SetNode(item.node)
fakeVolumeBinder := volumebinder.NewFakeVolumeBinder(item.volumeBinderConfig)
fakeVolumeBinder := scheduling.NewFakeVolumeBinder(item.volumeBinderConfig)
p := &VolumeBinding{
binder: fakeVolumeBinder,
}