From 5592c8a31430f077c50cfdb4bef85ff90e96113d Mon Sep 17 00:00:00 2001 From: rayoluo Date: Tue, 27 Jun 2023 20:11:32 +0800 Subject: [PATCH] fix some issues reported by golint Signed-off-by: rayoluo --- .../api/devices/nvidia/gpushare/device_info.go | 4 ++-- pkg/scheduler/api/devices/nvidia/vgpu/device_info.go | 4 ++-- pkg/scheduler/api/devices/nvidia/vgpu/type.go | 10 +++++----- pkg/scheduler/api/node_info.go | 7 ++++--- pkg/scheduler/framework/util.go | 2 +- pkg/scheduler/plugins/proportion/proportion_test.go | 6 +++--- .../admission/pods/mutate/mutate_pod_test.go | 6 +++--- test/e2e/jobp/job_lifecycle.go | 8 ++++---- test/e2e/jobseq/job_error_handling.go | 5 +++-- test/e2e/schedulingbase/sla.go | 12 ++++++------ test/e2e/util/job.go | 6 +++--- test/e2e/util/util.go | 3 ++- test/e2e/vcctl/command.go | 2 +- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/pkg/scheduler/api/devices/nvidia/gpushare/device_info.go b/pkg/scheduler/api/devices/nvidia/gpushare/device_info.go index 10e3144476..167139f0b3 100644 --- a/pkg/scheduler/api/devices/nvidia/gpushare/device_info.go +++ b/pkg/scheduler/api/devices/nvidia/gpushare/device_info.go @@ -94,7 +94,7 @@ func (gs *GPUDevices) GetIgnoredDevices() []string { return []string{""} } -// AddGPUResource adds the pod to GPU pool if it is assigned +// AddResource adds the pod to GPU pool if it is assigned func (gs *GPUDevices) AddResource(pod *v1.Pod) { gpuRes := getGPUMemoryOfPod(pod) if gpuRes > 0 { @@ -107,7 +107,7 @@ func (gs *GPUDevices) AddResource(pod *v1.Pod) { } } -// SubGPUResource frees the gpu hold by the pod +// SubResource frees the gpu hold by the pod func (gs *GPUDevices) SubResource(pod *v1.Pod) { gpuRes := getGPUMemoryOfPod(pod) if gpuRes > 0 { diff --git a/pkg/scheduler/api/devices/nvidia/vgpu/device_info.go b/pkg/scheduler/api/devices/nvidia/vgpu/device_info.go index 574f8c0c90..e956e1dafa 100644 --- a/pkg/scheduler/api/devices/nvidia/vgpu/device_info.go +++ b/pkg/scheduler/api/devices/nvidia/vgpu/device_info.go @@ -117,7 +117,7 @@ func (gs *GPUDevices) GetIgnoredDevices() []string { return []string{VolcanoVGPUMemory, VolcanoVGPUMemoryPercentage, VolcanoVGPUCores} } -// AddGPUResource adds the pod to GPU pool if it is assigned +// AddResource adds the pod to GPU pool if it is assigned func (gs *GPUDevices) AddResource(pod *v1.Pod) { ids, ok := pod.Annotations[AssignedIDsAnnotations] if !ok { @@ -141,7 +141,7 @@ func (gs *GPUDevices) AddResource(pod *v1.Pod) { } } -// SubGPUResource frees the gpu hold by the pod +// SubResource frees the gpu hold by the pod func (gs *GPUDevices) SubResource(pod *v1.Pod) { ids, ok := pod.Annotations[AssignedIDsAnnotations] if !ok { diff --git a/pkg/scheduler/api/devices/nvidia/vgpu/type.go b/pkg/scheduler/api/devices/nvidia/vgpu/type.go index 2884a61dd5..16544c5473 100644 --- a/pkg/scheduler/api/devices/nvidia/vgpu/type.go +++ b/pkg/scheduler/api/devices/nvidia/vgpu/type.go @@ -31,17 +31,17 @@ const ( NvidiaGPUDevice = "NVIDIA" - // VolcanoGPUMemory extended gpu memory + // VolcanoVGPUMemory extended gpu memory VolcanoVGPUMemory = "volcano.sh/vgpu-memory" - // VolcanoMemoryPercentage extends gpu memory + // VolcanoVGPUMemoryPercentage extends gpu memory VolcanoVGPUMemoryPercentage = "volcano.sh/vgpu-memory-percentage" - // VolcanoVGPUcores indicates utilization percentage of vgpu + // VolcanoVGPUCores indicates utilization percentage of vgpu VolcanoVGPUCores = "volcano.sh/vgpu-cores" - // VolcanoGPUNumber virtual GPU card number + // VolcanoVGPUNumber virtual GPU card number VolcanoVGPUNumber = "volcano.sh/vgpu-number" // VolcanoVGPURegister virtual gpu information registered from device-plugin to scheduler VolcanoVGPURegister = "volcano.sh/node-vgpu-register" - // Volcanohandshake for vgpu + // VolcanoVGPUHandshake for vgpu VolcanoVGPUHandshake = "volcano.sh/node-vgpu-handshake" // PredicateTime is the key of predicate time diff --git a/pkg/scheduler/api/node_info.go b/pkg/scheduler/api/node_info.go index c5e20c95b6..ae1585415a 100644 --- a/pkg/scheduler/api/node_info.go +++ b/pkg/scheduler/api/node_info.go @@ -25,6 +25,7 @@ import ( k8sframework "k8s.io/kubernetes/pkg/scheduler/framework" "volcano.sh/apis/pkg/apis/scheduling/v1beta1" + "volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/gpushare" "volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/vgpu" ) @@ -213,7 +214,7 @@ func (ni *NodeInfo) Clone() *NodeInfo { klog.V(5).Infof("imageStates is %v", res.ImageStates) res.Others = ni.CloneOthers() - res.ImageStates = ni.CloneImageSumary() + res.ImageStates = ni.CloneImageSummary() return res } @@ -539,8 +540,8 @@ func (ni *NodeInfo) Pods() (pods []*v1.Pod) { return } -// Clone Image State -func (ni *NodeInfo) CloneImageSumary() map[string]*k8sframework.ImageStateSummary { +// CloneImageSummary Clone Image State +func (ni *NodeInfo) CloneImageSummary() map[string]*k8sframework.ImageStateSummary { nodeImageStates := make(map[string]*k8sframework.ImageStateSummary) for imageName, summary := range ni.ImageStates { newImageSummary := &k8sframework.ImageStateSummary{ diff --git a/pkg/scheduler/framework/util.go b/pkg/scheduler/framework/util.go index ee6fad607a..0528c9dba5 100644 --- a/pkg/scheduler/framework/util.go +++ b/pkg/scheduler/framework/util.go @@ -230,7 +230,7 @@ func GenerateNodeMapAndSlice(nodes map[string]*api.NodeInfo) map[string]*schedul nodeInfo.SetNode(node.Node) nodeMap[node.Name] = nodeInfo // add imagestate into nodeinfo - nodeMap[node.Name].ImageStates = node.CloneImageSumary() + nodeMap[node.Name].ImageStates = node.CloneImageSummary() } return nodeMap } diff --git a/pkg/scheduler/plugins/proportion/proportion_test.go b/pkg/scheduler/plugins/proportion/proportion_test.go index e5199882a9..f7b4398b5c 100644 --- a/pkg/scheduler/plugins/proportion/proportion_test.go +++ b/pkg/scheduler/plugins/proportion/proportion_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/util/workqueue" schedulingv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1" + "volcano.sh/volcano/cmd/scheduler/app/options" "volcano.sh/volcano/pkg/scheduler/actions/allocate" "volcano.sh/volcano/pkg/scheduler/api" @@ -282,10 +283,9 @@ func TestProportion(t *testing.T) { t.Errorf("after delete vcjob pg2, queue_allocated metrics is fail,%v", metrics) c <- false return - } else { - t.Logf("after delete vcjob pg2, queue_allocated metrics is ok,%v", metrics) - c <- true } + t.Logf("after delete vcjob pg2, queue_allocated metrics is ok,%v", metrics) + c <- true } num++ } diff --git a/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go b/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go index 869327cb53..f964ee8372 100644 --- a/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go +++ b/pkg/webhooks/admission/pods/mutate/mutate_pod_test.go @@ -28,9 +28,9 @@ import ( ) func TestMutatePods(t *testing.T) { - affinityJsonStr := `{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"kubernetes.io/os","operator":"In","values":["linux"]}]}]}}}` + affinityJSONStr := `{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"kubernetes.io/os","operator":"In","values":["linux"]}]}]}}}` var affinity v1.Affinity - json.Unmarshal([]byte(affinityJsonStr), &affinity) + json.Unmarshal([]byte(affinityJSONStr), &affinity) admissionConfigData := &webconfig.AdmissionConfiguration{ ResGroupsConfig: []webconfig.ResGroupConfig{ @@ -51,7 +51,7 @@ func TestMutatePods(t *testing.T) { Effect: v1.TaintEffectNoSchedule, }, }, - Affinity: affinityJsonStr, + Affinity: affinityJSONStr, Labels: map[string]string{ "volcano.sh/nodetype": "management", }, diff --git a/test/e2e/jobp/job_lifecycle.go b/test/e2e/jobp/job_lifecycle.go index f9682ce8de..3ea44de6b7 100644 --- a/test/e2e/jobp/job_lifecycle.go +++ b/test/e2e/jobp/job_lifecycle.go @@ -45,7 +45,7 @@ var _ = Describe("Job Life Cycle", func() { Img: e2eutil.DefaultNginxImage, Min: 2, Rep: 2, - Req: e2eutil.CpuResource("10000"), + Req: e2eutil.CPUResource("10000"), }, }, }) @@ -222,7 +222,7 @@ var _ = Describe("Job Life Cycle", func() { Rep: 1, Command: "sleep 10s", RestartPolicy: v1.RestartPolicyNever, - Req: e2eutil.CpuResource("1"), + Req: e2eutil.CPUResource("1"), }, }, }) @@ -306,8 +306,8 @@ var _ = Describe("Job Life Cycle", func() { Rep: rep + 1, Command: "sleep 10s", RestartPolicy: v1.RestartPolicyNever, - Req: e2eutil.CpuResource("1"), - Limit: e2eutil.CpuResource("1"), + Req: e2eutil.CPUResource("1"), + Limit: e2eutil.CPUResource("1"), Affinity: &v1.Affinity{NodeAffinity: nodeAffinity}, }, }, diff --git a/test/e2e/jobseq/job_error_handling.go b/test/e2e/jobseq/job_error_handling.go index 554f937434..2478758b12 100644 --- a/test/e2e/jobseq/job_error_handling.go +++ b/test/e2e/jobseq/job_error_handling.go @@ -28,6 +28,7 @@ import ( vcbatch "volcano.sh/apis/pkg/apis/batch/v1alpha1" vcbus "volcano.sh/apis/pkg/apis/bus/v1alpha1" + jobctl "volcano.sh/volcano/pkg/controllers/job" e2eutil "volcano.sh/volcano/test/e2e/util" @@ -834,14 +835,14 @@ var _ = Describe("Job Error Handling", func() { Name: "higherprioritytask", Img: e2eutil.DefaultNginxImage, Rep: int32(nodecount), - Req: e2eutil.CpuResource(strconv.Itoa(int(rep)/nodecount - 1)), + Req: e2eutil.CPUResource(strconv.Itoa(int(rep)/nodecount - 1)), Taskpriority: e2eutil.MasterPriority, }, { Name: "lowerprioritytask", Img: e2eutil.DefaultNginxImage, Rep: int32(nodecount), - Req: e2eutil.CpuResource(strconv.Itoa(int(rep)/nodecount - 1)), + Req: e2eutil.CPUResource(strconv.Itoa(int(rep)/nodecount - 1)), Taskpriority: e2eutil.MasterPriority, }, }, diff --git a/test/e2e/schedulingbase/sla.go b/test/e2e/schedulingbase/sla.go index 22632d8578..6854c6067f 100644 --- a/test/e2e/schedulingbase/sla.go +++ b/test/e2e/schedulingbase/sla.go @@ -96,22 +96,22 @@ var _ = Describe("SLA Test", func() { Expect(err).NotTo(HaveOccurred()) job2.Name = "j2-slow-sla" - slowSlaJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "1h"}) - err = e2eutil.WaitTaskPhase(ctx, slowSlaJob, []v1.PodPhase{v1.PodPending}, 0) + slowSLAJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "1h"}) + err = e2eutil.WaitTaskPhase(ctx, slowSLAJob, []v1.PodPhase{v1.PodPending}, 0) Expect(err).NotTo(HaveOccurred()) job2.Name = "j3-fast-sla" - fastSlaJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "30m"}) - err = e2eutil.WaitTaskPhase(ctx, fastSlaJob, []v1.PodPhase{v1.PodPending}, 0) + fastSLAJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "30m"}) + err = e2eutil.WaitTaskPhase(ctx, fastSLAJob, []v1.PodPhase{v1.PodPending}, 0) Expect(err).NotTo(HaveOccurred()) err = ctx.Vcclient.BatchV1alpha1().Jobs(e2eutil.Namespace(ctx, job1)).Delete(context.TODO(), job1.Name, metav1.DeleteOptions{}) Expect(err).NotTo(HaveOccurred()) - err = e2eutil.WaitTaskPhase(ctx, slowSlaJob, []v1.PodPhase{v1.PodPending}, 0) + err = e2eutil.WaitTaskPhase(ctx, slowSLAJob, []v1.PodPhase{v1.PodPending}, 0) Expect(err).NotTo(HaveOccurred()) - err = e2eutil.WaitTasksReady(ctx, fastSlaJob, int(rep)) + err = e2eutil.WaitTasksReady(ctx, fastSLAJob, int(rep)) Expect(err).NotTo(HaveOccurred()) }) }) diff --git a/test/e2e/util/job.go b/test/e2e/util/job.go index ad8873df94..0d62287d06 100644 --- a/test/e2e/util/job.go +++ b/test/e2e/util/job.go @@ -67,7 +67,7 @@ type JobSpec struct { Volumes []batchv1alpha1.VolumeSpec NodeName string // ttl seconds after job finished - Ttl *int32 + TTL *int32 MinSuccess *int32 // job max retry MaxRetry int32 @@ -101,7 +101,7 @@ func CreateJobWithPodGroup(ctx *TestContext, jobSpec *JobSpec, Policies: jobSpec.Policies, Queue: jobSpec.Queue, Plugins: jobSpec.Plugins, - TTLSecondsAfterFinished: jobSpec.Ttl, + TTLSecondsAfterFinished: jobSpec.TTL, }, } @@ -197,7 +197,7 @@ func CreateJobInner(ctx *TestContext, jobSpec *JobSpec) (*batchv1alpha1.Job, err Policies: jobSpec.Policies, Queue: jobSpec.Queue, Plugins: jobSpec.Plugins, - TTLSecondsAfterFinished: jobSpec.Ttl, + TTLSecondsAfterFinished: jobSpec.TTL, MinSuccess: jobSpec.MinSuccess, MaxRetry: jobSpec.MaxRetry, }, diff --git a/test/e2e/util/util.go b/test/e2e/util/util.go index 4737463546..ed0e3d2d5b 100644 --- a/test/e2e/util/util.go +++ b/test/e2e/util/util.go @@ -39,6 +39,7 @@ import ( "k8s.io/client-go/kubernetes" vcclient "volcano.sh/apis/pkg/client/clientset/versioned" + "volcano.sh/volcano/pkg/controllers/job/helpers" schedulerapi "volcano.sh/volcano/pkg/scheduler/api" ) @@ -80,7 +81,7 @@ const ( DefaultPytorchImage = "volcanosh/pytorch-mnist-v1beta1-9ee8fda-example:0.0.1" ) -func CpuResource(request string) v1.ResourceList { +func CPUResource(request string) v1.ResourceList { return v1.ResourceList{v1.ResourceCPU: resource.MustParse(request)} } diff --git a/test/e2e/vcctl/command.go b/test/e2e/vcctl/command.go index d728c2ff83..d2817211c1 100644 --- a/test/e2e/vcctl/command.go +++ b/test/e2e/vcctl/command.go @@ -129,7 +129,7 @@ var _ = Describe("Job E2E Test: Test Job Command", func() { { Name: taskName, Img: e2eutil.DefaultNginxImage, - Req: e2eutil.CpuResource(fmt.Sprintf("%dm", 1000*rep)), + Req: e2eutil.CPUResource(fmt.Sprintf("%dm", 1000*rep)), Min: 1, Rep: 1, },