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

After setup error, do klog.Error not klog.Fatal, and move on #362

Merged

Conversation

codegold79
Copy link
Contributor

When an error happens during a setup step, instead of calling klog.Fatal which causes os.Exit, instead do klog.Error, break, run defer function with clean up steps, and return.

What type of PR is this?

/kind bug

What this PR does / why we need it:

I found this line to be the problem as to why our KinD cluster deletion was not happening as intended. As soon as an error value is passed during a setup step, klog.Fatalf(...) is called:

for _, setup := range setups {
    // context passed down to each setup
    if e.ctx, err = setup.run(e.ctx, e.cfg); err != nil {
        klog.Fatalf("%s failure: %s", setup.role, err)
   }
}

According to klog docs,

// Fatal logs to the FATAL, ERROR, WARNING, and INFO logs,
// prints stack trace(s), then calls OsExit(255).

To reiterate, klog.Fatal is stopping all operations and exiting program with os.Exit. This is not the behavior I want. What I want to happen is for the setup range loop to stop trying to do the setup steps, and try to get to the function return, return m.Run(). However, before returning, I expect the defer block to run next where the finishing steps, like cluster cleanup, happen.

Which issue(s) this PR fixes:

Fixes #188

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Gracefully exit when setup fails

Additional documentation e.g., Usage docs, etc.:


@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. kind/bug Categorizes issue or PR as related to a bug. labels Dec 8, 2023
Copy link

linux-foundation-easycla bot commented Dec 8, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: codegold79 / name: frankly_coding (70b0316)

@k8s-ci-robot k8s-ci-robot added the sig/testing Categorizes an issue or PR as relevant to SIG Testing. label Dec 8, 2023
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Dec 8, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @codegold79!

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 Dec 8, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @codegold79. 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/XS Denotes a PR that changes 0-9 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 Dec 8, 2023
@codegold79
Copy link
Contributor Author

I'm thinking about how to write a test that ensures finish/clean up steps happen after setup step fails. This PR will be a WIP until I can get some tests up.

@codegold79 codegold79 force-pushed the gracefully-exit-when-setup-fails branch from 43c5dab to f32d9a0 Compare December 14, 2023 06:45
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 14, 2023
@codegold79 codegold79 changed the title [WIP] After setup error, do klog.Error not klog.Fatal, and move on After setup error, do klog.Error not klog.Fatal, and move on Dec 14, 2023
@codegold79 codegold79 marked this pull request as ready for review December 14, 2023 18:55
@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 Dec 14, 2023
Copy link
Member

@neolit123 neolit123 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 Dec 14, 2023
@codegold79 codegold79 force-pushed the gracefully-exit-when-setup-fails branch from eb18dd1 to 84903fa Compare December 14, 2023 23:12
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.

HI @codegold79 thanks for taking on this. This is a good start, I left some comments about the structure of your test.

examples/graceful_setup_fail/main_test.go Show resolved Hide resolved
examples/graceful_setup_fail/main_test.go Outdated Show resolved Hide resolved
@vladimirvivien
Copy link
Contributor

@codegold79 apologies for the delay.
let me know if this ready for another round of review.

@codegold79 codegold79 force-pushed the gracefully-exit-when-setup-fails branch from 84903fa to 5541857 Compare February 27, 2024 02:00
@codegold79
Copy link
Contributor Author

codegold79 commented Feb 27, 2024

Thanks, @vladimirvivien! I responded to your first review comment and tried to explain why I had to make a separate example and use TestMain.

As for your second review comment, I made the change as you suggested. I also got rid of the dummy test, as it doesn't help anything except to not trigger a warning that there are no tests.

The thing is, I'm not testing any features, I'm making sure the final actions complete even after a panic in the setup, before any feature tests happen.

PR is ready for review again.

@vladimirvivien
Copy link
Contributor

@codegold79 (apologies for the late reply)
I did spend sometimes to see if this can be tested using a normal test function and I think you are doing the right thing.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 8, 2024
@vladimirvivien
Copy link
Contributor

Hi @codegold79 can you please squash commits. Thanks.

When an error happens during a setup step, instead of calling klog.Fatal
which causes os.Exit, instead do klog.Error, break, run defer function
with clean up steps, and return.

Include setup fail test example in examples directory.

Signed-off-by: F. Gold <fgold@vmware.com>
@codegold79 codegold79 force-pushed the gracefully-exit-when-setup-fails branch from 6c768f2 to 70b0316 Compare April 18, 2024 17:32
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2024
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.

thanks
/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: codegold79, cpanato

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 Apr 18, 2024
@k8s-ci-robot k8s-ci-robot merged commit 67260aa into kubernetes-sigs:main Apr 18, 2024
4 checks passed
@codegold79 codegold79 deleted the gracefully-exit-when-setup-fails branch April 18, 2024 18:10
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. kind/bug Categorizes issue or PR as related to a bug. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gracefully exit when setup fail
5 participants