|
|
|
@ -31,7 +31,6 @@ import (
|
|
|
|
|
storageutil "k8s.io/kubernetes/pkg/apis/storage/v1/util"
|
|
|
|
|
"k8s.io/kubernetes/pkg/volume/util"
|
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
|
|
|
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -143,7 +142,7 @@ func PVPVCCleanup(c clientset.Interface, ns string, pv *v1.PersistentVolume, pvc
|
|
|
|
|
errs = append(errs, fmt.Errorf("failed to delete PVC %q: %v", pvc.Name, err))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e2elog.Logf("pvc is nil")
|
|
|
|
|
framework.Logf("pvc is nil")
|
|
|
|
|
}
|
|
|
|
|
if pv != nil {
|
|
|
|
|
err := DeletePersistentVolume(c, pv.Name)
|
|
|
|
@ -151,7 +150,7 @@ func PVPVCCleanup(c clientset.Interface, ns string, pv *v1.PersistentVolume, pvc
|
|
|
|
|
errs = append(errs, fmt.Errorf("failed to delete PV %q: %v", pv.Name, err))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e2elog.Logf("pv is nil")
|
|
|
|
|
framework.Logf("pv is nil")
|
|
|
|
|
}
|
|
|
|
|
return errs
|
|
|
|
|
}
|
|
|
|
@ -185,7 +184,7 @@ func PVPVCMapCleanup(c clientset.Interface, ns string, pvols PVMap, claims PVCMa
|
|
|
|
|
// DeletePersistentVolume deletes the PV.
|
|
|
|
|
func DeletePersistentVolume(c clientset.Interface, pvName string) error {
|
|
|
|
|
if c != nil && len(pvName) > 0 {
|
|
|
|
|
e2elog.Logf("Deleting PersistentVolume %q", pvName)
|
|
|
|
|
framework.Logf("Deleting PersistentVolume %q", pvName)
|
|
|
|
|
err := c.CoreV1().PersistentVolumes().Delete(pvName, nil)
|
|
|
|
|
if err != nil && !apierrs.IsNotFound(err) {
|
|
|
|
|
return fmt.Errorf("PV Delete API error: %v", err)
|
|
|
|
@ -197,7 +196,7 @@ func DeletePersistentVolume(c clientset.Interface, pvName string) error {
|
|
|
|
|
// DeletePersistentVolumeClaim deletes the Claim.
|
|
|
|
|
func DeletePersistentVolumeClaim(c clientset.Interface, pvcName string, ns string) error {
|
|
|
|
|
if c != nil && len(pvcName) > 0 {
|
|
|
|
|
e2elog.Logf("Deleting PersistentVolumeClaim %q", pvcName)
|
|
|
|
|
framework.Logf("Deleting PersistentVolumeClaim %q", pvcName)
|
|
|
|
|
err := c.CoreV1().PersistentVolumeClaims(ns).Delete(pvcName, nil)
|
|
|
|
|
if err != nil && !apierrs.IsNotFound(err) {
|
|
|
|
|
return fmt.Errorf("PVC Delete API error: %v", err)
|
|
|
|
@ -211,14 +210,14 @@ func DeletePersistentVolumeClaim(c clientset.Interface, pvcName string, ns strin
|
|
|
|
|
// phase value to expect for the pv bound to the to-be-deleted claim.
|
|
|
|
|
func DeletePVCandValidatePV(c clientset.Interface, ns string, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, expectPVPhase v1.PersistentVolumePhase) error {
|
|
|
|
|
pvname := pvc.Spec.VolumeName
|
|
|
|
|
e2elog.Logf("Deleting PVC %v to trigger reclamation of PV %v", pvc.Name, pvname)
|
|
|
|
|
framework.Logf("Deleting PVC %v to trigger reclamation of PV %v", pvc.Name, pvname)
|
|
|
|
|
err := DeletePersistentVolumeClaim(c, pvc.Name, ns)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wait for the PV's phase to return to be `expectPVPhase`
|
|
|
|
|
e2elog.Logf("Waiting for reclaim process to complete.")
|
|
|
|
|
framework.Logf("Waiting for reclaim process to complete.")
|
|
|
|
|
err = WaitForPersistentVolumePhase(expectPVPhase, c, pv.Name, framework.Poll, PVReclaimingTimeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("pv %q phase did not become %v: %v", pv.Name, expectPVPhase, err)
|
|
|
|
@ -243,7 +242,7 @@ func DeletePVCandValidatePV(c clientset.Interface, ns string, pvc *v1.Persistent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2elog.Logf("PV %v now in %q phase", pv.Name, expectPVPhase)
|
|
|
|
|
framework.Logf("PV %v now in %q phase", pv.Name, expectPVPhase)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -360,7 +359,7 @@ func CreatePVPVC(c clientset.Interface, pvConfig PersistentVolumeConfig, pvcConf
|
|
|
|
|
if preBind {
|
|
|
|
|
preBindMsg = " pre-bound"
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("Creating a PV followed by a%s PVC", preBindMsg)
|
|
|
|
|
framework.Logf("Creating a PV followed by a%s PVC", preBindMsg)
|
|
|
|
|
|
|
|
|
|
// make the pv and pvc definitions
|
|
|
|
|
pv := MakePersistentVolume(pvConfig)
|
|
|
|
@ -433,7 +432,7 @@ func CreatePVsPVCs(numpvs, numpvcs int, c clientset.Interface, ns string, pvConf
|
|
|
|
|
// WaitOnPVandPVC waits for the pv and pvc to bind to each other.
|
|
|
|
|
func WaitOnPVandPVC(c clientset.Interface, ns string, pv *v1.PersistentVolume, pvc *v1.PersistentVolumeClaim) error {
|
|
|
|
|
// Wait for newly created PVC to bind to the PV
|
|
|
|
|
e2elog.Logf("Waiting for PV %v to bind to PVC %v", pv.Name, pvc.Name)
|
|
|
|
|
framework.Logf("Waiting for PV %v to bind to PVC %v", pv.Name, pvc.Name)
|
|
|
|
|
err := WaitForPersistentVolumeClaimPhase(v1.ClaimBound, c, ns, pvc.Name, framework.Poll, ClaimBindingTimeout)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("PVC %q did not become Bound: %v", pvc.Name, err)
|
|
|
|
@ -489,8 +488,8 @@ func WaitAndVerifyBinds(c clientset.Interface, ns string, pvols PVMap, claims PV
|
|
|
|
|
for pvName := range pvols {
|
|
|
|
|
err := WaitForPersistentVolumePhase(v1.VolumeBound, c, pvName, framework.Poll, PVBindingTimeout)
|
|
|
|
|
if err != nil && len(pvols) > len(claims) {
|
|
|
|
|
e2elog.Logf("WARN: pv %v is not bound after max wait", pvName)
|
|
|
|
|
e2elog.Logf(" This may be ok since there are more pvs than pvcs")
|
|
|
|
|
framework.Logf("WARN: pv %v is not bound after max wait", pvName)
|
|
|
|
|
framework.Logf(" This may be ok since there are more pvs than pvcs")
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
@ -604,7 +603,7 @@ func MakePersistentVolumeClaim(cfg PersistentVolumeClaimConfig, ns string) *v1.P
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cfg.VolumeMode != nil && *cfg.VolumeMode == "" {
|
|
|
|
|
e2elog.Logf("Warning: Making PVC: VolumeMode specified as invalid empty string, treating as nil")
|
|
|
|
|
framework.Logf("Warning: Making PVC: VolumeMode specified as invalid empty string, treating as nil")
|
|
|
|
|
cfg.VolumeMode = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -634,10 +633,10 @@ func createPDWithRetry(zone string) (string, error) {
|
|
|
|
|
for start := time.Now(); time.Since(start) < pdRetryTimeout; time.Sleep(pdRetryPollTime) {
|
|
|
|
|
newDiskName, err = createPD(zone)
|
|
|
|
|
if err != nil {
|
|
|
|
|
e2elog.Logf("Couldn't create a new PD, sleeping 5 seconds: %v", err)
|
|
|
|
|
framework.Logf("Couldn't create a new PD, sleeping 5 seconds: %v", err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("Successfully created a new PD: %q.", newDiskName)
|
|
|
|
|
framework.Logf("Successfully created a new PD: %q.", newDiskName)
|
|
|
|
|
return newDiskName, nil
|
|
|
|
|
}
|
|
|
|
|
return "", err
|
|
|
|
@ -659,10 +658,10 @@ func DeletePDWithRetry(diskName string) error {
|
|
|
|
|
for start := time.Now(); time.Since(start) < pdRetryTimeout; time.Sleep(pdRetryPollTime) {
|
|
|
|
|
err = deletePD(diskName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
e2elog.Logf("Couldn't delete PD %q, sleeping %v: %v", diskName, pdRetryPollTime, err)
|
|
|
|
|
framework.Logf("Couldn't delete PD %q, sleeping %v: %v", diskName, pdRetryPollTime, err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("Successfully deleted PD %q.", diskName)
|
|
|
|
|
framework.Logf("Successfully deleted PD %q.", diskName)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return fmt.Errorf("unable to delete PD %q: %v", diskName, err)
|
|
|
|
@ -710,18 +709,18 @@ func WaitForPVClaimBoundPhase(client clientset.Interface, pvclaims []*v1.Persist
|
|
|
|
|
|
|
|
|
|
// WaitForPersistentVolumePhase waits for a PersistentVolume to be in a specific phase or until timeout occurs, whichever comes first.
|
|
|
|
|
func WaitForPersistentVolumePhase(phase v1.PersistentVolumePhase, c clientset.Interface, pvName string, Poll, timeout time.Duration) error {
|
|
|
|
|
e2elog.Logf("Waiting up to %v for PersistentVolume %s to have phase %s", timeout, pvName, phase)
|
|
|
|
|
framework.Logf("Waiting up to %v for PersistentVolume %s to have phase %s", timeout, pvName, phase)
|
|
|
|
|
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
|
|
|
|
|
pv, err := c.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
e2elog.Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
|
|
|
|
|
framework.Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if pv.Status.Phase == phase {
|
|
|
|
|
e2elog.Logf("PersistentVolume %s found and phase=%s (%v)", pvName, phase, time.Since(start))
|
|
|
|
|
framework.Logf("PersistentVolume %s found and phase=%s (%v)", pvName, phase, time.Since(start))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("PersistentVolume %s found but phase is %s instead of %s.", pvName, pv.Status.Phase, phase)
|
|
|
|
|
framework.Logf("PersistentVolume %s found but phase is %s instead of %s.", pvName, pv.Status.Phase, phase)
|
|
|
|
|
}
|
|
|
|
|
return fmt.Errorf("PersistentVolume %s not in phase %s within %v", pvName, phase, timeout)
|
|
|
|
|
}
|
|
|
|
@ -737,22 +736,22 @@ func WaitForPersistentVolumeClaimsPhase(phase v1.PersistentVolumeClaimPhase, c c
|
|
|
|
|
if len(pvcNames) == 0 {
|
|
|
|
|
return fmt.Errorf("Incorrect parameter: Need at least one PVC to track. Found 0")
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("Waiting up to %v for PersistentVolumeClaims %v to have phase %s", timeout, pvcNames, phase)
|
|
|
|
|
framework.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) {
|
|
|
|
|
phaseFoundInAllClaims := true
|
|
|
|
|
for _, pvcName := range pvcNames {
|
|
|
|
|
pvc, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
e2elog.Logf("Failed to get claim %q, retrying in %v. Error: %v", pvcName, Poll, err)
|
|
|
|
|
framework.Logf("Failed to get claim %q, retrying in %v. Error: %v", pvcName, Poll, err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if pvc.Status.Phase == phase {
|
|
|
|
|
e2elog.Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
|
|
|
|
|
framework.Logf("PersistentVolumeClaim %s found and phase=%s (%v)", pvcName, phase, time.Since(start))
|
|
|
|
|
if matchAny {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
e2elog.Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase)
|
|
|
|
|
framework.Logf("PersistentVolumeClaim %s found but phase is %s instead of %s.", pvcName, pvc.Status.Phase, phase)
|
|
|
|
|
phaseFoundInAllClaims = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -808,7 +807,7 @@ func GetDefaultStorageClassName(c clientset.Interface) (string, error) {
|
|
|
|
|
if len(scName) == 0 {
|
|
|
|
|
return "", fmt.Errorf("No default storage class found")
|
|
|
|
|
}
|
|
|
|
|
e2elog.Logf("Default storage class: %q", scName)
|
|
|
|
|
framework.Logf("Default storage class: %q", scName)
|
|
|
|
|
return scName, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|