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

GIT-60: enable helper function for conditional waits #73

Merged

Conversation

harshanarayana
Copy link
Contributor

Closes #60

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 11, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @harshanarayana!

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 Nov 11, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @harshanarayana. 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 sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2021
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2021
@vladimirvivien vladimirvivien self-assigned this Nov 11, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 12, 2021
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.

@harshanarayana This is a great start and captures most of everything I was thinking about. I left some comments because I think this can be refined further.

Design consideration

The main thing that I would like to see is to be able to invoke the For function from the wait package without the need to create a wait.Interface instance. One way that could be done is to create a new subpackage wait/cond where all pre-conditions are defined. The cond package would expose Condition value with all the pre-conditions defined

// package wait/cond
type Condition struct {
    res *resources.Resources
}
func New(*resources.Resrouces) *Condition
func (c *Condition) ResourceScaled(...)
func (c *Condition) JobMatche(...)
func (c *Condition)
...

Then, using the wait package could look like this:

import ".../.../wait"
import ".../.../wait/cond"

func DoK8sStuff(){
    pod := createPod(...)
    wait.For(cond.New(*resources.Resources).PodRunning(&pod))
}

Hope this makes sense.

internal/testutil/setup.go Outdated Show resolved Hide resolved
internal/testutil/setup.go Outdated Show resolved Hide resolved
klient/client.go Outdated Show resolved Hide resolved
klient/client.go Outdated Show resolved Hide resolved
klient/client.go Outdated Show resolved Hide resolved
klient/wait/wait.go Outdated Show resolved Hide resolved
klient/wait/wait.go Outdated Show resolved Hide resolved
@harshanarayana
Copy link
Contributor Author

Hope this makes sense.

Absolutely. I like the notion of adding an inlined resource so that we can use multiple difference instance of the resources type to our advantage as required. Let me do the changes accordingly.

@harshanarayana
Copy link
Contributor Author

@vladimirvivien I have addressed all the changes you suggested and refactored it accordingly. PTAL when you manage to get some time. Thanks

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.

@harshanarayana First apologies for the late review.
Anyway, this is awesome work and you delivered exactly what the design called for.
I left a few comments (mostly housekeeping and cosmetics). Once done, this should be merged soon!!!!

klient/internal/testutil/setup.go Outdated Show resolved Hide resolved
klient/internal/testutil/setup.go Outdated Show resolved Hide resolved
klient/wait/conditions/conditions.go Outdated Show resolved Hide resolved
klient/wait/conditions/conditions.go Show resolved Hide resolved

func (c *Condition) ResourceScaled(obj k8s.Object, scaleFetcher func(object k8s.Object) int32, replica int32) apimachinerywait.ConditionFunc {
return func() (done bool, err error) {
log.Printf("Checking if the resource %s/%s has been scaled to %d", obj.GetNamespace(), obj.GetName(), replica)
Copy link
Contributor

Choose a reason for hiding this comment

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

These log statements will be a bit verbose when used. I would consider removing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I make these optional? By default it will be turned off but can be enabled by the users if required. Would that be ok ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think outputting logs from the framework code could be an issue because, as a user, when I write tests, I don't expect extra output unless I use something like t.Log (etc).

As far as making it optional, here is what we can do:

  • Get this merged (without logs)
  • Create a new PR to introduce more robust log capabilities via a level log framework
  • Then we can research for something that make sense for the project.
    How does that sound ?

klient/wait/main_test.go Outdated Show resolved Hide resolved
klient/wait/wait_test.go Show resolved Hide resolved
@harshanarayana
Copy link
Contributor Author

First apologies for the late review.

No worries at all @vladimirvivien . Thanks again for taking your time to review this. I have addressed the changes you requested. Let me know if you think anything else needs to be modified

@harshanarayana harshanarayana marked this pull request as ready for review November 18, 2021 17:23
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 18, 2021
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

/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 Nov 18, 2021
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.

@harshanarayana
I still have reservation about how logging is done (it feels a bit one-off). I left comments.
Other than than that, we should be ready to merge soon.

klient/wait/wait_test.go Outdated Show resolved Hide resolved
klient/wait/conditions/conditions.go Outdated Show resolved Hide resolved
@harshanarayana harshanarayana mentioned this pull request Nov 19, 2021
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.

@harshanarayana Awesome work.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harshanarayana, 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:

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 19, 2021
@k8s-ci-robot k8s-ci-robot merged commit 9169c87 into kubernetes-sigs:main Nov 19, 2021
@vladimirvivien
Copy link
Contributor

@harshanarayana
Couple things I just realized we need

  • Add an example test in the examples dir
  • A quick documentation blurb in README.md
    Please open a new issue you or someone else can get that done.

Thanks again!!!

@harshanarayana
Copy link
Contributor Author

@vladimirvivien let me take care of it right away.

@harshanarayana
Copy link
Contributor Author

  • Please open a new issue you or someone else can get that done.

#78

@helayoty
Copy link
Contributor

helayoty commented Dec 3, 2021

This is a very needed feature, thanks @harshanarayana for the great effort. @vladimirvivien When do we expect a new release so we can use it?

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce support for Waiting for given cluster conditions
5 participants