mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #42087 from cblecker/scheduler-lint
Automatic merge from submit-queue Add plugin/pkg/scheduler to linted packages **What this PR does / why we need it**: Adds plugin/pkg/scheduler to linted packages to improve style correctness. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #41868 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
b6d187d5f2
@ -286,6 +286,9 @@ plugin/pkg/auth
|
|||||||
plugin/pkg/auth/authenticator/token/bootstrap
|
plugin/pkg/auth/authenticator/token/bootstrap
|
||||||
plugin/pkg/auth/authorizer
|
plugin/pkg/auth/authorizer
|
||||||
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
|
plugin/pkg/auth/authorizer/rbac/bootstrappolicy
|
||||||
|
plugin/pkg/scheduler
|
||||||
|
plugin/pkg/scheduler/algorithmprovider
|
||||||
|
plugin/pkg/scheduler/algorithmprovider/defaults
|
||||||
plugin/pkg/scheduler/api/validation
|
plugin/pkg/scheduler/api/validation
|
||||||
staging/src/k8s.io/apimachinery/pkg/api/equality
|
staging/src/k8s.io/apimachinery/pkg/api/equality
|
||||||
staging/src/k8s.io/apimachinery/pkg/api/errors
|
staging/src/k8s.io/apimachinery/pkg/api/errors
|
||||||
|
@ -41,7 +41,7 @@ type PriorityMapFunction func(pod *v1.Pod, meta interface{}, nodeInfo *scheduler
|
|||||||
// TODO: Change interface{} to a specific type.
|
// TODO: Change interface{} to a specific type.
|
||||||
type PriorityReduceFunction func(pod *v1.Pod, meta interface{}, nodeNameToInfo map[string]*schedulercache.NodeInfo, result schedulerapi.HostPriorityList) error
|
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{}
|
type MetadataProducer func(pod *v1.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo) interface{}
|
||||||
|
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This is the default algorithm provider for the scheduler.
|
|
||||||
package defaults
|
package defaults
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -35,13 +34,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// DefaultMaxGCEPDVolumes defines the maximum number of PD Volumes for GCE
|
||||||
// GCE instances can have up to 16 PD volumes attached.
|
// GCE instances can have up to 16 PD volumes attached.
|
||||||
DefaultMaxGCEPDVolumes = 16
|
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
|
DefaultMaxAzureDiskVolumes = 16
|
||||||
ClusterAutoscalerProvider = "ClusterAutoscalerProvider"
|
// ClusterAutoscalerProvider defines the default autoscaler provider
|
||||||
StatefulSetKind = "StatefulSet"
|
ClusterAutoscalerProvider = "ClusterAutoscalerProvider"
|
||||||
KubeMaxPDVols = "KUBE_MAX_PD_VOLS"
|
// 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() {
|
func init() {
|
||||||
|
@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This package is used to register algorithm provider plugins.
|
|
||||||
package algorithmprovider
|
package algorithmprovider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
// Import defaults of algorithmprovider for initialization.
|
||||||
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults"
|
_ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults"
|
||||||
)
|
)
|
||||||
|
@ -41,6 +41,8 @@ type Binder interface {
|
|||||||
Bind(binding *v1.Binding) error
|
Bind(binding *v1.Binding) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PodConditionUpdater updates the condition of a pod based on the passed
|
||||||
|
// PodCondition
|
||||||
type PodConditionUpdater interface {
|
type PodConditionUpdater interface {
|
||||||
Update(pod *v1.Pod, podCondition *v1.PodCondition) error
|
Update(pod *v1.Pod, podCondition *v1.PodCondition) error
|
||||||
}
|
}
|
||||||
@ -51,12 +53,15 @@ type Scheduler struct {
|
|||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StopEverything closes the scheduler config's StopEverything channel, to shut
|
||||||
|
// down the Scheduler.
|
||||||
func (sched *Scheduler) StopEverything() {
|
func (sched *Scheduler) StopEverything() {
|
||||||
close(sched.config.StopEverything)
|
close(sched.config.StopEverything)
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are the functions which need to be provided in order to build a Scheduler configuration.
|
// Configurator defines I/O, caching, and other functionality needed to
|
||||||
// An implementation of this can be seen in factory.go.
|
// construct a new scheduler. An implementation of this can be seen in
|
||||||
|
// factory.go.
|
||||||
type Configurator interface {
|
type Configurator interface {
|
||||||
GetPriorityFunctionConfigs(priorityKeys sets.String) ([]algorithm.PriorityConfig, error)
|
GetPriorityFunctionConfigs(priorityKeys sets.String) ([]algorithm.PriorityConfig, error)
|
||||||
GetPriorityMetadataProducer() (algorithm.MetadataProducer, error)
|
GetPriorityMetadataProducer() (algorithm.MetadataProducer, error)
|
||||||
@ -81,6 +86,7 @@ type Configurator interface {
|
|||||||
CreateFromKeys(predicateKeys, priorityKeys sets.String, extenders []algorithm.SchedulerExtender) (*Config, error)
|
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.
|
// TODO over time we should make this struct a hidden implementation detail of the scheduler.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// It is expected that changes made via SchedulerCache will be observed
|
// 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.
|
// Run begins watching and scheduling. It starts a goroutine and returns immediately.
|
||||||
func (s *Scheduler) Run() {
|
func (sched *Scheduler) Run() {
|
||||||
go wait.Until(s.scheduleOne, 0, s.config.StopEverything)
|
go wait.Until(sched.scheduleOne, 0, sched.config.StopEverything)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) scheduleOne() {
|
func (sched *Scheduler) scheduleOne() {
|
||||||
pod := s.config.NextPod()
|
pod := sched.config.NextPod()
|
||||||
if pod.DeletionTimestamp != nil {
|
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)
|
glog.V(3).Infof("Skip schedule deleting pod: %v/%v", pod.Namespace, pod.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(3).Infof("Attempting to schedule pod: %v/%v", pod.Namespace, pod.Name)
|
glog.V(3).Infof("Attempting to schedule pod: %v/%v", pod.Namespace, pod.Name)
|
||||||
start := time.Now()
|
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 {
|
if err != nil {
|
||||||
glog.V(1).Infof("Failed to schedule pod: %v/%v", pod.Namespace, pod.Name)
|
glog.V(1).Infof("Failed to schedule pod: %v/%v", pod.Namespace, pod.Name)
|
||||||
s.config.Error(pod, err)
|
sched.config.Error(pod, err)
|
||||||
s.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "%v", err)
|
sched.config.Recorder.Eventf(pod, v1.EventTypeWarning, "FailedScheduling", "%v", err)
|
||||||
s.config.PodConditionUpdater.Update(pod, &v1.PodCondition{
|
sched.config.PodConditionUpdater.Update(pod, &v1.PodCondition{
|
||||||
Type: v1.PodScheduled,
|
Type: v1.PodScheduled,
|
||||||
Status: v1.ConditionFalse,
|
Status: v1.ConditionFalse,
|
||||||
Reason: v1.PodReasonUnschedulable,
|
Reason: v1.PodReasonUnschedulable,
|
||||||
@ -176,7 +182,7 @@ func (s *Scheduler) scheduleOne() {
|
|||||||
// immediately.
|
// immediately.
|
||||||
assumed := *pod
|
assumed := *pod
|
||||||
assumed.Spec.NodeName = dest
|
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)
|
glog.Errorf("scheduler cache AssumePod failed: %v", err)
|
||||||
// TODO: This means that a given pod is already in cache (which means it
|
// 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
|
// is either assumed or already added). This is most probably result of a
|
||||||
@ -201,18 +207,18 @@ func (s *Scheduler) scheduleOne() {
|
|||||||
bindingStart := time.Now()
|
bindingStart := time.Now()
|
||||||
// If binding succeeded then PodScheduled condition will be updated in apiserver so that
|
// If binding succeeded then PodScheduled condition will be updated in apiserver so that
|
||||||
// it's atomic with setting host.
|
// it's atomic with setting host.
|
||||||
err := s.config.Binder.Bind(b)
|
err := sched.config.Binder.Bind(b)
|
||||||
if err := s.config.SchedulerCache.FinishBinding(&assumed); err != nil {
|
if err := sched.config.SchedulerCache.FinishBinding(&assumed); err != nil {
|
||||||
glog.Errorf("scheduler cache FinishBinding failed: %v", err)
|
glog.Errorf("scheduler cache FinishBinding failed: %v", err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(1).Infof("Failed to bind pod: %v/%v", pod.Namespace, pod.Name)
|
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)
|
glog.Errorf("scheduler cache ForgetPod failed: %v", err)
|
||||||
}
|
}
|
||||||
s.config.Error(pod, err)
|
sched.config.Error(pod, err)
|
||||||
s.config.Recorder.Eventf(pod, v1.EventTypeNormal, "FailedScheduling", "Binding rejected: %v", err)
|
sched.config.Recorder.Eventf(pod, v1.EventTypeNormal, "FailedScheduling", "Binding rejected: %v", err)
|
||||||
s.config.PodConditionUpdater.Update(pod, &v1.PodCondition{
|
sched.config.PodConditionUpdater.Update(pod, &v1.PodCondition{
|
||||||
Type: v1.PodScheduled,
|
Type: v1.PodScheduled,
|
||||||
Status: v1.ConditionFalse,
|
Status: v1.ConditionFalse,
|
||||||
Reason: "BindingRejected",
|
Reason: "BindingRejected",
|
||||||
@ -220,6 +226,6 @@ func (s *Scheduler) scheduleOne() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
metrics.BindingLatency.Observe(metrics.SinceInMicroseconds(bindingStart))
|
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)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user