追踪整个代码跳过过程 1 2 3 4 cmd/kube-batch/main.go:39main-> cmd/kube-batch/main.go:53app.Runcmd/kube-batch/app/server.go:60Run-> cmd/kube-batch/app/server.go:86sched.Runcmd/kube-batch/app/server.go:86sched.Run-> pkg/scheduler/scheduler.go:59cmd/kube-batch/app/server.go:59sched.Run-> pkg/scheduler/scheduler.runOnce:84 cmd/kube-batch/app/server.go:59 行代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 func(pc*Scheduler)Run(stopCh<-chanstruct{}){varerrerror// Start cache for policy. gopc.cache.Run(stopCh)pc.cache.WaitForCacheSync(stopCh)// Load configuration of scheduler schedConf:=defaultSchedulerConfiflen(pc.schedulerConf)!=0{ifschedConf,err=readSchedulerConf(pc.schedulerConf);err!=nil{glog.Errorf("Failed to read scheduler configuration '%s', using default configuration: %v",pc.schedulerConf,err)schedConf=defaultSchedulerConf}}pc.actions,pc.plugins,err=loadSchedulerConf(schedConf)iferr!=nil{panic(err)}// 这里又开始周期性调用 runOnce了。开始调用 gowait.Until(pc.runOnce,pc.schedulePeriod,stopCh)} cmd/kube-batch/app/server.go:84 行代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 func(pc*Scheduler)runOnce(){glog.V(4).Infof("Start scheduling ...")scheduleStartTime:=time.Now()deferglog.V(4).Infof("End scheduling ...")defermetrics.UpdateE2eDuration(metrics.Duration(scheduleStartTime))ssn:=framework.OpenSession(pc.cache,pc.plugins)deferframework.CloseSession(ssn)for_,action:=rangepc.actions{actionStartTime:=time.Now()action.Execute(ssn)metrics.UpdateActionDuration(action.Name(),metrics.Duration(actionStartTime))}} 这里主要 defer 是延迟函数,就是返回值之前执行。所以上面……
阅读全文