Skip to content

Commit

Permalink
Return UnschedulableAndUnresolvable when looking up volume-related re…
Browse files Browse the repository at this point in the history
…sources returns NotFound error
  • Loading branch information
ahg-g committed Jun 2, 2021
1 parent e160aa0 commit ef655bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/scheduler/framework/fake/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion pkg/scheduler/framework/fake/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/scheduler/framework/plugins/volumezone/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 17 additions & 7 deletions pkg/scheduler/framework/plugins/volumezone/volume_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit ef655bd

Please sign in to comment.