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 envtest testing docs to extend cronjob example #1521

Merged

Conversation

gabbifish
Copy link
Contributor

This PR adds testing docs to extend the CronJob example and teach people general patterns for writing tests with envtest. It addresses #1518.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 18, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @gabbifish!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. 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/kubebuilder 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 May 18, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @gabbifish. 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 18, 2020
@gabbifish
Copy link
Contributor Author

I'm trying to sign the CLA but when I link my github account to my LF account, I keep seeing There was an error processing your request. :( I'm going to email the LF helpdesk to see what they can do.

@camilamacedo86
Copy link
Member

/ok-to-test

@gabbifish really thank you for your great contribution. Please, see that you need to assign the CLA as well for this contribution be able to be accepted.

@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 May 18, 2020
@gabbifish
Copy link
Contributor Author

gabbifish commented May 18, 2020

All right! My CLA should be signed now.

@k8s-ci-robot k8s-ci-robot added 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 May 19, 2020
@hasbro17
Copy link

Still going through the example itself but this is pretty good and a lot more comprehensive than what I originally had in mind.

@gabbifish
Copy link
Contributor Author

gabbifish commented May 26, 2020

Thank you for the great feedback, @camilamacedo86 and @hasbro17! I've incorporated most of it, and left a question above I would love some more clarification on. :) Unclear why continuous-integration is failing, given that I rebased my changes on master just now to include the testdata changes @camilamacedo86 recently pushed

@pwittrock
Copy link
Contributor

/lgtm

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

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 16, 2020
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

Comments inline about tests. Just some details about a couple of points in the tests, overall structure looks fine. We should put this in the cronjob tutorial though -- it's not really reference.

Also: please stick the boilerplate sections (e.g. imports) in collapsible sections like we do in the other book pages.

docs/book/src/reference/writing-tests.md Outdated Show resolved Hide resolved
}
return true
}, timeout, interval).Should(BeTrue())
Expect(createdCronjob.Spec.Schedule).Should(Equal("1 * * * *"))
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment here or something explaining this? I'm assuming it's a sanity test for when you have pruning turned on on the API server (CRD v1 or CRD v1beta1 w/ conversion), but it's worth pointing out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't as much a sanity test for pruning as it is a check to ensure that our CronJob spec Schedule field matches the parameters we passed in. (I don't think Schedule is supposed to ever get pruned?) Please let me know if I misunderstood something!

Copy link
Contributor

@DirectXMan12 DirectXMan12 Jun 22, 2020

Choose a reason for hiding this comment

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

I think i'm just not understanding the failure condition you're testing for. The two failure modes I can imaging are conversion screwing up something during round-tripping (which I forgot about when leaving the comment here) or pruning removing the field. Otherwise, "field passed in" == "field read" should be ensured by the apiserver. If not, somethings terribly wrong with the apiserver (hence referring to it above as a "sanity test").

Copy link
Contributor Author

@gabbifish gabbifish Jun 25, 2020

Choose a reason for hiding this comment

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

This failure condition was originally created to check for "field passed in" == "field read" (which is ensured by the APIserver). Pruning shouldn't happen here, given that Schedule is a required CronJob Spec field. The idea for adding this came from some conversations @camilamacedo86 and I had earlier (see #1521 (comment)). The conversion point you bring up is still valid and potentially worth leaving the test for, though.

Given that the consistency of a created object and its input spec is ensured by/tested in the apiserver, I think it could make sense to just delete this check or add a comment mentioning testing schedule string conversion behavior--what do you think?

Copy link
Contributor Author

@gabbifish gabbifish Jun 28, 2020

Choose a reason for hiding this comment

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

I went with the second option (add extra comment to clarify that this tests the conversion of the Schedule string). I think this should be ready for final review? :)

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gabbifish, pwittrock

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 Jun 21, 2020
@gabbifish
Copy link
Contributor Author

gabbifish commented Jun 21, 2020

Thank you for the helpful feedback, @DirectXMan12! In my first follow-up commit, I incorporated all of it (except for one follow-up question I asked above). In the second follow-up commit, I put the Writing Tests page under the CronJob tutorial and hoisted the envtest docs up to section 4.9 in the Reference section. Let me know what you think :)

@camilamacedo86
Copy link
Member

PS.: For we are able to merge the commits need to be squashed

@gabbifish
Copy link
Contributor Author

/retest

@gabbifish
Copy link
Contributor Author

gabbifish commented Jun 21, 2020

rebased! now playing a game of whack-a-mole with the e2e tests 😂 (I think they are acting flaky at the moment).

@pwittrock
Copy link
Contributor

/retest

@pwittrock
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 29, 2020
@k8s-ci-robot k8s-ci-robot merged commit 42ae4b8 into kubernetes-sigs:master Jun 29, 2020
@gabbifish gabbifish deleted the add-envtest-testing-docs branch June 29, 2020 22:37
gabbifish pushed a commit to gabbifish/kubebuilder that referenced this pull request Jun 29, 2020
…sting-docs

Add envtest testing docs to extend cronjob example
gabbifish pushed a commit to gabbifish/kubebuilder that referenced this pull request Jul 2, 2020
…sting-docs

Add envtest testing docs to extend cronjob example
gabbifish pushed a commit to gabbifish/kubebuilder that referenced this pull request Jul 3, 2020
…sting-docs

Add envtest testing docs to extend cronjob example
@camilamacedo86
Copy link
Member

@pwittrock we need fix this one. See that it is not showing the in the book and then the previous info also shows no longer appears.

gabbifish pushed a commit to gabbifish/kubebuilder that referenced this pull request Aug 31, 2020
…sting-docs

Add envtest testing docs to extend cronjob example
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. 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.

7 participants