Skip to content

Commit

Permalink
Merge pull request #251 from ryankwilliams/deployment-available-condi…
Browse files Browse the repository at this point in the history
…tion

Add condition for checking if a deployment is available
  • Loading branch information
k8s-ci-robot authored Jun 10, 2023
2 parents c3b933f + e83717d commit aa78221
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 @@ -237,3 +237,12 @@ func TestResourceMatch(t *testing.T) {
}
log.Info("Done")
}

func TestDeploymentAvailable(t *testing.T) {
var err error
deployment := createDeployment("d7", 2, t)
err = For(conditions.New(getResourceManager()).DeploymentAvailable(deployment.Name, deployment.Namespace))
if err != nil {
t.Error("failed waiting for deployment to become available")
}
}

0 comments on commit aa78221

Please sign in to comment.