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 API validation test framework #1919

Merged
merged 4 commits into from
Mar 4, 2024

Conversation

mdbooth
Copy link
Contributor

@mdbooth mdbooth commented Mar 1, 2024

This series adds a framework for testing API validations via calls to a running apiserver using envtest. It initially adds only a couple of example tests.

Firstly we update ginkgo to have the same version in tools and the main module, because otherwise it emits a warning.

The we fix an actual bug discovered by the example test: managedSecurityGroups was missing an omitempty, which caused creation of a bare cluster object to fail. We will likely want to visit the minimum set of required parameters, but this was an obvious bug.

Running the tests requires a set of assets to have been downloaded, which the make test target conveniently does for us. However, it wasn't possible to restrict make test to only the tests we are interested in, so we give it an optional TEST_PATHS parameters.

Finally we add a new test suite with 2 trivial tests, enough to demonstrate that it is working correctly.

TEST_PATHS defaults to the previous hardcoded value of './...', but can
now be overridden. e.g. To run just the controller tests:

  make test TEST_PATHS=./controllers/...
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 1, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mdbooth

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 Mar 1, 2024
Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit 4d3e79c
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65e5b433a1a5a60008618fbc
😎 Deploy Preview https://deploy-preview-1919--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 1, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 1, 2024

/cc @JoelSpeed whose CPMS code I cribbed from heavily.

Comment on lines 60 to 64
Expect((&infrav1.OpenStackMachineTemplateWebhook{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineTemplate webhook should be registered with manager")
Expect((&infrav1.OpenStackMachineTemplateList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineTemplateList webhook should be registered with manager")
Expect((&infrav1.OpenStackCluster{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackCluster webhook should be registered with manager")
Expect((&infrav1.OpenStackClusterTemplate{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackClusterTemplate webhook should be registered with manager")
Expect((&infrav1.OpenStackMachine{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachine webhook should be registered with manager")
Expect((&infrav1.OpenStackMachineList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineList webhook should be registered with manager")
Expect((&infrav1.OpenStackClusterList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackClusterList webhook should be registered with manager")

Choose a reason for hiding this comment

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

In general it's bad practice to have code attached to your API types, introduces dependencies and makes it hard for people to import your API types. We've resolved this issue in core CAPI, will want to resolve in wider ecosystem too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. We've had a user report about that, too. It's on the TODO list!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reference: #1891

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JoelSpeed Just for you: #1920


minorInt, err := strconv.Atoi(serverVersion.Minor)
Expect(err).ToNot(HaveOccurred())
Expect(minorInt).To(BeNumerically(">=", 25), fmt.Sprintf("This test suite requires a Kube API server of at least version 1.25, current version is 1.%s", serverVersion.Minor))

Choose a reason for hiding this comment

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

Depending on which validations you are using, this number may be greater. What is the minimum supported version for running this controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now we're not relying any anything new. We don't even require CEL support. However, I deliberate left this in because:

  • 1.25 is probably a reasonable support minimum right now
  • You keep badgering me to add CEL support, and I'm hoping to get to it soon

@mdbooth mdbooth force-pushed the apivalidationtests branch 4 times, most recently from 23ab488 to a6f2a46 Compare March 1, 2024 17:38
@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 Mar 1, 2024
@jichenjc
Copy link
Contributor

jichenjc commented Mar 4, 2024

/lgtm
/hold

add a hold in case anyone want to see this again

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 4, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2024
Copy link
Contributor

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

Awesome!
Just one tiny nit below

test/e2e/suites/apivalidations/suite_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 4, 2024

Interesting that it didn't re-run the tests 🤔

/test all

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 4, 2024

/test pull-cluster-api-provider-openstack-test

Copy link
Contributor

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

/lgtm
/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 Mar 4, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2024
@k8s-ci-robot k8s-ci-robot merged commit 23b9f34 into kubernetes-sigs:main Mar 4, 2024
9 checks passed
@mdbooth mdbooth deleted the apivalidationtests branch March 4, 2024 13:19
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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants