Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition for checking if a deployment is available #251

Merged
merged 1 commit into from
Jun 10, 2023
Merged

Add condition for checking if a deployment is available #251

merged 1 commit into from
Jun 10, 2023

Conversation

ryankwilliams
Copy link
Contributor

Change

This PR 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 will handle 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.

Before

import (
    "os"
    appsv1 "k8s.io/api/apps/v1"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    "sigs.k8s.io/e2e-framework/klient/wait"
    "sigs.k8s.io/e2e-framework/klient/wait/conditions"
)

deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "deployment", Namespace: "namespace"}}
err = wait.For(conditions.New(client).DeploymentConditionMatch(deployment, appsv1.DeploymentAvailable, v1.ConditionTrue))
if err != nil {
    fmt.Printf("error waiting for deployment to become available: %v", err)
    os.Exit(1)
}

After

import (
    "os"
    "sigs.k8s.io/e2e-framework/klient/wait"
    "sigs.k8s.io/e2e-framework/klient/wait/conditions"
)

err = wait.For(conditions.New(client).DeploymentAvailable("deployment", "namespace"))
if err != nil {
    fmt.Printf("error waiting for deployment to become available: %v", err)
    os.Exit(1)
}

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 25, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ryankwilliams / name: Ryan Williams (3d55e45)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 25, 2023
@k8s-ci-robot k8s-ci-robot requested a review from cpanato April 25, 2023 20:39
@k8s-ci-robot k8s-ci-robot added the sig/testing Categorizes an issue or PR as relevant to SIG Testing. label Apr 25, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @ryankwilliams!

It looks like this is your first PR to kubernetes-sigs/e2e-framework 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/e2e-framework has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 25, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @ryankwilliams. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 25, 2023
@ShwethaKumbla
Copy link
Member

@ryankwilliams Thanks for simplifying the usage.

@ShwethaKumbla
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 28, 2023
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.
Copy link
Member

@ShwethaKumbla ShwethaKumbla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
/cc @vladimirvivien

@ShwethaKumbla
Copy link
Member

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 29, 2023
@vladimirvivien
Copy link
Contributor

vladimirvivien commented May 3, 2023

Thanks @ryankwilliams for the contribution.
While this is a helper, I am concerned it too much of a one-of. My issue is that it is specific to a single API resource. If we have one for Deployment, should we not have one for, say Pod, or Service, etc.

Now, if you can figure out a way to make the helper more generic, then I think that would be better for the e2e-framework API usability. For instance, you could do something that creates a condition for any resource

err = wait.For(conditions.New(client).ResourceAvailable(corev1.ObjectMeta{Name:"my-deployment", Namespace:"my-ns"}, schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployment"}))
if err != nil {
    fmt.Printf("error waiting for deployment to become available: %v", err)
    os.Exit(1)
}

Or, follow the options api pattern that is already used in the e2e-framework

err = wait.For(conditions.New(client).ResourceAvailable(
    conditions.WithObjectName("my-deployment"),
    conditions.WithNamespace("Namespace"), 
    conditions.WithObjectGVR("apps", "v1", "deployment"),
))
if err != nil {
    fmt.Printf("error waiting for deployment to become available: %v", err)
    os.Exit(1)
}

@ryankwilliams
Copy link
Contributor Author

Thank you @vladimirvivien for your reply!

I was following in the same steps as lines 269 -> 294 where helper functions existed to see if a pod was ready, containers ready, pod running, job completed or job failed.

Thank you for sharing the code examples, I will rethink on this to see about making it into a more generic helper.

@vladimirvivien
Copy link
Contributor

@ryankwilliams you were absolutely right to think this was the proper direction to take originally (based on the code link in your last comment). I should have made that point in the original PR.

Nevertheless, if you have time to do a generic version of wait, then you are welcome to. If not, we can accept the original changes since there is precedence.

@ryankwilliams
Copy link
Contributor Author

Hi @vladimirvivien, Thank you for your response. My apologies on the delayed follow up. I have not had time to work on a generic version of wait yet. For now, if you would like to accept my original change, please feel free to else I can close this.

Copy link
Contributor

@vladimirvivien vladimirvivien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 10, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ryankwilliams, ShwethaKumbla, vladimirvivien

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ShwethaKumbla,vladimirvivien]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit aa78221 into kubernetes-sigs:main Jun 10, 2023
@ryankwilliams ryankwilliams deleted the deployment-available-condition branch June 12, 2023 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants