From 0fac97a062457c1d6d147bfb1528369f54d3e5d4 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Fri, 24 Feb 2017 14:41:53 -0800 Subject: [PATCH 1/3] Add plugin/pkg/scheduler to linted packages --- hack/.linted_packages | 1 + 1 file changed, 1 insertion(+) diff --git a/hack/.linted_packages b/hack/.linted_packages index d533920bf4f..ff447d66dad 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -286,6 +286,7 @@ plugin/pkg/auth plugin/pkg/auth/authenticator/token/bootstrap plugin/pkg/auth/authorizer plugin/pkg/auth/authorizer/rbac/bootstrappolicy +plugin/pkg/scheduler plugin/pkg/scheduler/api/validation staging/src/k8s.io/apimachinery/pkg/api/equality staging/src/k8s.io/apimachinery/pkg/api/errors From 6a6ee160e8ac8910cb86eb1252cefb39f1056497 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Tue, 7 Mar 2017 12:21:16 -0800 Subject: [PATCH 2/3] golint fixes to plugin/pkg/scheduler/scheduler.go --- plugin/pkg/scheduler/scheduler.go | 44 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/plugin/pkg/scheduler/scheduler.go b/plugin/pkg/scheduler/scheduler.go index 1d37ef6d056..f151d1e0bdb 100644 --- a/plugin/pkg/scheduler/scheduler.go +++ b/plugin/pkg/scheduler/scheduler.go @@ -41,6 +41,8 @@ type Binder interface { Bind(binding *v1.Binding) error } +// PodConditionUpdater updates the condition of a pod based on the passed +// PodCondition type PodConditionUpdater interface { Update(pod *v1.Pod, podCondition *v1.PodCondition) error } @@ -51,12 +53,15 @@ type Scheduler struct { config *Config } +// StopEverything closes the scheduler config's StopEverything channel, to shut +// down the Scheduler. func (sched *Scheduler) StopEverything() { close(sched.config.StopEverything) } -// These are the functions which need to be provided in order to build a Scheduler configuration. -// An implementation of this can be seen in factory.go. +// Configurator defines I/O, caching, and other functionality needed to +// construct a new scheduler. An implementation of this can be seen in +// factory.go. type Configurator interface { GetPriorityFunctionConfigs(priorityKeys sets.String) ([]algorithm.PriorityConfig, error) GetPriorityMetadataProducer() (algorithm.MetadataProducer, error) @@ -81,6 +86,7 @@ type Configurator interface { CreateFromKeys(predicateKeys, priorityKeys sets.String, extenders []algorithm.SchedulerExtender) (*Config, error) } +// Config is an implementation of the Scheduler's configured input data. // TODO over time we should make this struct a hidden implementation detail of the scheduler. type Config struct { // It is expected that changes made via SchedulerCache will be observed @@ -141,26 +147,26 @@ func NewFromConfigurator(c Configurator, modifiers ...func(c *Config)) (*Schedul } // Run begins watching and scheduling. It starts a goroutine and returns immediately. -func (s *Scheduler) Run() { - go wait.Until(s.scheduleOne, 0, s.config.StopEverything) +func (sched *Scheduler) Run() { + go wait.Until(sched.scheduleOne, 0, sched.config.StopEverything) } -func (s *Scheduler) scheduleOne() { - pod := s.config.NextPod() +func (sched *Scheduler) scheduleOne() { + pod := sched.config.NextPod() if pod.DeletionTimestamp != nil { - s.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name) + sched.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name) glog.V(3).Infof("Skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name) return } glog.V(3).Infof("Attempting to schedule pod: %v/%v", pod.Namespace, pod.Name) start := time.Now() - dest, err := s.config.Algorithm.Schedule(pod, s.config.NodeLister) + dest, err := sched.config.Algorithm.Schedule(pod, sched.config.NodeLister) if err != nil { glog.V(1).Infof("Failed to schedule pod: %v/%v", pod.Namespace, pod.Name) - s.config.Error(pod, err) - s.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "%v", err) - s.config.PodConditionUpdater.Update(pod, &v1.PodCondition{ + sched.config.Error(pod, err) + sched.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "%v", err) + sched.config.PodConditionUpdater.Update(pod, &v1.PodCondition{ Type: v1.PodScheduled, Status: v1.ConditionFalse, Reason: v1.PodReasonUnschedulable, @@ -176,7 +182,7 @@ func (s *Scheduler) scheduleOne() { // immediately. assumed := *pod assumed.Spec.NodeName = dest - if err := s.config.SchedulerCache.AssumePod(&assumed); err != nil { + if err := sched.config.SchedulerCache.AssumePod(&assumed); err != nil { glog.Errorf("scheduler cache AssumePod failed: %v", err) // TODO: This means that a given pod is already in cache (which means it // is either assumed or already added). This is most probably result of a @@ -201,18 +207,18 @@ func (s *Scheduler) scheduleOne() { bindingStart := time.Now() // If binding succeeded then PodScheduled condition will be updated in apiserver so that // it's atomic with setting host. - err := s.config.Binder.Bind(b) - if err := s.config.SchedulerCache.FinishBinding(&assumed); err != nil { + err := sched.config.Binder.Bind(b) + if err := sched.config.SchedulerCache.FinishBinding(&assumed); err != nil { glog.Errorf("scheduler cache FinishBinding failed: %v", err) } if err != nil { glog.V(1).Infof("Failed to bind pod: %v/%v", pod.Namespace, pod.Name) - if err := s.config.SchedulerCache.ForgetPod(&assumed); err != nil { + if err := sched.config.SchedulerCache.ForgetPod(&assumed); err != nil { glog.Errorf("scheduler cache ForgetPod failed: %v", err) } - s.config.Error(pod, err) - s.config.Recorder.Eventf(pod, v1.EventTypeNormal, "FailedScheduling", "Binding rejected: %v", err) - s.config.PodConditionUpdater.Update(pod, &v1.PodCondition{ + sched.config.Error(pod, err) + sched.config.Recorder.Eventf(pod, v1.EventTypeNormal, "FailedScheduling", "Binding rejected: %v", err) + sched.config.PodConditionUpdater.Update(pod, &v1.PodCondition{ Type: v1.PodScheduled, Status: v1.ConditionFalse, Reason: "BindingRejected", @@ -220,6 +226,6 @@ func (s *Scheduler) scheduleOne() { return } metrics.BindingLatency.Observe(metrics.SinceInMicroseconds(bindingStart)) - s.config.Recorder.Eventf(pod, v1.EventTypeNormal, "Scheduled", "Successfully assigned %v to %v", pod.Name, dest) + sched.config.Recorder.Eventf(pod, v1.EventTypeNormal, "Scheduled", "Successfully assigned %v to %v", pod.Name, dest) }() } From ca24afe7788f0712b553594de719afecd5333318 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Tue, 7 Mar 2017 18:32:45 -0800 Subject: [PATCH 3/3] Additional plugin/pkg/scheduler golint fixes --- hack/.linted_packages | 2 ++ plugin/pkg/scheduler/algorithm/types.go | 2 +- .../algorithmprovider/defaults/defaults.go | 15 ++++++++++----- plugin/pkg/scheduler/algorithmprovider/plugins.go | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hack/.linted_packages b/hack/.linted_packages index ff447d66dad..01d43460ee7 100644 --- a/hack/.linted_packages +++ b/hack/.linted_packages @@ -287,6 +287,8 @@ plugin/pkg/auth/authenticator/token/bootstrap plugin/pkg/auth/authorizer plugin/pkg/auth/authorizer/rbac/bootstrappolicy plugin/pkg/scheduler +plugin/pkg/scheduler/algorithmprovider +plugin/pkg/scheduler/algorithmprovider/defaults plugin/pkg/scheduler/api/validation staging/src/k8s.io/apimachinery/pkg/api/equality staging/src/k8s.io/apimachinery/pkg/api/errors diff --git a/plugin/pkg/scheduler/algorithm/types.go b/plugin/pkg/scheduler/algorithm/types.go index 78f426ff2d3..580722c0785 100644 --- a/plugin/pkg/scheduler/algorithm/types.go +++ b/plugin/pkg/scheduler/algorithm/types.go @@ -41,7 +41,7 @@ type PriorityMapFunction func(pod *v1.Pod, meta interface{}, nodeInfo *scheduler // TODO: Change interface{} to a specific type. type PriorityReduceFunction func(pod *v1.Pod, meta interface{}, nodeNameToInfo map[string]*schedulercache.NodeInfo, result schedulerapi.HostPriorityList) error -// MetdataProducer is a function that computes metadata for a given pod. +// MetadataProducer is a function that computes metadata for a given pod. type MetadataProducer func(pod *v1.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo) interface{} // DEPRECATED diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go index ded15fe9776..6b1f6550936 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This is the default algorithm provider for the scheduler. package defaults import ( @@ -35,13 +34,19 @@ import ( ) const ( + // DefaultMaxGCEPDVolumes defines the maximum number of PD Volumes for GCE // GCE instances can have up to 16 PD volumes attached. DefaultMaxGCEPDVolumes = 16 - // Larger Azure VMs can actually have much more disks attached. TODO We should determine the max based on VM size + // DefaultMaxAzureDiskVolumes defines the maximum number of PD Volumes for Azure + // Larger Azure VMs can actually have much more disks attached. + // TODO We should determine the max based on VM size DefaultMaxAzureDiskVolumes = 16 - ClusterAutoscalerProvider = "ClusterAutoscalerProvider" - StatefulSetKind = "StatefulSet" - KubeMaxPDVols = "KUBE_MAX_PD_VOLS" + // ClusterAutoscalerProvider defines the default autoscaler provider + ClusterAutoscalerProvider = "ClusterAutoscalerProvider" + // StatefulSetKind defines the name of 'StatefulSet' kind + StatefulSetKind = "StatefulSet" + // KubeMaxPDVols defines the maximum number of PD Volumes per kubelet + KubeMaxPDVols = "KUBE_MAX_PD_VOLS" ) func init() { diff --git a/plugin/pkg/scheduler/algorithmprovider/plugins.go b/plugin/pkg/scheduler/algorithmprovider/plugins.go index f85cf055536..2aace84d046 100644 --- a/plugin/pkg/scheduler/algorithmprovider/plugins.go +++ b/plugin/pkg/scheduler/algorithmprovider/plugins.go @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -// This package is used to register algorithm provider plugins. package algorithmprovider import ( + // Import defaults of algorithmprovider for initialization. _ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults" )