Skip to content

Commit

Permalink
Lint:fix lints
Browse files Browse the repository at this point in the history
Signed-off-by: Thor <1187526662@qq.com>
  • Loading branch information
Thor-wl committed May 29, 2020
1 parent 76110e4 commit 0408f1b
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 82 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- dupl
- errcheck
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
Expand Down Expand Up @@ -103,3 +102,10 @@ issues:
- golint
- deadcode
- godot

linters-settings:
lll:
line-length: 256
funlen:
lines: 100
statements: 60
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
4 changes: 2 additions & 2 deletions 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 @@ -59,7 +60,7 @@ func main() {
if _, found := podMap[nodeName]; !found {
podMap[nodeName] = api.EmptyResource()
}
res := api.GetPodResourceWithoutInitContainers(&p)
res := api.GetPodResourceWithoutInitContainers(p)
podMap[nodeName].Add(res)
}

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)
}
3 changes: 2 additions & 1 deletion pkg/client/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
8 changes: 4 additions & 4 deletions pkg/scheduler/actions/preempt/preempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (alloc *Action) Execute(ssn *framework.Session) {

preemptor := preemptorTasks[preemptorJob.UID].Pop().(*api.TaskInfo)

if preempted, _ := preempt(ssn, stmt, preemptor, func(task *api.TaskInfo) bool {
if preempted := preempt(ssn, stmt, preemptor, func(task *api.TaskInfo) bool {
// Ignore non running task.
if task.Status != api.Running {
return false
Expand Down Expand Up @@ -155,7 +155,7 @@ func (alloc *Action) Execute(ssn *framework.Session) {
preemptor := preemptorTasks[job.UID].Pop().(*api.TaskInfo)

stmt := ssn.Statement()
assigned, _ := preempt(ssn, stmt, preemptor, func(task *api.TaskInfo) bool {
assigned := preempt(ssn, stmt, preemptor, func(task *api.TaskInfo) bool {
// Ignore non running task.
if task.Status != api.Running {
return false
Expand Down Expand Up @@ -185,7 +185,7 @@ func preempt(
stmt *framework.Statement,
preemptor *api.TaskInfo,
filter func(*api.TaskInfo) bool,
) (bool, error) {
) bool {
assigned := false

allNodes := util.GetNodeList(ssn.Nodes)
Expand Down Expand Up @@ -258,5 +258,5 @@ func preempt(
}
}

return assigned, nil
return assigned
}
18 changes: 7 additions & 11 deletions pkg/scheduler/actions/reclaim/reclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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
// var underRequest []*api.JobInfo
for _, job := range ssn.Jobs {
if job.PodGroup.Status.Phase == scheduling.PodGroupPending {
continue
Expand All @@ -64,22 +64,19 @@ 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)
// 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 +189,6 @@ func (ra *Action) Execute(ssn *framework.Session) {
}
queues.Push(queue)
}

}

func (ra *Action) UnInitialize() {
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)
}
18 changes: 5 additions & 13 deletions pkg/scheduler/cache/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package cache
import (
"fmt"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -246,18 +246,16 @@ func (sc *SchedulerCache) DeletePod(obj interface{}) {
}

// Assumes that lock is already acquired.
func (sc *SchedulerCache) addNode(node *v1.Node) error {
func (sc *SchedulerCache) addNode(node *v1.Node) {
if sc.Nodes[node.Name] != nil {
sc.Nodes[node.Name].SetNode(node)
} else {
sc.Nodes[node.Name] = schedulingapi.NewNodeInfo(node)
}

return nil
}

// Assumes that lock is already acquired.
func (sc *SchedulerCache) updateNode(oldNode, newNode *v1.Node) error {
func (sc *SchedulerCache) updateNode(newNode *v1.Node) error {
if sc.Nodes[newNode.Name] != nil {
sc.Nodes[newNode.Name].SetNode(newNode)
return nil
Expand Down Expand Up @@ -286,11 +284,7 @@ func (sc *SchedulerCache) AddNode(obj interface{}) {
sc.Mutex.Lock()
defer sc.Mutex.Unlock()

err := sc.addNode(node)
if err != nil {
klog.Errorf("Failed to add node %s into cache: %v", node.Name, err)
return
}
sc.addNode(node)
}

// UpdateNode update node to scheduler cache
Expand All @@ -309,7 +303,7 @@ func (sc *SchedulerCache) UpdateNode(oldObj, newObj interface{}) {
sc.Mutex.Lock()
defer sc.Mutex.Unlock()

err := sc.updateNode(oldNode, newNode)
err := sc.updateNode(newNode)
if err != nil {
klog.Errorf("Failed to update node %v in cache: %v", oldNode.Name, err)
return
Expand Down Expand Up @@ -596,9 +590,7 @@ func (sc *SchedulerCache) UpdatePriorityClass(oldObj, newObj interface{}) {
newSS, ok := newObj.(*v1beta1.PriorityClass)
if !ok {
klog.Errorf("Cannot convert newObj to *v1beta1.PriorityClass: %v", newObj)

return

}

sc.Mutex.Lock()
Expand Down
Loading

0 comments on commit 0408f1b

Please sign in to comment.