Skip to content

Commit 8274bec

Browse files
authored
Merge pull request kubernetes#82990 from SataQiu/cleanup-scheduler-20190922
Clean up code about scheduler algorithm
2 parents 2e4d02e + 7cb4850 commit 8274bec

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

pkg/scheduler/algorithm/predicates/predicates.go

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const (
9696
// DEPRECATED
9797
// All cloudprovider specific predicates are deprecated in favour of MaxCSIVolumeCountPred.
9898
MaxCinderVolumeCountPred = "MaxCinderVolumeCount"
99-
// MaxCSIVolumeCountPred defines the predicate that decides how many CSI volumes should be attached
99+
// MaxCSIVolumeCountPred defines the predicate that decides how many CSI volumes should be attached.
100100
MaxCSIVolumeCountPred = "MaxCSIVolumeCountPred"
101101
// NoVolumeZoneConflictPred defines the name of predicate NoVolumeZoneConflict.
102102
NoVolumeZoneConflictPred = "NoVolumeZoneConflict"
@@ -106,18 +106,18 @@ const (
106106
CheckNodeDiskPressurePred = "CheckNodeDiskPressure"
107107
// CheckNodePIDPressurePred defines the name of predicate CheckNodePIDPressure.
108108
CheckNodePIDPressurePred = "CheckNodePIDPressure"
109-
// EvenPodsSpreadPred defines the name of predicate EvenPodsSpread
109+
// EvenPodsSpreadPred defines the name of predicate EvenPodsSpread.
110110
EvenPodsSpreadPred = "EvenPodsSpread"
111111

112-
// DefaultMaxGCEPDVolumes defines the maximum number of PD Volumes for GCE
112+
// DefaultMaxGCEPDVolumes defines the maximum number of PD Volumes for GCE.
113113
// GCE instances can have up to 16 PD volumes attached.
114114
DefaultMaxGCEPDVolumes = 16
115-
// DefaultMaxAzureDiskVolumes defines the maximum number of PD Volumes for Azure
115+
// DefaultMaxAzureDiskVolumes defines the maximum number of PD Volumes for Azure.
116116
// Larger Azure VMs can actually have much more disks attached.
117117
// TODO We should determine the max based on VM size
118118
DefaultMaxAzureDiskVolumes = 16
119119

120-
// KubeMaxPDVols defines the maximum number of PD Volumes per kubelet
120+
// KubeMaxPDVols defines the maximum number of PD Volumes per kubelet.
121121
KubeMaxPDVols = "KUBE_MAX_PD_VOLS"
122122

123123
// EBSVolumeFilterType defines the filter name for EBSVolumeFilter.
@@ -153,16 +153,21 @@ var (
153153
CheckNodeMemoryPressurePred, CheckNodePIDPressurePred, CheckNodeDiskPressurePred, EvenPodsSpreadPred, MatchInterPodAffinityPred}
154154
)
155155

156+
// Ordering returns the ordering of predicates.
157+
func Ordering() []string {
158+
return predicatesOrdering
159+
}
160+
156161
// FitPredicate is a function that indicates if a pod fits into an existing node.
157162
// The failure information is given by the error.
158163
type FitPredicate func(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error)
159164

160-
// NodeInfo interface represents anything that can get node object from node ID.
165+
// NodeInfo interface represents anything that can get node object from node name.
161166
type NodeInfo interface {
162-
GetNodeInfo(nodeID string) (*v1.Node, error)
167+
GetNodeInfo(nodeName string) (*v1.Node, error)
163168
}
164169

165-
// CSINodeInfo interface represents anything that can get CSINode object from node ID.
170+
// CSINodeInfo interface represents anything that can get CSINode object from node name.
166171
type CSINodeInfo interface {
167172
GetCSINodeInfo(nodeName string) (*storagev1beta1.CSINode, error)
168173
}
@@ -172,16 +177,13 @@ type PersistentVolumeInfo interface {
172177
GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error)
173178
}
174179

180+
var _ PersistentVolumeInfo = &CachedPersistentVolumeInfo{}
181+
175182
// CachedPersistentVolumeInfo implements PersistentVolumeInfo
176183
type CachedPersistentVolumeInfo struct {
177184
corelisters.PersistentVolumeLister
178185
}
179186

180-
// Ordering returns the ordering of predicates.
181-
func Ordering() []string {
182-
return predicatesOrdering
183-
}
184-
185187
// GetPersistentVolumeInfo returns a persistent volume object by PV ID.
186188
func (c *CachedPersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error) {
187189
return c.Get(pvID)
@@ -193,12 +195,14 @@ type PersistentVolumeClaimInfo interface {
193195
GetPersistentVolumeClaimInfo(namespace string, name string) (*v1.PersistentVolumeClaim, error)
194196
}
195197

198+
var _ PersistentVolumeClaimInfo = &CachedPersistentVolumeClaimInfo{}
199+
196200
// CachedPersistentVolumeClaimInfo implements PersistentVolumeClaimInfo
197201
type CachedPersistentVolumeClaimInfo struct {
198202
corelisters.PersistentVolumeClaimLister
199203
}
200204

201-
// GetPersistentVolumeClaimInfo fetches the claim in specified namespace with specified name
205+
// GetPersistentVolumeClaimInfo fetches the claim in specified namespace with specified name.
202206
func (c *CachedPersistentVolumeClaimInfo) GetPersistentVolumeClaimInfo(namespace string, name string) (*v1.PersistentVolumeClaim, error) {
203207
return c.PersistentVolumeClaims(namespace).Get(name)
204208
}
@@ -208,6 +212,8 @@ type StorageClassInfo interface {
208212
GetStorageClassInfo(className string) (*storagev1.StorageClass, error)
209213
}
210214

215+
var _ StorageClassInfo = &CachedStorageClassInfo{}
216+
211217
// CachedStorageClassInfo implements StorageClassInfo
212218
type CachedStorageClassInfo struct {
213219
storagelisters.StorageClassLister
@@ -301,7 +307,7 @@ type MaxPDVolumeCountChecker struct {
301307
randomVolumeIDPrefix string
302308
}
303309

304-
// VolumeFilter contains information on how to filter PD Volumes when checking PD Volume caps
310+
// VolumeFilter contains information on how to filter PD Volumes when checking PD Volume caps.
305311
type VolumeFilter struct {
306312
// Filter normal volumes
307313
FilterVolume func(vol *v1.Volume) (id string, relevant bool)
@@ -396,13 +402,13 @@ func getMaxEBSVolume(nodeInstanceType string) int {
396402
return volumeutil.DefaultMaxEBSVolumes
397403
}
398404

399-
// getMaxVolLimitFromEnv checks the max PD volumes environment variable, otherwise returning a default value
405+
// getMaxVolLimitFromEnv checks the max PD volumes environment variable, otherwise returning a default value.
400406
func getMaxVolLimitFromEnv() int {
401407
if rawMaxVols := os.Getenv(KubeMaxPDVols); rawMaxVols != "" {
402408
if parsedMaxVols, err := strconv.Atoi(rawMaxVols); err != nil {
403409
klog.Errorf("Unable to parse maximum PD volumes value, using default: %v", err)
404410
} else if parsedMaxVols <= 0 {
405-
klog.Errorf("Maximum PD volumes must be a positive value, using default ")
411+
klog.Errorf("Maximum PD volumes must be a positive value, using default")
406412
} else {
407413
return parsedMaxVols
408414
}
@@ -555,7 +561,7 @@ func (c *MaxPDVolumeCountChecker) predicate(pod *v1.Pod, meta PredicateMetadata,
555561
return true, nil, nil
556562
}
557563

558-
// EBSVolumeFilter is a VolumeFilter for filtering AWS ElasticBlockStore Volumes
564+
// EBSVolumeFilter is a VolumeFilter for filtering AWS ElasticBlockStore Volumes.
559565
var EBSVolumeFilter = VolumeFilter{
560566
FilterVolume: func(vol *v1.Volume) (string, bool) {
561567
if vol.AWSElasticBlockStore != nil {
@@ -583,7 +589,7 @@ var EBSVolumeFilter = VolumeFilter{
583589
},
584590
}
585591

586-
// GCEPDVolumeFilter is a VolumeFilter for filtering GCE PersistentDisk Volumes
592+
// GCEPDVolumeFilter is a VolumeFilter for filtering GCE PersistentDisk Volumes.
587593
var GCEPDVolumeFilter = VolumeFilter{
588594
FilterVolume: func(vol *v1.Volume) (string, bool) {
589595
if vol.GCEPersistentDisk != nil {
@@ -611,7 +617,7 @@ var GCEPDVolumeFilter = VolumeFilter{
611617
},
612618
}
613619

614-
// AzureDiskVolumeFilter is a VolumeFilter for filtering Azure Disk Volumes
620+
// AzureDiskVolumeFilter is a VolumeFilter for filtering Azure Disk Volumes.
615621
var AzureDiskVolumeFilter = VolumeFilter{
616622
FilterVolume: func(vol *v1.Volume) (string, bool) {
617623
if vol.AzureDisk != nil {
@@ -639,7 +645,7 @@ var AzureDiskVolumeFilter = VolumeFilter{
639645
},
640646
}
641647

642-
// CinderVolumeFilter is a VolumeFilter for filtering Cinder Volumes
648+
// CinderVolumeFilter is a VolumeFilter for filtering Cinder Volumes.
643649
// It will be deprecated once Openstack cloudprovider has been removed from in-tree.
644650
var CinderVolumeFilter = VolumeFilter{
645651
FilterVolume: func(vol *v1.Volume) (string, bool) {
@@ -1023,7 +1029,7 @@ func NewNodeLabelPredicate(labels []string, presence bool) FitPredicate {
10231029
//
10241030
// Alternately, eliminating nodes that have a certain label, regardless of value, is also useful
10251031
// A node may have a label with "retiring" as key and the date as the value
1026-
// and it may be desirable to avoid scheduling new pods on this node
1032+
// and it may be desirable to avoid scheduling new pods on this node.
10271033
func (n *NodeLabelChecker) CheckNodeLabelPresence(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
10281034
node := nodeInfo.Node()
10291035
if node == nil {
@@ -1172,7 +1178,7 @@ func PodFitsHostPorts(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulerno
11721178
return true, nil, nil
11731179
}
11741180

1175-
// search two arrays and return true if they have at least one common element; return false otherwise
1181+
// haveOverlap searches two arrays and returns true if they have at least one common element; returns false otherwise.
11761182
func haveOverlap(a1, a2 []string) bool {
11771183
if len(a1) > len(a2) {
11781184
a1, a2 = a2, a1
@@ -1192,7 +1198,7 @@ func haveOverlap(a1, a2 []string) bool {
11921198
}
11931199

11941200
// GeneralPredicates checks whether noncriticalPredicates and EssentialPredicates pass. noncriticalPredicates are the predicates
1195-
// that only non-critical pods need and EssentialPredicates are the predicates that all pods, including critical pods, need
1201+
// that only non-critical pods need and EssentialPredicates are the predicates that all pods, including critical pods, need.
11961202
func GeneralPredicates(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
11971203
var predicateFails []PredicateFailureReason
11981204
for _, predicate := range []FitPredicate{noncriticalPredicates, EssentialPredicates} {
@@ -1208,7 +1214,7 @@ func GeneralPredicates(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulern
12081214
return len(predicateFails) == 0, predicateFails, nil
12091215
}
12101216

1211-
// noncriticalPredicates are the predicates that only non-critical pods need
1217+
// noncriticalPredicates are the predicates that only non-critical pods need.
12121218
func noncriticalPredicates(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
12131219
var predicateFails []PredicateFailureReason
12141220
fit, reasons, err := PodFitsResources(pod, meta, nodeInfo)
@@ -1222,7 +1228,7 @@ func noncriticalPredicates(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedu
12221228
return len(predicateFails) == 0, predicateFails, nil
12231229
}
12241230

1225-
// EssentialPredicates are the predicates that all pods, including critical pods, need
1231+
// EssentialPredicates are the predicates that all pods, including critical pods, need.
12261232
func EssentialPredicates(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
12271233
var predicateFails []PredicateFailureReason
12281234
// TODO: PodFitsHostPorts is essential for now, but kubelet should ideally
@@ -1400,7 +1406,7 @@ func (c *PodAffinityChecker) getMatchingAntiAffinityTopologyPairsOfPods(pod *v1.
14001406
func (c *PodAffinityChecker) satisfiesExistingPodsAntiAffinity(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (PredicateFailureReason, error) {
14011407
node := nodeInfo.Node()
14021408
if node == nil {
1403-
return ErrExistingPodsAntiAffinityRulesNotMatch, fmt.Errorf("Node is nil")
1409+
return ErrExistingPodsAntiAffinityRulesNotMatch, fmt.Errorf("node not found")
14041410
}
14051411
var topologyMaps *topologyPairsMaps
14061412
if predicateMeta, ok := meta.(*predicateMetadata); ok {
@@ -1470,13 +1476,13 @@ func (c *PodAffinityChecker) nodeMatchesAnyTopologyTerm(pod *v1.Pod, topologyPai
14701476
return false
14711477
}
14721478

1473-
// Checks if scheduling the pod onto this node would break any term of this pod.
1479+
// satisfiesPodsAffinityAntiAffinity checks if scheduling the pod onto this node would break any term of this pod.
14741480
func (c *PodAffinityChecker) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
14751481
meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo,
14761482
affinity *v1.Affinity) (PredicateFailureReason, error) {
14771483
node := nodeInfo.Node()
14781484
if node == nil {
1479-
return ErrPodAffinityRulesNotMatch, fmt.Errorf("Node is nil")
1485+
return ErrPodAffinityRulesNotMatch, fmt.Errorf("node not found")
14801486
}
14811487
if predicateMeta, ok := meta.(*predicateMetadata); ok {
14821488
// Check all affinity terms.
@@ -1592,7 +1598,7 @@ func CheckNodeUnschedulablePredicate(pod *v1.Pod, meta PredicateMetadata, nodeIn
15921598
return true, nil, nil
15931599
}
15941600

1595-
// PodToleratesNodeTaints checks if a pod tolerations can tolerate the node taints
1601+
// PodToleratesNodeTaints checks if a pod tolerations can tolerate the node taints.
15961602
func PodToleratesNodeTaints(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
15971603
if nodeInfo == nil || nodeInfo.Node() == nil {
15981604
return false, []PredicateFailureReason{ErrNodeUnknownCondition}, nil
@@ -1604,7 +1610,7 @@ func PodToleratesNodeTaints(pod *v1.Pod, meta PredicateMetadata, nodeInfo *sched
16041610
})
16051611
}
16061612

1607-
// PodToleratesNodeNoExecuteTaints checks if a pod tolerations can tolerate the node's NoExecute taints
1613+
// PodToleratesNodeNoExecuteTaints checks if a pod tolerations can tolerate the node's NoExecute taints.
16081614
func PodToleratesNodeNoExecuteTaints(pod *v1.Pod, meta PredicateMetadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) {
16091615
return podToleratesNodeTaints(pod, nodeInfo, func(t *v1.Taint) bool {
16101616
return t.Effect == v1.TaintEffectNoExecute
@@ -1623,7 +1629,7 @@ func podToleratesNodeTaints(pod *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo, f
16231629
return false, []PredicateFailureReason{ErrTaintsTolerationsNotMatch}, nil
16241630
}
16251631

1626-
// isPodBestEffort checks if pod is scheduled with best-effort QoS
1632+
// isPodBestEffort checks if pod is scheduled with best-effort QoS.
16271633
func isPodBestEffort(pod *v1.Pod) bool {
16281634
return v1qos.GetPodQOS(pod) == v1.PodQOSBestEffort
16291635
}

pkg/scheduler/algorithm/scheduler_interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type SchedulerExtender interface {
3838

3939
// Prioritize based on extender-implemented priority functions. The returned scores & weight
4040
// are used to compute the weighted score for an extender. The weighted scores are added to
41-
// the scores computed by Kubernetes scheduler. The total scores are used to do the host selection.
41+
// the scores computed by Kubernetes scheduler. The total scores are used to do the host selection.
4242
Prioritize(pod *v1.Pod, nodes []*v1.Node) (hostPriorities *schedulerapi.HostPriorityList, weight int64, err error)
4343

4444
// Bind delegates the action of binding a pod to a node to the extender.

pkg/scheduler/algorithm/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
2525
)
2626

27-
// NodeFieldSelectorKeys is a map that: the key are node field selector keys; the values are
27+
// NodeFieldSelectorKeys is a map that: the keys are node field selector keys; the values are
2828
// the functions to get the value of the node field.
2929
var NodeFieldSelectorKeys = map[string]func(*v1.Node) string{
3030
schedulerapi.NodeFieldSelectorKeyNodeName: func(n *v1.Node) string { return n.Name },
@@ -62,7 +62,7 @@ type ServiceLister interface {
6262
type ControllerLister interface {
6363
// Lists all the replication controllers
6464
List(labels.Selector) ([]*v1.ReplicationController, error)
65-
// Gets the services for the given pod
65+
// Gets the replication controller for the given pod
6666
GetPodControllers(*v1.Pod) ([]*v1.ReplicationController, error)
6767
}
6868

@@ -74,7 +74,7 @@ type ReplicaSetLister interface {
7474

7575
// PDBLister interface represents anything that can list PodDisruptionBudget objects.
7676
type PDBLister interface {
77-
// List() returns a list of PodDisruptionBudgets matching the selector.
77+
// List all the PodDisruptionBudgets matching the selector
7878
List(labels.Selector) ([]*policyv1beta1.PodDisruptionBudget, error)
7979
}
8080

0 commit comments

Comments
 (0)