diff --git a/e2e/cephfs.go b/e2e/cephfs.go index dbbc1d2e48cd..b340969dae90 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -282,7 +282,7 @@ var _ = Describe("cephfs", func() { appEphemeralPath := cephFSExamplePath + "pod-ephemeral.yaml" By("checking provisioner deployment is running", func() { - err := waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err := waitForDeploymentComplete(f.ClientSet, cephFSDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err) } diff --git a/e2e/deployment.go b/e2e/deployment.go index 32a9fad205b0..b70bf1904510 100644 --- a/e2e/deployment.go +++ b/e2e/deployment.go @@ -18,6 +18,7 @@ package e2e import ( "context" + "errors" "fmt" "time" @@ -124,3 +125,48 @@ func waitForDeploymentInAvailableState(clientSet kubernetes.Interface, name, ns return cond != nil, nil }) } + +// Waits for the deployment to complete. +func waitForDeploymentComplete(clientSet kubernetes.Interface, name, ns string, deployTimeout int) error { + var ( + deployment *appsv1.Deployment + reason string + err error + ) + timeout := time.Duration(deployTimeout) * time.Minute + err = wait.PollImmediate(poll, timeout, func() (bool, error) { + deployment, err = clientSet.AppsV1().Deployments(ns).Get(context.TODO(), name, metav1.GetOptions{}) + if err != nil { + if isRetryableAPIError(err) { + return false, nil + } + e2elog.Logf("deployment error: %v", err) + + return false, err + } + + // TODO need to check rolling update + + // When the deployment status and its underlying resources reach the + // desired state, we're done + if deployment.Status.Replicas == deployment.Status.ReadyReplicas { + return true, nil + } + e2elog.Logf( + "deployment status: expected replica count %d running replica count %d", + deployment.Status.Replicas, + deployment.Status.ReadyReplicas) + reason = fmt.Sprintf("deployment status: %#v", deployment.Status.String()) + + return false, nil + }) + + if errors.Is(err, wait.ErrWaitTimeout) { + err = fmt.Errorf("%s", reason) + } + if err != nil { + return fmt.Errorf("error waiting for deployment %q status to match desired state: %w", name, err) + } + + return nil +} diff --git a/e2e/pod.go b/e2e/pod.go index a8242bd6a6e8..9f0127d09333 100644 --- a/e2e/pod.go +++ b/e2e/pod.go @@ -7,7 +7,6 @@ import ( "strings" "time" - appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -73,52 +72,6 @@ func waitForDaemonSets(name, ns string, c kubernetes.Interface, t int) error { }) } -// Waits for the deployment to complete. - -func waitForDeploymentComplete(name, ns string, c kubernetes.Interface, t int) error { - var ( - deployment *appsv1.Deployment - reason string - err error - ) - timeout := time.Duration(t) * time.Minute - err = wait.PollImmediate(poll, timeout, func() (bool, error) { - deployment, err = c.AppsV1().Deployments(ns).Get(context.TODO(), name, metav1.GetOptions{}) - if err != nil { - if isRetryableAPIError(err) { - return false, nil - } - e2elog.Logf("deployment error: %v", err) - - return false, err - } - - // TODO need to check rolling update - - // When the deployment status and its underlying resources reach the - // desired state, we're done - if deployment.Status.Replicas == deployment.Status.ReadyReplicas { - return true, nil - } - e2elog.Logf( - "deployment status: expected replica count %d running replica count %d", - deployment.Status.Replicas, - deployment.Status.ReadyReplicas) - reason = fmt.Sprintf("deployment status: %#v", deployment.Status.String()) - - return false, nil - }) - - if errors.Is(err, wait.ErrWaitTimeout) { - err = fmt.Errorf("%s", reason) - } - if err != nil { - return fmt.Errorf("error waiting for deployment %q status to match expectation: %w", name, err) - } - - return nil -} - func findPodAndContainerName(f *framework.Framework, ns, cn string, opt *metav1.ListOptions) (string, string, error) { podList, err := f.PodClientNS(ns).List(context.TODO(), *opt) if err != nil { diff --git a/e2e/rbd.go b/e2e/rbd.go index e5ab04e644c0..0978df39179d 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -254,7 +254,7 @@ var _ = Describe("RBD", func() { deployVault(f.ClientSet, deployTimeout) // wait for provisioner deployment - err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err) } @@ -2414,7 +2414,7 @@ var _ = Describe("RBD", func() { if err != nil { e2elog.Failf("timeout waiting for daemonset pods: %v", err) } - err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for deployment to be in running state: %v", err) } diff --git a/e2e/rbd_helper.go b/e2e/rbd_helper.go index 08661c792f91..6d6950fb43a5 100644 --- a/e2e/rbd_helper.go +++ b/e2e/rbd_helper.go @@ -997,7 +997,7 @@ func recreateCSIRBDPods(f *framework.Framework) error { if err != nil { return fmt.Errorf("timeout waiting for daemonset pods: %w", err) } - err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout) if err != nil { return fmt.Errorf("timeout waiting for deployment to be in running state: %w", err) } diff --git a/e2e/upgrade-cephfs.go b/e2e/upgrade-cephfs.go index e01926c6b341..236675841cb9 100644 --- a/e2e/upgrade-cephfs.go +++ b/e2e/upgrade-cephfs.go @@ -148,7 +148,7 @@ var _ = Describe("CephFS Upgrade Testing", func() { Context("Cephfs Upgrade Test", func() { It("Cephfs Upgrade Test", func() { By("checking provisioner deployment is running", func() { - err = waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, cephFSDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err) } @@ -241,7 +241,7 @@ var _ = Describe("CephFS Upgrade Testing", func() { } deployCephfsPlugin() - err = waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, cephFSDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for upgraded deployment %s: %v", cephFSDeploymentName, err) } diff --git a/e2e/upgrade-rbd.go b/e2e/upgrade-rbd.go index 67c45ab10550..2db1e419a311 100644 --- a/e2e/upgrade-rbd.go +++ b/e2e/upgrade-rbd.go @@ -165,7 +165,7 @@ var _ = Describe("RBD Upgrade Testing", func() { appPath := rbdExamplePath + "pod.yaml" By("checking provisioner deployment is running", func() { - err := waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err := waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err) } @@ -260,7 +260,7 @@ var _ = Describe("RBD Upgrade Testing", func() { deployRBDPlugin() - err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) + err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout) if err != nil { e2elog.Failf("timeout waiting for upgraded deployment %s: %v", rbdDeploymentName, err) }