mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-05 11:39:29 +00:00
e2e: add getPersistentVolumeClaim helper function
added getPersistentVolumeClaim helper function to get the PVC and also try if there is any API error to improve the CI. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
c880061882
commit
89d9ec0823
@ -145,9 +145,7 @@ func unmountCephFSVolume(f *framework.Framework, appName, pvcName string) error
|
|||||||
|
|
||||||
return fmt.Errorf("failed to get pod: %w", err)
|
return fmt.Errorf("failed to get pod: %w", err)
|
||||||
}
|
}
|
||||||
pvc, err := f.ClientSet.CoreV1().
|
pvc, err := getPersistentVolumeClaim(f.ClientSet, f.UniqueName, pvcName)
|
||||||
PersistentVolumeClaims(f.UniqueName).
|
|
||||||
Get(context.TODO(), pvcName, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName)
|
e2elog.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName)
|
||||||
|
|
||||||
|
31
e2e/pvc.go
31
e2e/pvc.go
@ -191,10 +191,33 @@ func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPersistentVolumeClaim returns the PersistentVolumeClaim with the given
|
||||||
|
// name in the given namespace and retries if there is any API error.
|
||||||
|
func getPersistentVolumeClaim(c kubernetes.Interface, namespace, name string) (*v1.PersistentVolumeClaim, error) {
|
||||||
|
var pvc *v1.PersistentVolumeClaim
|
||||||
|
var err error
|
||||||
|
timeout := time.Duration(deployTimeout) * time.Minute
|
||||||
|
err = wait.PollImmediate(1*time.Second, timeout, func() (bool, error) {
|
||||||
|
pvc, err = c.CoreV1().PersistentVolumeClaims(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
e2elog.Logf("Error getting pvc %q in namespace %q: %v", name, namespace, err)
|
||||||
|
if isRetryableAPIError(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, fmt.Errorf("failed to get pvc: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, err
|
||||||
|
})
|
||||||
|
|
||||||
|
return pvc, err
|
||||||
|
}
|
||||||
|
|
||||||
func getPVCAndPV(
|
func getPVCAndPV(
|
||||||
c kubernetes.Interface,
|
c kubernetes.Interface,
|
||||||
pvcName, pvcNamespace string) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) {
|
pvcName, pvcNamespace string) (*v1.PersistentVolumeClaim, *v1.PersistentVolume, error) {
|
||||||
pvc, err := c.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{})
|
pvc, err := getPersistentVolumeClaim(c, pvcNamespace, pvcName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to get PVC: %w", err)
|
return nil, nil, fmt.Errorf("failed to get PVC: %w", err)
|
||||||
}
|
}
|
||||||
@ -213,7 +236,7 @@ func deletePVCAndValidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
|
|||||||
var err error
|
var err error
|
||||||
e2elog.Logf("Deleting PersistentVolumeClaim %v on namespace %v", name, nameSpace)
|
e2elog.Logf("Deleting PersistentVolumeClaim %v on namespace %v", name, nameSpace)
|
||||||
|
|
||||||
pvc, err = c.CoreV1().PersistentVolumeClaims(nameSpace).Get(context.TODO(), name, metav1.GetOptions{})
|
pvc, err = getPersistentVolumeClaim(c, nameSpace, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get pvc: %w", err)
|
return fmt.Errorf("failed to get pvc: %w", err)
|
||||||
}
|
}
|
||||||
@ -265,9 +288,7 @@ func deletePVCAndValidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
|
|||||||
// getBoundPV returns a PV details.
|
// getBoundPV returns a PV details.
|
||||||
func getBoundPV(client kubernetes.Interface, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolume, error) {
|
func getBoundPV(client kubernetes.Interface, pvc *v1.PersistentVolumeClaim) (*v1.PersistentVolume, error) {
|
||||||
// Get new copy of the claim
|
// Get new copy of the claim
|
||||||
claim, err := client.CoreV1().
|
claim, err := getPersistentVolumeClaim(client, pvc.Namespace, pvc.Name)
|
||||||
PersistentVolumeClaims(pvc.Namespace).
|
|
||||||
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get pvc: %w", err)
|
return nil, fmt.Errorf("failed to get pvc: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -414,11 +414,7 @@ var _ = Describe("RBD", func() {
|
|||||||
if pvcNamespace != pvc.Namespace {
|
if pvcNamespace != pvc.Namespace {
|
||||||
e2elog.Failf("expected pvcNamespace %q got %q", pvc.Namespace, pvcNamespace)
|
e2elog.Failf("expected pvcNamespace %q got %q", pvc.Namespace, pvcNamespace)
|
||||||
}
|
}
|
||||||
|
pvcObj, err := getPersistentVolumeClaim(c, pvc.Namespace, pvc.Name)
|
||||||
pvcObj, err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(
|
|
||||||
context.TODO(),
|
|
||||||
pvc.Name,
|
|
||||||
metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Logf("error getting pvc %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
e2elog.Logf("error getting pvc %q in namespace %q: %v", pvc.Name, pvc.Namespace, err)
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,7 @@ import (
|
|||||||
func expandPVCSize(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, size string, t int) error {
|
func expandPVCSize(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, size string, t int) error {
|
||||||
pvcName := pvc.Name
|
pvcName := pvc.Name
|
||||||
pvcNamespace := pvc.Namespace
|
pvcNamespace := pvc.Namespace
|
||||||
|
updatedPVC, err := getPersistentVolumeClaim(c, pvcNamespace, pvcName)
|
||||||
updatedPVC, err := c.CoreV1().
|
|
||||||
PersistentVolumeClaims(pvcNamespace).
|
|
||||||
Get(context.TODO(), pvcName, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error fetching pvc %q with %w", pvcName, err)
|
return fmt.Errorf("error fetching pvc %q with %w", pvcName, err)
|
||||||
}
|
}
|
||||||
@ -120,10 +117,7 @@ func resizePVCAndValidateSize(pvcPath, appPath string, f *framework.Framework) e
|
|||||||
opt := metav1.ListOptions{
|
opt := metav1.ListOptions{
|
||||||
LabelSelector: "app=resize-pvc",
|
LabelSelector: "app=resize-pvc",
|
||||||
}
|
}
|
||||||
|
pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name)
|
||||||
pvc, err = f.ClientSet.CoreV1().
|
|
||||||
PersistentVolumeClaims(pvc.Namespace).
|
|
||||||
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get pvc: %w", err)
|
return fmt.Errorf("failed to get pvc: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -390,9 +390,7 @@ var _ = Describe("CephFS Upgrade Testing", func() {
|
|||||||
opt := metav1.ListOptions{
|
opt := metav1.ListOptions{
|
||||||
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
||||||
}
|
}
|
||||||
pvc, err = f.ClientSet.CoreV1().
|
pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name)
|
||||||
PersistentVolumeClaims(pvc.Namespace).
|
|
||||||
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Failf("failed to get pvc: %v", err)
|
e2elog.Failf("failed to get pvc: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -401,9 +401,7 @@ var _ = Describe("RBD Upgrade Testing", func() {
|
|||||||
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
LabelSelector: fmt.Sprintf("%s=%s", appKey, label[appKey]),
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
pvc, err = f.ClientSet.CoreV1().
|
pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name)
|
||||||
PersistentVolumeClaims(pvc.Namespace).
|
|
||||||
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Failf("failed to get pvc: %v", err)
|
e2elog.Failf("failed to get pvc: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -683,9 +683,7 @@ func validatePVCClone(
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkSum := ""
|
checkSum := ""
|
||||||
pvc, err = f.ClientSet.CoreV1().
|
pvc, err = getPersistentVolumeClaim(f.ClientSet, pvc.Namespace, pvc.Name)
|
||||||
PersistentVolumeClaims(pvc.Namespace).
|
|
||||||
Get(context.TODO(), pvc.Name, metav1.GetOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Failf("failed to get pvc %v", err)
|
e2elog.Failf("failed to get pvc %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user