From 5ddb1be59a5c614524b8123b0774dad72ee3daf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E6=8C=AF=E5=85=B410069964?= Date: Fri, 9 Apr 2021 15:31:32 +0800 Subject: [PATCH] code cleanup for pkg/scheduler --- pkg/scheduler/apis/config/v1beta1/defaults.go | 3 +-- pkg/scheduler/framework/plugins/nodevolumelimits/csi.go | 2 +- pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go | 2 +- .../framework/plugins/selectorspread/selector_spread.go | 3 +-- pkg/scheduler/framework/plugins/volumezone/volume_zone.go | 6 +++--- pkg/scheduler/internal/queue/scheduling_queue.go | 6 +++--- pkg/scheduler/internal/queue/scheduling_queue_test.go | 3 +-- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/scheduler/apis/config/v1beta1/defaults.go b/pkg/scheduler/apis/config/v1beta1/defaults.go index 2771ba42033..dd2a436b037 100644 --- a/pkg/scheduler/apis/config/v1beta1/defaults.go +++ b/pkg/scheduler/apis/config/v1beta1/defaults.go @@ -21,7 +21,6 @@ import ( "strconv" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/util/feature" componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1" @@ -53,7 +52,7 @@ func SetDefaults_KubeSchedulerConfiguration(obj *v1beta1.KubeSchedulerConfigurat // Only apply a default scheduler name when there is a single profile. // Validation will ensure that every profile has a non-empty unique name. if len(obj.Profiles) == 1 && obj.Profiles[0].SchedulerName == nil { - obj.Profiles[0].SchedulerName = pointer.StringPtr(v1.DefaultSchedulerName) + obj.Profiles[0].SchedulerName = pointer.StringPtr(corev1.DefaultSchedulerName) } // For Healthz and Metrics bind addresses, we want to check: diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go index e911a0a4a92..15895a0acc9 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go @@ -75,7 +75,7 @@ func (pl *CSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod *v node := nodeInfo.Node() if node == nil { - return framework.NewStatus(framework.Error, fmt.Sprintf("node not found")) + return framework.NewStatus(framework.Error, "node not found") } // If CSINode doesn't exist, the predicate may read the limits from Node object diff --git a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go index 475d5f11c40..f0ea1bce0bc 100644 --- a/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go +++ b/pkg/scheduler/framework/plugins/nodevolumelimits/non_csi.go @@ -215,7 +215,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod node := nodeInfo.Node() if node == nil { - return framework.NewStatus(framework.Error, fmt.Sprintf("node not found")) + return framework.NewStatus(framework.Error, "node not found") } var csiNode *storage.CSINode diff --git a/pkg/scheduler/framework/plugins/selectorspread/selector_spread.go b/pkg/scheduler/framework/plugins/selectorspread/selector_spread.go index 402c1ce69fe..6a8d04f7b26 100644 --- a/pkg/scheduler/framework/plugins/selectorspread/selector_spread.go +++ b/pkg/scheduler/framework/plugins/selectorspread/selector_spread.go @@ -181,8 +181,7 @@ func (pl *SelectorSpread) PreScore(ctx context.Context, cycleState *framework.Cy if skipSelectorSpread(pod) { return nil } - var selector labels.Selector - selector = helper.DefaultSelector( + selector := helper.DefaultSelector( pod, pl.services, pl.replicationControllers, diff --git a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go index 91fb62e9aac..b50baf6e811 100644 --- a/pkg/scheduler/framework/plugins/volumezone/volume_zone.go +++ b/pkg/scheduler/framework/plugins/volumezone/volume_zone.go @@ -123,7 +123,7 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * if pvName == "" { scName := storagehelpers.GetPersistentVolumeClaimClass(pvc) if len(scName) == 0 { - return framework.NewStatus(framework.Error, fmt.Sprint("PersistentVolumeClaim had no pv name and storageClass name")) + return framework.NewStatus(framework.Error, "PersistentVolumeClaim had no pv name and storageClass name") } class, _ := pl.scLister.Get(scName) @@ -139,7 +139,7 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * continue } - return framework.NewStatus(framework.Error, fmt.Sprint("PersistentVolume had no name")) + return framework.NewStatus(framework.Error, "PersistentVolume had no name") } pv, err := pl.pvLister.Get(pvName) @@ -155,7 +155,7 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod * if !volumeZoneLabels.Has(k) { continue } - nodeV, _ := nodeConstraints[k] + nodeV := nodeConstraints[k] volumeVSet, err := volumehelpers.LabelZonesToSet(v) if err != nil { klog.InfoS("Failed to parse label, ignoring the label", "label", fmt.Sprintf("%s:%s", k, v), "err", err) diff --git a/pkg/scheduler/internal/queue/scheduling_queue.go b/pkg/scheduler/internal/queue/scheduling_queue.go index 12ea0fef52a..c711fb907cc 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue.go +++ b/pkg/scheduler/internal/queue/scheduling_queue.go @@ -31,7 +31,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/labels" - ktypes "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -773,7 +773,7 @@ type nominatedPodMap struct { nominatedPods map[string][]*framework.PodInfo // nominatedPodToNode is map keyed by a Pod UID to the node name where it is // nominated. - nominatedPodToNode map[ktypes.UID]string + nominatedPodToNode map[types.UID]string sync.RWMutex } @@ -845,7 +845,7 @@ func (npm *nominatedPodMap) UpdateNominatedPod(oldPod *v1.Pod, newPodInfo *frame func NewPodNominator() framework.PodNominator { return &nominatedPodMap{ nominatedPods: make(map[string][]*framework.PodInfo), - nominatedPodToNode: make(map[ktypes.UID]string), + nominatedPodToNode: make(map[types.UID]string), } } diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index 1c14b872671..8bd7601e3f3 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -30,7 +30,6 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/clock" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/component-base/metrics/testutil" @@ -1670,7 +1669,7 @@ func TestBackOffFlow(t *testing.T) { }, } - podID := ktypes.NamespacedName{ + podID := types.NamespacedName{ Namespace: pod.Namespace, Name: pod.Name, }