From 3d55e45f1fca63f4de9eeb532de26f0210190df3 Mon Sep 17 00:00:00 2001 From: Ryan Williams <3375653+ryankwilliams@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:13:58 -0400 Subject: [PATCH] Add condition for checking if a deployment is available This change adds a new condition to check if a deployment is available. The wait condition only requires the user to provide the deployment name and namespace and the condition method handles building the deployment object/checking the deployment condition for a match. With this new condition, it will remove the need for the user to build the deployment object and call deployment condition match condition in their code bases. --- klient/wait/conditions/conditions.go | 11 +++++++++++ klient/wait/wait_test.go | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/klient/wait/conditions/conditions.go b/klient/wait/conditions/conditions.go index f4d04099..6e81962e 100644 --- a/klient/wait/conditions/conditions.go +++ b/klient/wait/conditions/conditions.go @@ -27,6 +27,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" apimachinerywait "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/e2e-framework/klient/k8s" @@ -292,3 +293,13 @@ func (c *Condition) JobCompleted(job k8s.Object) apimachinerywait.ConditionWithC func (c *Condition) JobFailed(job k8s.Object) apimachinerywait.ConditionWithContextFunc { return c.JobConditionMatch(job, batchv1.JobFailed, v1.ConditionTrue) } + +// DeploymentAvailable is a helper function used to check if the deployment condition appsv1.DeploymentAvailable +// has reached v1.ConditionTrue state +func (c *Condition) DeploymentAvailable(name, namespace string) apimachinerywait.ConditionWithContextFunc { + return c.DeploymentConditionMatch( + &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}}, + appsv1.DeploymentAvailable, + v1.ConditionTrue, + ) +} diff --git a/klient/wait/wait_test.go b/klient/wait/wait_test.go index 8396a7d9..e594c5ec 100644 --- a/klient/wait/wait_test.go +++ b/klient/wait/wait_test.go @@ -159,6 +159,15 @@ func TestResourceListMatchN(t *testing.T) { log.Info("Done") } +func TestDeploymentAvailable(t *testing.T) { + var err error + deployment := createDeployment("d5", 2, t) + err = For(conditions.New(getResourceManager()).DeploymentAvailable(deployment.Name, deployment.Namespace)) + if err != nil { + t.Error("failed waiting for deployment to become available") + } +} + func TestResourcesMatch(t *testing.T) { var err error go func() {