Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
80afde7c
Unverified
Commit
80afde7c
authored
Jan 07, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 07, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70026 from bertinatto/only_schedule_pod_if_pv_requirements_are_met
Check PV requirements before scheduling
parents
8b3b5a9f
bb4fcddd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
11 deletions
+37
-11
BUILD
pkg/controller/volume/persistentvolume/BUILD
+1
-0
scheduler_binder.go
pkg/controller/volume/persistentvolume/scheduler_binder.go
+31
-6
scheduler_binder_test.go
...ntroller/volume/persistentvolume/scheduler_binder_test.go
+0
-0
factory.go
pkg/scheduler/factory/factory.go
+3
-4
volume_binder.go
pkg/scheduler/volumebinder/volume_binder.go
+2
-1
No files found.
pkg/controller/volume/persistentvolume/BUILD
View file @
80afde7c
...
...
@@ -99,6 +99,7 @@ go_test(
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
...
...
pkg/controller/volume/persistentvolume/scheduler_binder.go
View file @
80afde7c
...
...
@@ -21,15 +21,14 @@ import (
"sort"
"time"
"k8s.io/klog"
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
coreinformers
"k8s.io/client-go/informers/core/v1"
storageinformers
"k8s.io/client-go/informers/storage/v1"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
v1helper
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
)
...
...
@@ -99,8 +98,9 @@ type SchedulerVolumeBinder interface {
type
volumeBinder
struct
{
ctrl
*
PersistentVolumeController
pvcCache
PVCAssumeCache
pvCache
PVAssumeCache
nodeInformer
coreinformers
.
NodeInformer
pvcCache
PVCAssumeCache
pvCache
PVAssumeCache
// Stores binding decisions that were made in FindPodVolumes for use in AssumePodVolumes.
// AssumePodVolumes modifies the bindings again for use in BindPodVolumes.
...
...
@@ -113,6 +113,7 @@ type volumeBinder struct {
// NewVolumeBinder sets up all the caches needed for the scheduler to make volume binding decisions.
func
NewVolumeBinder
(
kubeClient
clientset
.
Interface
,
nodeInformer
coreinformers
.
NodeInformer
,
pvcInformer
coreinformers
.
PersistentVolumeClaimInformer
,
pvInformer
coreinformers
.
PersistentVolumeInformer
,
storageClassInformer
storageinformers
.
StorageClassInformer
,
...
...
@@ -126,6 +127,7 @@ func NewVolumeBinder(
b
:=
&
volumeBinder
{
ctrl
:
ctrl
,
nodeInformer
:
nodeInformer
,
pvcCache
:
NewPVCAssumeCache
(
pvcInformer
.
Informer
()),
pvCache
:
NewPVAssumeCache
(
pvInformer
.
Informer
()),
podBindingCache
:
NewPodBindingCache
(),
...
...
@@ -139,7 +141,9 @@ func (b *volumeBinder) GetBindingsCache() PodBindingCache {
return
b
.
podBindingCache
}
// FindPodVolumes caches the matching PVs and PVCs to provision per node in podBindingCache
// FindPodVolumes caches the matching PVs and PVCs to provision per node in podBindingCache.
// This method intentionally takes in a *v1.Node object instead of using volumebinder.nodeInformer.
// That's necessary because some operations will need to pass in to the predicate fake node objects.
func
(
b
*
volumeBinder
)
FindPodVolumes
(
pod
*
v1
.
Pod
,
node
*
v1
.
Node
)
(
unboundVolumesSatisfied
,
boundVolumesSatisfied
bool
,
err
error
)
{
podName
:=
getPodName
(
pod
)
...
...
@@ -382,6 +386,11 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*bindingInfo, claim
return
false
,
fmt
.
Errorf
(
"failed to get cached claims to provision for pod %q"
,
podName
)
}
node
,
err
:=
b
.
nodeInformer
.
Lister
()
.
Get
(
pod
.
Spec
.
NodeName
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to get node %q: %v"
,
pod
.
Spec
.
NodeName
,
err
)
}
for
_
,
binding
:=
range
bindings
{
// Check for any conditions that might require scheduling retry
...
...
@@ -391,6 +400,11 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*bindingInfo, claim
return
false
,
fmt
.
Errorf
(
"failed to check pv binding: %v"
,
err
)
}
// Check PV's node affinity (the node might not have the proper label)
if
err
:=
volumeutil
.
CheckNodeAffinity
(
pv
,
node
.
Labels
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"pv %q node affinity doesn't match node %q: %v"
,
pv
.
Name
,
node
.
Name
,
err
)
}
// Check if pv.ClaimRef got dropped by unbindVolume()
if
pv
.
Spec
.
ClaimRef
==
nil
||
pv
.
Spec
.
ClaimRef
.
UID
==
""
{
return
false
,
fmt
.
Errorf
(
"ClaimRef got reset for pv %q"
,
pv
.
Name
)
...
...
@@ -420,6 +434,17 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*bindingInfo, claim
return
false
,
fmt
.
Errorf
(
"selectedNode annotation value %q not set to scheduled node %q"
,
selectedNode
,
pod
.
Spec
.
NodeName
)
}
// If the PVC is bound to a PV, check its node affinity
if
pvc
.
Spec
.
VolumeName
!=
""
{
pv
,
err
:=
b
.
pvCache
.
GetPV
(
pvc
.
Spec
.
VolumeName
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to get pv %q from cache: %v"
,
pvc
.
Spec
.
VolumeName
,
err
)
}
if
err
:=
volumeutil
.
CheckNodeAffinity
(
pv
,
node
.
Labels
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"pv %q node affinity doesn't match node %q: %v"
,
pv
.
Name
,
node
.
Name
,
err
)
}
}
if
!
bound
{
return
false
,
nil
}
...
...
pkg/controller/volume/persistentvolume/scheduler_binder_test.go
View file @
80afde7c
This diff is collapsed.
Click to expand it.
pkg/scheduler/factory/factory.go
View file @
80afde7c
...
...
@@ -23,9 +23,7 @@ import (
"reflect"
"time"
"k8s.io/klog"
"k8s.io/api/core/v1"
v1
"k8s.io/api/core/v1"
storagev1
"k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -47,6 +45,7 @@ import (
storagelisters
"k8s.io/client-go/listers/storage/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
...
...
@@ -375,7 +374,7 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
)
// Setup volume binder
c
.
volumeBinder
=
volumebinder
.
NewVolumeBinder
(
args
.
Client
,
args
.
PvcInformer
,
args
.
PvInformer
,
args
.
StorageClassInformer
,
time
.
Duration
(
args
.
BindTimeoutSeconds
)
*
time
.
Second
)
c
.
volumeBinder
=
volumebinder
.
NewVolumeBinder
(
args
.
Client
,
args
.
NodeInformer
,
args
.
PvcInformer
,
args
.
PvInformer
,
args
.
StorageClassInformer
,
time
.
Duration
(
args
.
BindTimeoutSeconds
)
*
time
.
Second
)
args
.
StorageClassInformer
.
Informer
()
.
AddEventHandler
(
cache
.
ResourceEventHandlerFuncs
{
...
...
pkg/scheduler/volumebinder/volume_binder.go
View file @
80afde7c
...
...
@@ -34,13 +34,14 @@ type VolumeBinder struct {
// NewVolumeBinder sets up the volume binding library and binding queue
func
NewVolumeBinder
(
client
clientset
.
Interface
,
nodeInformer
coreinformers
.
NodeInformer
,
pvcInformer
coreinformers
.
PersistentVolumeClaimInformer
,
pvInformer
coreinformers
.
PersistentVolumeInformer
,
storageClassInformer
storageinformers
.
StorageClassInformer
,
bindTimeout
time
.
Duration
)
*
VolumeBinder
{
return
&
VolumeBinder
{
Binder
:
persistentvolume
.
NewVolumeBinder
(
client
,
pvcInformer
,
pvInformer
,
storageClassInformer
,
bindTimeout
),
Binder
:
persistentvolume
.
NewVolumeBinder
(
client
,
nodeInformer
,
pvcInformer
,
pvInformer
,
storageClassInformer
,
bindTimeout
),
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment