diff --git a/docs/syntax.md b/docs/syntax.md index 5cc57f5..46a56b4 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -50,6 +50,7 @@ Below you will find the step syntax next to the name of the method it utilizes. - ` [the] deployment is running in namespace ` kdt.KubeClientSet.DeploymentIsRunning - ` [the] data in [the] ConfigMap "" in namespace "" has key "" with value ""` kdt.KubeClientSet.ConfigMapDataHasKeyAndValue - ` [the] persistentvolume exists with status (Available|Bound|Released|Failed|Pending)` kdt.KubeClientSet.PersistentVolExists +- ` [the] persistentvolumeclaim exists with status (Available|Bound|Released|Failed|Pending) in namespace ` kdt.KubeClientSet.PersistentVolClaimExists - ` [the] (clusterrole|clusterrolebinding) with name should be found` kdt.KubeClientSet.ClusterRbacIsFound - ` [the] ingress in [the] namespace [is] [available] on port and path ` kdt.KubeClientSet.IngressAvailable - ` [I] send tps to ingress in [the] namespace [available] on port and path for (minutes|seconds) expecting up to error[s]` kdt.KubeClientSet.SendTrafficToIngress diff --git a/pkg/kube/structured/structured.go b/pkg/kube/structured/structured.go index 8d5026e..765f384 100644 --- a/pkg/kube/structured/structured.go +++ b/pkg/kube/structured/structured.go @@ -236,11 +236,13 @@ func PersistentVolExists(kubeClientset kubernetes.Interface, name, expectedPhase } func PersistentVolClaimExists(kubeClientset kubernetes.Interface, name, expectedPhase string, namespace string) error { - vol, err := GetPersistentVolumeClaim(kubeClientset, name, namespace) + vol, err := util.RetryOnError(&util.DefaultRetry, util.IsRetriable, func() (interface{}, error) { + return GetPersistentVolumeClaim(kubeClientset, name, namespace) + }) if err != nil { return err } - phase := string(vol.Status.Phase) + phase := string(vol.(*corev1.PersistentVolumeClaim).Status.Phase) if phase != expectedPhase { return fmt.Errorf("persistentvolumeclaim had unexpected phase %v, expected phase %v", phase, expectedPhase) } diff --git a/pkg/kube/structured/structured_test.go b/pkg/kube/structured/structured_test.go index 62787be..13137bf 100644 --- a/pkg/kube/structured/structured_test.go +++ b/pkg/kube/structured/structured_test.go @@ -501,7 +501,7 @@ func TestPersistentVolClaimExists(t *testing.T) { kubeClientset: fake.NewSimpleClientset(getResource(t, persistentVolumeClaimType, persistentvolumeClaimName)), name: persistentvolumeClaimName, namespace: "", - expectedPhase: "", + expectedPhase: "Bound", }, wantErr: false, }, @@ -518,7 +518,7 @@ func TestPersistentVolClaimExists(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := PersistentVolClaimExists(tt.args.kubeClientset, tt.args.name, tt.args.namespace, tt.args.expectedPhase); (err != nil) != tt.wantErr { + if err := PersistentVolClaimExists(tt.args.kubeClientset, tt.args.name, tt.args.expectedPhase, tt.args.namespace); (err != nil) != tt.wantErr { t.Errorf("PersistentVolClaimExists() error = %v, wantErr %v", err, tt.wantErr) } }) @@ -885,6 +885,9 @@ func getResourceWithAll(t *testing.T, resourceType, name, namespace, label strin Namespace: namespace, Labels: labels, }, + Status: corev1.PersistentVolumeClaimStatus{ + Phase: corev1.ClaimBound, + }, } case statefulSetType: return &appsv1.StatefulSet{