mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
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:
parent
6e819b60e7
commit
fd7c8f375e
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
47
e2e/pod.go
47
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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user