Skip to content

Commit

Permalink
fix scheduler ha bug (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
weekface authored and tennix committed May 1, 2019
1 parent 4280261 commit f9166c3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
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

0 comments on commit f9166c3

Please sign in to comment.