From aba817ac1d689d9851a825c701a3806503075115 Mon Sep 17 00:00:00 2001 From: utam0k Date: Sun, 19 Nov 2023 15:21:29 +0900 Subject: [PATCH] return not-found errors properly from fake listeres Signed-off-by: utam0k --- .../framework/plugins/nodevolumelimits/csi_test.go | 4 ++-- .../plugins/nodevolumelimits/non_csi_test.go | 2 +- .../plugins/volumezone/volume_zone_test.go | 4 ++-- pkg/scheduler/testing/framework/fake_listers.go | 13 ++++--------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go b/pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go index 1207176abc5..c7a1c4c8d21 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go @@ -495,7 +495,7 @@ func TestCSILimits(t *testing.T) { ephemeralEnabled: true, driverNames: []string{ebsCSIDriverName}, test: "ephemeral volume missing", - wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaim "abc-xyz" not found`)), + wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaims "abc-xyz" not found`)), }, { newPod: ephemeralVolumePod, @@ -595,7 +595,7 @@ func TestCSILimits(t *testing.T) { ephemeralEnabled: true, driverNames: []string{ebsCSIDriverName}, test: "don't skip Filter when the pod has ephemeral volumes", - wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaim "abc-xyz" not found`)), + wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaims "abc-xyz" not found`)), }, { newPod: inlineMigratablePodWithConfigmapAndSecret, diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi_test.go b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi_test.go index c34dd9630af..fdb2c8b3fe0 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi_test.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi_test.go @@ -139,7 +139,7 @@ func TestEphemeralLimits(t *testing.T) { newPod: ephemeralVolumePod, ephemeralEnabled: true, test: "volume missing", - wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaim "abc-xyz" not found`)), + wantStatus: framework.AsStatus(errors.New(`looking up PVC test/abc-xyz: persistentvolumeclaims "abc-xyz" not found`)), }, { newPod: ephemeralVolumePod, diff --git a/pkg/scheduler/framework/plugins/volumezone/volume_zone_test.go b/pkg/scheduler/framework/plugins/volumezone/volume_zone_test.go index dfeb024153f..76d73a36495 100644 --- a/pkg/scheduler/framework/plugins/volumezone/volume_zone_test.go +++ b/pkg/scheduler/framework/plugins/volumezone/volume_zone_test.go @@ -494,9 +494,9 @@ func TestWithBinding(t *testing.T) { Pod: createPodWithVolume("pod_1", "vol_1", "PVC_NoSC"), Node: testNode, wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, - "unable to find storage class: Class_0"), + `storageclasses.storage.k8s.io "Class_0" not found`), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, - "unable to find storage class: Class_0"), + `storageclasses.storage.k8s.io "Class_0" not found`), }, { name: "unbound volume immediate binding mode", diff --git a/pkg/scheduler/testing/framework/fake_listers.go b/pkg/scheduler/testing/framework/fake_listers.go index 2135f68129b..fc2dd39788f 100644 --- a/pkg/scheduler/testing/framework/fake_listers.go +++ b/pkg/scheduler/testing/framework/fake_listers.go @@ -195,7 +195,7 @@ func (f *persistentVolumeClaimNamespaceLister) Get(name string) (*v1.PersistentV return pvc, nil } } - return nil, fmt.Errorf("persistentvolumeclaim %q not found", name) + return nil, errors.NewNotFound(v1.Resource("persistentvolumeclaims"), name) } func (f persistentVolumeClaimNamespaceLister) List(selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error) { @@ -266,7 +266,7 @@ func (n CSINodeLister) Get(name string) (*storagev1.CSINode, error) { return &cn, nil } } - return nil, fmt.Errorf("csiNode %q not found", name) + return nil, errors.NewNotFound(storagev1.Resource("csinodes"), name) } // List lists all CSINodes in the indexer. @@ -286,7 +286,7 @@ func (pvs PersistentVolumeLister) Get(pvID string) (*v1.PersistentVolume, error) return &pv, nil } } - return nil, fmt.Errorf("unable to find persistent volume: %s", pvID) + return nil, errors.NewNotFound(v1.Resource("persistentvolumes"), pvID) } // List lists all PersistentVolumes in the indexer. @@ -306,12 +306,7 @@ func (classes StorageClassLister) Get(name string) (*storagev1.StorageClass, err return &sc, nil } } - return nil, &errors.StatusError{ - ErrStatus: metav1.Status{ - Reason: metav1.StatusReasonNotFound, - Message: fmt.Sprintf("unable to find storage class: %s", name), - }, - } + return nil, errors.NewNotFound(storagev1.Resource("storageclasses"), name) } // List lists all StorageClass in the indexer.