Unverified Commit 0ca67bde authored by k8s-ci-robot's avatar k8s-ci-robot Committed by GitHub

Merge pull request #70362 from ddebroy/ddebroy-multi-pvc

Add multi PVC versions of e2e tests for WaitForFirstConsumer
parents d8e78c8a 923df464
...@@ -1016,22 +1016,40 @@ func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll, ...@@ -1016,22 +1016,40 @@ func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll,
// WaitForPersistentVolumeClaimPhase waits for a PersistentVolumeClaim to be in a specific phase or until timeout occurs, whichever comes first. // WaitForPersistentVolumeClaimPhase waits for a PersistentVolumeClaim to be in a specific phase or until timeout occurs, whichever comes first.
func WaitForPersistentVolumeClaimPhase(phase v1.PersistentVolumeClaimPhase, c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error { func WaitForPersistentVolumeClaimPhase(phase v1.PersistentVolumeClaimPhase, c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error {
Logf("Waiting up to %v for PersistentVolumeClaim %s to have phase %s", timeout, pvcName, phase) return WaitForPersistentVolumeClaimsPhase(phase, c, ns, []string{pvcName}, Poll, timeout, true)
}
// WaitForPersistentVolumeClaimPhase waits for any (if matchAny is true) or all (if matchAny is false) PersistentVolumeClaims
// to be in a specific phase or until timeout occurs, whichever comes first.
func WaitForPersistentVolumeClaimsPhase(phase v1.PersistentVolumeClaimPhase, c clientset.Interface, ns string, pvcNames []string, Poll, timeout time.Duration, matchAny bool) error {
if len(pvcNames) == 0 {
return fmt.Errorf("Incorrect parameter: Need at least one PVC to track. Found 0.")
}
Logf("Waiting up to %v for PersistentVolumeClaims %v to have phase %s", timeout, pvcNames, phase)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) { for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
pvc, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{}) phaseFoundInAllClaims := true
if err != nil { for _, pvcName := range pvcNames {
Logf("Failed to get claim %q, retrying in %v. Error: %v", pvcName, Poll, err) pvc, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{})
continue if err != nil {
} else { Logf("Failed to get claim %q, retrying in %v. Error: %v", pvcName, Poll, err)
if pvc.Status.Phase == phase { continue
Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
return nil
} else { } else {
Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase) if pvc.Status.Phase == phase {
Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
if matchAny {
return nil
}
} else {
Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase)
phaseFoundInAllClaims = false
}
} }
} }
if phaseFoundInAllClaims {
return nil
}
} }
return fmt.Errorf("PersistentVolumeClaim %s not in phase %s within %v", pvcName, phase, timeout) return fmt.Errorf("PersistentVolumeClaims %v not all in phase %s within %v", pvcNames, phase, timeout)
} }
// CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name. // CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name.
......
...@@ -74,7 +74,8 @@ var _ = utils.SIGDescribe("Regional PD", func() { ...@@ -74,7 +74,8 @@ var _ = utils.SIGDescribe("Regional PD", func() {
}) })
It("should provision storage with delayed binding [Slow]", func() { It("should provision storage with delayed binding [Slow]", func() {
testRegionalDelayedBinding(c, ns) testRegionalDelayedBinding(c, ns, 1 /* pvcCount */)
testRegionalDelayedBinding(c, ns, 3 /* pvcCount */)
}) })
It("should provision storage in the allowedTopologies [Slow]", func() { It("should provision storage in the allowedTopologies [Slow]", func() {
...@@ -82,7 +83,8 @@ var _ = utils.SIGDescribe("Regional PD", func() { ...@@ -82,7 +83,8 @@ var _ = utils.SIGDescribe("Regional PD", func() {
}) })
It("should provision storage in the allowedTopologies with delayed binding [Slow]", func() { It("should provision storage in the allowedTopologies with delayed binding [Slow]", func() {
testRegionalAllowedTopologiesWithDelayedBinding(c, ns) testRegionalAllowedTopologiesWithDelayedBinding(c, ns, 1 /* pvcCount */)
testRegionalAllowedTopologiesWithDelayedBinding(c, ns, 3 /* pvcCount */)
}) })
It("should failover to a different zone when all nodes in one zone become unreachable [Slow] [Disruptive]", func() { It("should failover to a different zone when all nodes in one zone become unreachable [Slow] [Disruptive]", func() {
...@@ -297,7 +299,7 @@ func addTaint(c clientset.Interface, ns string, nodes []v1.Node, podZone string) ...@@ -297,7 +299,7 @@ func addTaint(c clientset.Interface, ns string, nodes []v1.Node, podZone string)
} }
} }
func testRegionalDelayedBinding(c clientset.Interface, ns string) { func testRegionalDelayedBinding(c clientset.Interface, ns string, pvcCount int) {
test := testsuites.StorageClassTest{ test := testsuites.StorageClassTest{
Name: "Regional PD storage class with waitForFirstConsumer test on GCE", Name: "Regional PD storage class with waitForFirstConsumer test on GCE",
Provisioner: "kubernetes.io/gce-pd", Provisioner: "kubernetes.io/gce-pd",
...@@ -311,9 +313,13 @@ func testRegionalDelayedBinding(c clientset.Interface, ns string) { ...@@ -311,9 +313,13 @@ func testRegionalDelayedBinding(c clientset.Interface, ns string) {
suffix := "delayed-regional" suffix := "delayed-regional"
class := newStorageClass(test, ns, suffix) class := newStorageClass(test, ns, suffix)
claim := newClaim(test, ns, suffix) var claims []*v1.PersistentVolumeClaim
claim.Spec.StorageClassName = &class.Name for i := 0; i < pvcCount; i++ {
pv, node := testBindingWaitForFirstConsumer(c, claim, class) claim := newClaim(test, ns, suffix)
claim.Spec.StorageClassName = &class.Name
claims = append(claims, claim)
}
pvs, node := testBindingWaitForFirstConsumerMultiPVC(c, claims, class)
if node == nil { if node == nil {
framework.Failf("unexpected nil node found") framework.Failf("unexpected nil node found")
} }
...@@ -321,7 +327,9 @@ func testRegionalDelayedBinding(c clientset.Interface, ns string) { ...@@ -321,7 +327,9 @@ func testRegionalDelayedBinding(c clientset.Interface, ns string) {
if !ok { if !ok {
framework.Failf("label %s not found on Node", kubeletapis.LabelZoneFailureDomain) framework.Failf("label %s not found on Node", kubeletapis.LabelZoneFailureDomain)
} }
checkZoneFromLabelAndAffinity(pv, zone, false) for _, pv := range pvs {
checkZoneFromLabelAndAffinity(pv, zone, false)
}
} }
func testRegionalAllowedTopologies(c clientset.Interface, ns string) { func testRegionalAllowedTopologies(c clientset.Interface, ns string) {
...@@ -346,7 +354,7 @@ func testRegionalAllowedTopologies(c clientset.Interface, ns string) { ...@@ -346,7 +354,7 @@ func testRegionalAllowedTopologies(c clientset.Interface, ns string) {
checkZonesFromLabelAndAffinity(pv, sets.NewString(zones...), true) checkZonesFromLabelAndAffinity(pv, sets.NewString(zones...), true)
} }
func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns string) { func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns string, pvcCount int) {
test := testsuites.StorageClassTest{ test := testsuites.StorageClassTest{
Name: "Regional PD storage class with allowedTopologies and waitForFirstConsumer test on GCE", Name: "Regional PD storage class with allowedTopologies and waitForFirstConsumer test on GCE",
Provisioner: "kubernetes.io/gce-pd", Provisioner: "kubernetes.io/gce-pd",
...@@ -362,9 +370,13 @@ func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns s ...@@ -362,9 +370,13 @@ func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns s
class := newStorageClass(test, ns, suffix) class := newStorageClass(test, ns, suffix)
topoZones := getTwoRandomZones(c) topoZones := getTwoRandomZones(c)
addAllowedTopologiesToStorageClass(c, class, topoZones) addAllowedTopologiesToStorageClass(c, class, topoZones)
claim := newClaim(test, ns, suffix) var claims []*v1.PersistentVolumeClaim
claim.Spec.StorageClassName = &class.Name for i := 0; i < pvcCount; i++ {
pv, node := testBindingWaitForFirstConsumer(c, claim, class) claim := newClaim(test, ns, suffix)
claim.Spec.StorageClassName = &class.Name
claims = append(claims, claim)
}
pvs, node := testBindingWaitForFirstConsumerMultiPVC(c, claims, class)
if node == nil { if node == nil {
framework.Failf("unexpected nil node found") framework.Failf("unexpected nil node found")
} }
...@@ -382,7 +394,9 @@ func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns s ...@@ -382,7 +394,9 @@ func testRegionalAllowedTopologiesWithDelayedBinding(c clientset.Interface, ns s
if !zoneFound { if !zoneFound {
framework.Failf("zones specified in AllowedTopologies: %v does not contain zone of node where PV got provisioned: %s", topoZones, nodeZone) framework.Failf("zones specified in AllowedTopologies: %v does not contain zone of node where PV got provisioned: %s", topoZones, nodeZone)
} }
checkZonesFromLabelAndAffinity(pv, sets.NewString(topoZones...), true) for _, pv := range pvs {
checkZonesFromLabelAndAffinity(pv, sets.NewString(topoZones...), true)
}
} }
func getPVC(c clientset.Interface, ns string, pvcLabels map[string]string) *v1.PersistentVolumeClaim { func getPVC(c clientset.Interface, ns string, pvcLabels map[string]string) *v1.PersistentVolumeClaim {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment