cleanup: move waitForDeploymentComplete to deployment.go

Fixed the order of function parameters

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2021-10-29 14:06:30 +05:30 committed by mergify[bot]
parent 6e819b60e7
commit fd7c8f375e
7 changed files with 54 additions and 55 deletions

View File

@ -282,7 +282,7 @@ var _ = Describe("cephfs", func() {
appEphemeralPath := cephFSExamplePath + "pod-ephemeral.yaml" appEphemeralPath := cephFSExamplePath + "pod-ephemeral.yaml"
By("checking provisioner deployment is running", 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 { if err != nil {
e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err) e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err)
} }

View File

@ -18,6 +18,7 @@ package e2e
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"time" "time"
@ -124,3 +125,48 @@ func waitForDeploymentInAvailableState(clientSet kubernetes.Interface, name, ns
return cond != nil, nil 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
}

View File

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors" apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 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) { func findPodAndContainerName(f *framework.Framework, ns, cn string, opt *metav1.ListOptions) (string, string, error) {
podList, err := f.PodClientNS(ns).List(context.TODO(), *opt) podList, err := f.PodClientNS(ns).List(context.TODO(), *opt)
if err != nil { if err != nil {

View File

@ -254,7 +254,7 @@ var _ = Describe("RBD", func() {
deployVault(f.ClientSet, deployTimeout) deployVault(f.ClientSet, deployTimeout)
// wait for provisioner deployment // wait for provisioner deployment
err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err) e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err)
} }
@ -2414,7 +2414,7 @@ var _ = Describe("RBD", func() {
if err != nil { if err != nil {
e2elog.Failf("timeout waiting for daemonset pods: %v", err) 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 { if err != nil {
e2elog.Failf("timeout waiting for deployment to be in running state: %v", err) e2elog.Failf("timeout waiting for deployment to be in running state: %v", err)
} }

View File

@ -997,7 +997,7 @@ func recreateCSIRBDPods(f *framework.Framework) error {
if err != nil { if err != nil {
return fmt.Errorf("timeout waiting for daemonset pods: %w", err) 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 { if err != nil {
return fmt.Errorf("timeout waiting for deployment to be in running state: %w", err) return fmt.Errorf("timeout waiting for deployment to be in running state: %w", err)
} }

View File

@ -148,7 +148,7 @@ var _ = Describe("CephFS Upgrade Testing", func() {
Context("Cephfs Upgrade Test", func() { Context("Cephfs Upgrade Test", func() {
It("Cephfs Upgrade Test", func() { It("Cephfs Upgrade Test", func() {
By("checking provisioner deployment is running", 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 { if err != nil {
e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err) e2elog.Failf("timeout waiting for deployment %s: %v", cephFSDeploymentName, err)
} }
@ -241,7 +241,7 @@ var _ = Describe("CephFS Upgrade Testing", func() {
} }
deployCephfsPlugin() deployCephfsPlugin()
err = waitForDeploymentComplete(cephFSDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) err = waitForDeploymentComplete(f.ClientSet, cephFSDeploymentName, cephCSINamespace, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("timeout waiting for upgraded deployment %s: %v", cephFSDeploymentName, err) e2elog.Failf("timeout waiting for upgraded deployment %s: %v", cephFSDeploymentName, err)
} }

View File

@ -165,7 +165,7 @@ var _ = Describe("RBD Upgrade Testing", func() {
appPath := rbdExamplePath + "pod.yaml" appPath := rbdExamplePath + "pod.yaml"
By("checking provisioner deployment is running", func() { By("checking provisioner deployment is running", func() {
err := waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) err := waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err) e2elog.Failf("timeout waiting for deployment %s: %v", rbdDeploymentName, err)
} }
@ -260,7 +260,7 @@ var _ = Describe("RBD Upgrade Testing", func() {
deployRBDPlugin() deployRBDPlugin()
err = waitForDeploymentComplete(rbdDeploymentName, cephCSINamespace, f.ClientSet, deployTimeout) err = waitForDeploymentComplete(f.ClientSet, rbdDeploymentName, cephCSINamespace, deployTimeout)
if err != nil { if err != nil {
e2elog.Failf("timeout waiting for upgraded deployment %s: %v", rbdDeploymentName, err) e2elog.Failf("timeout waiting for upgraded deployment %s: %v", rbdDeploymentName, err)
} }