From fd7c8f375e59ac41a6ac63a59dea38f7003713af Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 29 Oct 2021 14:06:30 +0530 Subject: [PATCH] cleanup: move waitForDeploymentComplete to deployment.go Fixed the order of function parameters Signed-off-by: Prasanna Kumar Kalever --- e2e/cephfs.go | 2 +- e2e/deployment.go | 46 ++++++++++++++++++++++++++++++++++++++++++ e2e/pod.go | 47 ------------------------------------------- e2e/rbd.go | 4 ++-- e2e/rbd_helper.go | 2 +- e2e/upgrade-cephfs.go | 4 ++-- e2e/upgrade-rbd.go | 4 ++-- 7 files changed, 54 insertions(+), 55 deletions(-) diff --git a/e2e/cephfs.go b/e2e/cephfs.go index dbbc1d2e4..b340969da 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 32a9fad20..b70bf1904 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 a8242bd6a..9f0127d09 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 e5ab04e64..0978df391 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 08661c792..6d6950fb4 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 e01926c6b..236675841 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 67c45ab10..2db1e419a 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) }