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

fix scheduler ha bug #443

Merged
merged 1 commit into from
May 1, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/scheduler/predicates/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,18 @@ func (h *ha) realAcquireLock(pod *apiv1.Pod) (*apiv1.PersistentVolumeClaim, *api
if schedulingPVC == currentPVC {
return schedulingPVC, currentPVC, nil
}
schedulingPodName := getPodNameFromPVC(schedulingPVC)
schedulingPod, err := h.podGetFn(ns, schedulingPodName)
if err != nil {
return schedulingPVC, currentPVC, err
}
if schedulingPVC.Status.Phase != apiv1.ClaimBound || schedulingPod.Spec.NodeName == "" {
return schedulingPVC, currentPVC, fmt.Errorf("waiting for Pod %s/%s scheduling", ns, strings.TrimPrefix(schedulingPVC.GetName(), component))

// if pvc is not defer deleting(has AnnPVCDeferDeleting annotation means defer deleting), we must wait for its scheduling
// else clear its AnnPVCPodScheduling annotation and acquire the lock
if schedulingPVC.Annotations[label.AnnPVCDeferDeleting] == "" {
schedulingPodName := getPodNameFromPVC(schedulingPVC)
schedulingPod, err := h.podGetFn(ns, schedulingPodName)
if err != nil {
return schedulingPVC, currentPVC, err
}
if schedulingPVC.Status.Phase != apiv1.ClaimBound || schedulingPod.Spec.NodeName == "" {
return schedulingPVC, currentPVC, fmt.Errorf("waiting for Pod %s/%s scheduling", ns, strings.TrimPrefix(schedulingPVC.GetName(), component))
}
}

delete(schedulingPVC.Annotations, label.AnnPVCPodScheduling)
Expand Down
39 changes: 39 additions & 0 deletions pkg/scheduler/predicates/ha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,45 @@ func TestHARealAcquireLockFn(t *testing.T) {
g.Expect(currentPVC.Annotations[label.AnnPVCPodScheduling]).NotTo(BeEmpty())
},
},
{
name: "scheduling pvc is defer deleting, current pvc acquire lock",
podFn: newHAPDPod,
pvcListFn: func(ns, instanceName, component string) (*corev1.PersistentVolumeClaimList, error) {
return &corev1.PersistentVolumeClaimList{
TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaimList", APIVersion: "v1"},
Items: []corev1.PersistentVolumeClaim{
{
TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaim", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "pd-cluster-1-pd-0",
},
},
{
TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaim", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "pd-cluster-1-pd-1",
Annotations: map[string]string{
label.AnnPVCPodScheduling: "true",
label.AnnPVCDeferDeleting: "true",
},
},
Status: corev1.PersistentVolumeClaimStatus{Phase: corev1.ClaimBound},
},
},
}, nil
},
podGetFn: podGetErr(),
updatePVCFn: func(claim *corev1.PersistentVolumeClaim) error {
return nil
},
expectFn: func(schedulingPVC, currentPVC *apiv1.PersistentVolumeClaim, err error) {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(schedulingPVC.Annotations[label.AnnPVCPodScheduling]).To(BeEmpty())
g.Expect(currentPVC.Annotations[label.AnnPVCPodScheduling]).NotTo(BeEmpty())
},
},
}

for i := range tests {
Expand Down