Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint:fix lints #841

Merged
merged 2 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 9 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,24 @@ linters:
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- goimports
- golint
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- gocognit
- godox
- maligned
- prealloc
- wsl
- godot
- nestif
- gomodguard
- asciicheck
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- varcheck

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down Expand Up @@ -102,4 +77,4 @@ issues:
linters:
- golint
- deadcode
- godot
- godot
2 changes: 1 addition & 1 deletion cmd/cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CheckError(cmd *cobra.Command, err error) {

// Ignore the root command.
for cur := cmd; cur.Parent() != nil; cur = cur.Parent() {
msg = msg + fmt.Sprintf(" %s", cur.Name())
msg += fmt.Sprintf(" %s", cur.Name())
}

fmt.Printf("%s: %v\n", msg, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/vcctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func checkError(cmd *cobra.Command, err error) {

// Ignore the root command.
for cur := cmd; cur.Parent() != nil; cur = cur.Parent() {
msg = msg + fmt.Sprintf(" %s", cur.Name())
msg += fmt.Sprintf(" %s", cur.Name())
}

fmt.Printf("%s: %v\n", msg, err)
Expand Down
2 changes: 1 addition & 1 deletion example/kubecon-2019-china/scripts/node-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

v1 "k8s.io/api/core/v1"

"volcano.sh/volcano/pkg/scheduler/api"
Expand Down Expand Up @@ -89,5 +90,4 @@ func main() {
fmt.Printf(" %-20s |", res)
}
fmt.Print("\n--------------------------------------------------------------------------------------------------------------\n")

}
2 changes: 1 addition & 1 deletion pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ func HumanDuration(d time.Duration) string {
} else if hours < 24*365*8 {
return fmt.Sprintf("%dy%dd", hours/24/365, (hours/24)%365)
}
return fmt.Sprintf("%dy", int(hours/24/365))
return fmt.Sprintf("%dy", hours/24/365)
}
2 changes: 1 addition & 1 deletion pkg/cli/queue/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CreateQueue() error {
Name: createQueueFlags.Name,
},
Spec: schedulingv1beta1.QueueSpec{
Weight: int32(createQueueFlags.Weight),
Weight: createQueueFlags.Weight,
},
Status: schedulingv1beta1.QueueStatus{
State: schedulingv1beta1.QueueState(createQueueFlags.State),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ func HumanDuration(d time.Duration) string {
} else if hours < 24*365*8 {
return fmt.Sprintf("%dy%dd", hours/24/365, (hours/24)%365)
}
return fmt.Sprintf("%dy", int(hours/24/365))
return fmt.Sprintf("%dy", hours/24/365)
}
2 changes: 1 addition & 1 deletion pkg/controllers/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestJobCache_AddPod(t *testing.T) {
if err == nil {
job, err := jobCache.Get(fmt.Sprintf("%s/%s", testcase.JobsInCache["job1"].Namespace, testcase.JobsInCache["job1"].Name))
if err != nil {
t.Errorf("Expected Error not to occur while retriving job from cache in case %d", i)
t.Errorf("Expected Error not to occur while retrieving job from cache in case %d", i)
}
if err == nil {
if len(job.Pods) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/job/job_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (cc *Controller) killJob(jobInfo *apis.JobInfo, podRetainPhase state.PhaseM

job = job.DeepCopy()
// Job version is bumped only when job is killed
job.Status.Version = job.Status.Version + 1
job.Status.Version++

job.Status = batch.JobStatus{
State: job.Status.State,
Expand Down
12 changes: 5 additions & 7 deletions pkg/scheduler/actions/enqueue/enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ func (enqueue *Action) Execute(ssn *framework.Session) {
klog.Errorf("Failed to find Queue <%s> for Job <%s/%s>",
job.Queue, job.Namespace, job.Name)
continue
} else {
if _, existed := queueMap[queue.UID]; !existed {
klog.V(3).Infof("Added Queue <%s> for Job <%s/%s>",
queue.Name, job.Namespace, job.Name)
} else if _, existed := queueMap[queue.UID]; !existed {
klog.V(3).Infof("Added Queue <%s> for Job <%s/%s>",
queue.Name, job.Namespace, job.Name)

queueMap[queue.UID] = queue
queues.Push(queue)
}
queueMap[queue.UID] = queue
queues.Push(queue)
}

if job.PodGroup.Status.Phase == scheduling.PodGroupPending {
Expand Down
15 changes: 4 additions & 11 deletions pkg/scheduler/actions/reclaim/reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (ra *Action) Execute(ssn *framework.Session) {
klog.V(3).Infof("There are <%d> Jobs and <%d> Queues in total for scheduling.",
len(ssn.Jobs), len(ssn.Queues))

var underRequest []*api.JobInfo
for _, job := range ssn.Jobs {
if job.PodGroup.Status.Phase == scheduling.PodGroupPending {
continue
Expand All @@ -64,22 +63,17 @@ func (ra *Action) Execute(ssn *framework.Session) {
klog.Errorf("Failed to find Queue <%s> for Job <%s/%s>",
job.Queue, job.Namespace, job.Name)
continue
} else {
if _, existed := queueMap[queue.UID]; !existed {
klog.V(4).Infof("Added Queue <%s> for Job <%s/%s>",
queue.Name, job.Namespace, job.Name)

queueMap[queue.UID] = queue
queues.Push(queue)
}
} else if _, existed := queueMap[queue.UID]; !existed {
klog.V(4).Infof("Added Queue <%s> for Job <%s/%s>", queue.Name, job.Namespace, job.Name)
queueMap[queue.UID] = queue
queues.Push(queue)
}

if len(job.TaskStatusIndex[api.Pending]) != 0 {
if _, found := preemptorsMap[job.Queue]; !found {
preemptorsMap[job.Queue] = util.NewPriorityQueue(ssn.JobOrderFn)
}
preemptorsMap[job.Queue].Push(job)
underRequest = append(underRequest, job)
preemptorTasks[job.UID] = util.NewPriorityQueue(ssn.TaskOrderFn)
for _, task := range job.TaskStatusIndex[api.Pending] {
preemptorTasks[job.UID].Push(task)
Expand Down Expand Up @@ -192,7 +186,6 @@ func (ra *Action) Execute(ssn *framework.Session) {
}
queues.Push(queue)
}

}

func (ra *Action) UnInitialize() {
Expand Down
16 changes: 8 additions & 8 deletions pkg/scheduler/api/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@ func (ci ClusterInfo) String() string {
str := "Cache:\n"

if len(ci.Nodes) != 0 {
str = str + "Nodes:\n"
str += "Nodes:\n"
for _, n := range ci.Nodes {
str = str + fmt.Sprintf("\t %s: idle(%v) used(%v) allocatable(%v) pods(%d)\n",
str += fmt.Sprintf("\t %s: idle(%v) used(%v) allocatable(%v) pods(%d)\n",
n.Name, n.Idle, n.Used, n.Allocatable, len(n.Tasks))

i := 0
for _, p := range n.Tasks {
str = str + fmt.Sprintf("\t\t %d: %v\n", i, p)
str += fmt.Sprintf("\t\t %d: %v\n", i, p)
i++
}
}
}

if len(ci.Jobs) != 0 {
str = str + "Jobs:\n"
str += "Jobs:\n"
for _, job := range ci.Jobs {
str = str + fmt.Sprintf("\t Job(%s) name(%s) minAvailable(%v)\n",
str += fmt.Sprintf("\t Job(%s) name(%s) minAvailable(%v)\n",
job.UID, job.Name, job.MinAvailable)

i := 0
for _, task := range job.Tasks {
str = str + fmt.Sprintf("\t\t %d: %v\n", i, task)
str += fmt.Sprintf("\t\t %d: %v\n", i, task)
i++
}
}
}

if len(ci.NamespaceInfo) != 0 {
str = str + "Namespaces:\n"
str += "Namespaces:\n"
for _, ns := range ci.NamespaceInfo {
str = str + fmt.Sprintf("\t Namespace(%s) Weight(%v)\n",
str += fmt.Sprintf("\t Namespace(%s) Weight(%v)\n",
ns.Name, ns.Weight)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/scheduler/api/job_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sort"
"strings"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

Expand Down Expand Up @@ -296,7 +296,7 @@ func (ji JobInfo) String() string {

i := 0
for _, task := range ji.Tasks {
res = res + fmt.Sprintf("\n\t %d: %v", i, task)
res += fmt.Sprintf("\n\t %d: %v", i, task)
i++
}

Expand Down Expand Up @@ -352,7 +352,7 @@ func (ji *JobInfo) WaitingTaskNum() int32 {
occupid := 0
for status, tasks := range ji.TaskStatusIndex {
if status == Pipelined {
occupid = occupid + len(tasks)
occupid += len(tasks)
}
}

Expand All @@ -367,7 +367,7 @@ func (ji *JobInfo) ValidTaskNum() int32 {
status == Succeeded ||
status == Pipelined ||
status == Pending {
occupied = occupied + len(tasks)
occupied += len(tasks)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/api/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (ni NodeInfo) String() string {

i := 0
for _, task := range ni.Tasks {
tasks = tasks + fmt.Sprintf("\n\t %d: %v", i, task)
tasks += fmt.Sprintf("\n\t %d: %v", i, task)
i++
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/api/resource_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ func (r *Resource) FitDelta(rr *Resource) *Resource {

// Multi multiples the resource with ratio provided
func (r *Resource) Multi(ratio float64) *Resource {
r.MilliCPU = r.MilliCPU * ratio
r.Memory = r.Memory * ratio
r.MilliCPU *= ratio
r.Memory *= ratio
for rName, rQuant := range r.ScalarResources {
r.ScalarResources[rName] = rQuant * ratio
}
Expand Down
23 changes: 11 additions & 12 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package cache

import (
"fmt"
"k8s.io/api/core/v1"
"sync"
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -38,8 +41,6 @@ import (
"k8s.io/klog"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
"sync"
"time"
vcv1beta1 "volcano.sh/volcano/pkg/apis/scheduling/v1beta1"

"volcano.sh/volcano/cmd/scheduler/app/options"
Expand Down Expand Up @@ -395,7 +396,6 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {

// WaitForCacheSync sync the cache with the api server
func (sc *SchedulerCache) WaitForCacheSync(stopCh <-chan struct{}) bool {

return cache.WaitForCacheSync(stopCh,
func() []cache.InformerSynced {
informerSynced := []cache.InformerSynced{
Expand Down Expand Up @@ -737,31 +737,31 @@ func (sc *SchedulerCache) String() string {
str := "Cache:\n"

if len(sc.Nodes) != 0 {
str = str + "Nodes:\n"
str += "Nodes:\n"
for _, n := range sc.Nodes {
str = str + fmt.Sprintf("\t %s: idle(%v) used(%v) allocatable(%v) pods(%d)\n",
str += fmt.Sprintf("\t %s: idle(%v) used(%v) allocatable(%v) pods(%d)\n",
n.Name, n.Idle, n.Used, n.Allocatable, len(n.Tasks))

i := 0
for _, p := range n.Tasks {
str = str + fmt.Sprintf("\t\t %d: %v\n", i, p)
str += fmt.Sprintf("\t\t %d: %v\n", i, p)
i++
}
}
}

if len(sc.Jobs) != 0 {
str = str + "Jobs:\n"
str += "Jobs:\n"
for _, job := range sc.Jobs {
str = str + fmt.Sprintf("\t %s\n", job)
str += fmt.Sprintf("\t %s\n", job)
}
}

if len(sc.NamespaceCollection) != 0 {
str = str + "Namespaces:\n"
str += "Namespaces:\n"
for _, ns := range sc.NamespaceCollection {
info := ns.Snapshot()
str = str + fmt.Sprintf("\t Namespace(%s) Weight(%v)\n",
str += fmt.Sprintf("\t Namespace(%s) Weight(%v)\n",
info.Name, info.Weight)
}
}
Expand Down Expand Up @@ -831,6 +831,5 @@ func (sc *SchedulerCache) recordPodGroupEvent(podGroup *schedulingapi.PodGroup,
klog.Errorf("Error while converting PodGroup to v1alpha1.PodGroup with error: %v", err)
return
}

sc.Recorder.Eventf(pg, eventType, reason, msg)
}
Loading