diff --git a/pkg/scheduler/framework/fake/BUILD b/pkg/scheduler/framework/fake/BUILD index 7ee990b183386..724d771527485 100644 --- a/pkg/scheduler/framework/fake/BUILD +++ b/pkg/scheduler/framework/fake/BUILD @@ -10,6 +10,7 @@ go_library( "//staging/src/k8s.io/api/apps/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/client-go/listers/apps/v1:go_default_library", diff --git a/pkg/scheduler/framework/fake/listers.go b/pkg/scheduler/framework/fake/listers.go index 0352bf3821783..1b4482fa3d249 100644 --- a/pkg/scheduler/framework/fake/listers.go +++ b/pkg/scheduler/framework/fake/listers.go @@ -22,6 +22,7 @@ import ( appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" appslisters "k8s.io/client-go/listers/apps/v1" @@ -311,7 +312,12 @@ func (classes StorageClassLister) Get(name string) (*storagev1.StorageClass, err return &sc, nil } } - return nil, fmt.Errorf("unable to find storage class: %s", name) + return nil, &errors.StatusError{ + ErrStatus: metav1.Status{ + Reason: metav1.StatusReasonNotFound, + Message: fmt.Sprintf("unable to find storage class: %s", name), + }, + } } // List lists all StorageClass in the indexer. diff --git a/pkg/scheduler/framework/plugins/volumezone/BUILD b/pkg/scheduler/framework/plugins/volumezone/BUILD index 6d04f475f1694..5c8c283795cf9 100644 --- a/pkg/scheduler/framework/plugins/volumezone/BUILD +++ b/pkg/scheduler/framework/plugins/volumezone/BUILD @@ -10,6 +10,7 @@ go_library( "//pkg/scheduler/framework:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/client-go/listers/core/v1:go_default_library", diff --git a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go index b190dfb2b97fa..02fd1046328c3 100644 --- a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go +++ b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go @@ -22,6 +22,7 @@ import ( v1 "k8s.io/api/core/v1" storage "k8s.io/api/storage/v1" + "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" corelisters "k8s.io/client-go/listers/core/v1" @@ -111,8 +112,8 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * return framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolumeClaim had no name") } pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName) - if err != nil { - return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) + if s := getErrorAsStatus(err); !s.IsSuccess() { + return s } pvName := pvc.Spec.VolumeName @@ -123,9 +124,8 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * } class, err := pl.scLister.Get(scName) - if err != nil { - return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) - + if s := getErrorAsStatus(err); !s.IsSuccess() { + return s } if class.VolumeBindingMode == nil { return framework.NewStatus(framework.UnschedulableAndUnresolvable, fmt.Sprintf("VolumeBindingMode not set for StorageClass %q", scName)) @@ -139,8 +139,8 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * } pv, err := pl.pvLister.Get(pvName) - if err != nil { - return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) + if s := getErrorAsStatus(err); !s.IsSuccess() { + return s } for k, v := range pv.ObjectMeta.Labels { @@ -163,6 +163,16 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * return nil } +func getErrorAsStatus(err error) *framework.Status { + if err != nil { + if errors.IsNotFound(err) { + return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error()) + } + return framework.AsStatus(err) + } + return nil +} + // New initializes a new plugin and returns it. func New(_ runtime.Object, handle framework.Handle) (framework.Plugin, error) { informerFactory := handle.SharedInformerFactory()