Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default pv controller and scheduler to immediate mode if volume binding mode is nil #71286

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/controller/volume/persistentvolume/pv_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ func (ctrl *PersistentVolumeController) shouldDelayBinding(claim *v1.PersistentV
}

if class.VolumeBindingMode == nil {
return false, fmt.Errorf("VolumeBindingMode not set for StorageClass %q", className)
// In an HA upgrade scenario, the API server may still be on a lower version
// than the controller-manager. Default to behavior as if the feature is off.
return false, nil
}

// TODO: add check to handle dynamic provisioning later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ func TestDelayBinding(t *testing.T) {
"no-mode-class": {
pvc: makePVCClass(&classNoMode),
shouldDelay: false,
shouldFail: true,
},
"immediate-mode-class": {
pvc: makePVCClass(&classImmediateMode),
Expand Down
14 changes: 8 additions & 6 deletions pkg/scheduler/algorithm/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,14 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta algorithm.PredicateMetad
if scName != nil && len(*scName) > 0 {
class, _ := c.classInfo.GetStorageClassInfo(*scName)
if class != nil {
if class.VolumeBindingMode == nil {
return false, nil, fmt.Errorf("VolumeBindingMode not set for StorageClass %q", scName)
}
if *class.VolumeBindingMode == storagev1.VolumeBindingWaitForFirstConsumer {
// Skip unbound volumes
continue
if class.VolumeBindingMode != nil {
// In an HA Upgrade scenario, the API server may still be
// on a lower version than the scheduler. Default to
// behavior as if the feature is off
if *class.VolumeBindingMode == storagev1.VolumeBindingWaitForFirstConsumer {
// Skip unbound volumes
continue
}
}
}
}
Expand Down
65 changes: 48 additions & 17 deletions pkg/scheduler/algorithm/predicates/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3692,6 +3692,7 @@ func createPodWithVolume(pod, pv, pvc string) *v1.Pod {
}

func TestVolumeZonePredicate(t *testing.T) {
scName := "SC_1"
pvInfo := FakePersistentVolumeInfo{
{
ObjectMeta: metav1.ObjectMeta{Name: "Vol_1", Labels: map[string]string{kubeletapis.LabelZoneFailureDomain: "us-west1-a"}},
Expand Down Expand Up @@ -3721,13 +3722,24 @@ func TestVolumeZonePredicate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "PVC_4", Namespace: "default"},
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "Vol_not_exist"},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "PVC_5", Namespace: "default"},
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "", StorageClassName: &scName},
},
}

scInfo := FakeStorageClassInfo{
{
ObjectMeta: metav1.ObjectMeta{Name: scName},
},
}

tests := []struct {
Name string
Pod *v1.Pod
Fits bool
Node *v1.Node
Name string
Pod *v1.Pod
Fits bool
Node *v1.Node
ExpectError bool
}{
{
Name: "pod without volume",
Expand Down Expand Up @@ -3796,26 +3808,45 @@ func TestVolumeZonePredicate(t *testing.T) {
},
Fits: false,
},
{
Name: "pvc not bound",
Pod: createPodWithVolume("pod_1", "nothing", "PVC_5"),
Node: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "host1",
Labels: map[string]string{kubeletapis.LabelZoneFailureDomain: "no_us-west1-a", "uselessLabel": "none"},
},
},
Fits: false,
ExpectError: true,
},
}

expectedFailureReasons := []algorithm.PredicateFailureReason{ErrVolumeZoneConflict}

for _, test := range tests {
fit := NewVolumeZonePredicate(pvInfo, pvcInfo, nil)
node := &schedulercache.NodeInfo{}
node.SetNode(test.Node)
t.Run(test.Name, func(t *testing.T) {
fit := NewVolumeZonePredicate(pvInfo, pvcInfo, scInfo)
node := &schedulercache.NodeInfo{}
node.SetNode(test.Node)

fits, reasons, err := fit(test.Pod, nil, node)
if err != nil {
t.Errorf("%s: unexpected error: %v", test.Name, err)
}
if !fits && !reflect.DeepEqual(reasons, expectedFailureReasons) {
t.Errorf("%s: unexpected failure reasons: %v, want: %v", test.Name, reasons, expectedFailureReasons)
}
if fits != test.Fits {
t.Errorf("%s: expected %v got %v", test.Name, test.Fits, fits)
}
fits, reasons, err := fit(test.Pod, nil, node)
if test.ExpectError && err == nil {
t.Errorf("expected error, got success")
}
if !test.ExpectError {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !fits && !reflect.DeepEqual(reasons, expectedFailureReasons) {
t.Errorf("unexpected failure reasons: %v, want: %v", reasons, expectedFailureReasons)
}
}

if fits != test.Fits {
t.Errorf("expected %v got %v", test.Fits, fits)
}
})
}
}

Expand Down