Skip to content

Commit

Permalink
Add condition for checking if a deployment is available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryankwilliams committed Apr 25, 2023
1 parent 29b8cc8 commit 3d55e45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions klient/wait/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
}
9 changes: 9 additions & 0 deletions klient/wait/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3d55e45

Please sign in to comment.