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

Enhance e2e Tests: Validate Conversion with Mock Scenario #4297

Open
camilamacedo86 opened this issue Nov 6, 2024 · 4 comments
Open

Enhance e2e Tests: Validate Conversion with Mock Scenario #4297

camilamacedo86 opened this issue Nov 6, 2024 · 4 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. testing
Milestone

Comments

@camilamacedo86
Copy link
Member

What broke? What's expected?

Description:

Enhance the existing e2e tests by ensuring that a valid mock scenario is created and verifying that the conversion webhook functions as expected. Currently, there is a TODO note to add checks and validate the conversion’s success in our e2e tests, but this validation has not yet been implemented.

Reference:

The relevant section can be found here: plugin_cluster_test.go#L390-L392.

Enhancements Needed:

  1. Validate Mock Data: Ensure that the mock data used in the test is valid and sufficient to simulate a realistic conversion scenario.

  2. Conversion Check: Implement a check to validate that the conversion occurred as expected according to the webhook’s intended functionality.

  3. Adjust Mock Data if Necessary: Modify the mock data setup if needed to ensure it aligns with the requirements for validating the conversion webhook accurately.

You can check the changes in PR #4296 to understand the current setup, expected outcomes, and to help move forward with this task.

Reproducing this issue

No response

KubeBuilder (CLI) Version

master

PROJECT version

No response

Plugin versions

No response

Other versions

No response

Extra Labels

No response

@camilamacedo86 camilamacedo86 added kind/bug Categorizes issue or PR as related to a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. testing and removed kind/bug Categorizes issue or PR as related to a bug. labels Nov 6, 2024
@robinlovell13
Copy link

/assign

@robinlovell13
Copy link

Hi! This is my first Kubernetes issue. Can the mock data yaml file be found somewhere or is it dynamically generated? Where can I find documentation on the structure of v1 and v2 ConversionTest objects? Thank you for any guidance!

@camilamacedo86 camilamacedo86 added this to the webhook milestone Nov 25, 2024
@sureshkrishnan-v
Copy link

/assign

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Dec 11, 2024

Hi @robinlovell13 @sureshkrishnan-v

The goal of the change is replace the TODO for the code implementation here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/v4/plugin_cluster_test.go#L412-L413

If you check here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/v4/plugin_cluster_test.go#L69-L103

You can see the test scenarios covered.

Then, you can see that the mock tests are generating calling the tool, uncomment and injecting code here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/v4/generate_test.go

In this way, to answer Where can I find documentation on the structure of v1 and v2 ConversionTest objects?

See the code implementation to generate the conversion webhook used on the tests:

// scaffoldConversionWebhook sets up conversion webhooks for testing the ConversionTest API
func scaffoldConversionWebhook(kbc *utils.TestContext) {
By("scaffolding conversion webhooks for testing ConversionTest v1 to v2 conversion")
// Create API for v1 (hub) with conversion enabled
err := kbc.CreateAPI(
"--group", kbc.Group,
"--version", "v1",
"--kind", "ConversionTest",
"--controller=true",
"--resource=true",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to create v1 API for conversion testing")
// Create API for v2 (spoke) without a controller
err = kbc.CreateAPI(
"--group", kbc.Group,
"--version", "v2",
"--kind", "ConversionTest",
"--controller=false",
"--resource=true",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to create v2 API for conversion testing")
// Create the conversion webhook for v1
By("setting up the conversion webhook for v1")
err = kbc.CreateWebhook(
"--group", kbc.Group,
"--version", "v1",
"--kind", "ConversionTest",
"--conversion",
"--spoke", "v2",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "failed to create conversion webhook for v1")
// Insert Size field in v1
By("implementing the size spec in v1")
ExpectWithOffset(1, pluginutil.InsertCode(
filepath.Join(kbc.Dir, "api", "v1", "conversiontest_types.go"),
"Foo string `json:\"foo,omitempty\"`",
"\n\tSize int `json:\"size,omitempty\"` // Number of desired instances",
)).NotTo(HaveOccurred(), "failed to add size spec to conversiontest_types v1")
// Insert Replicas field in v2
By("implementing the replicas spec in v2")
ExpectWithOffset(1, pluginutil.InsertCode(
filepath.Join(kbc.Dir, "api", "v2", "conversiontest_types.go"),
"Foo string `json:\"foo,omitempty\"`",
"\n\tReplicas int `json:\"replicas,omitempty\"` // Number of replicas",
)).NotTo(HaveOccurred(), "failed to add replicas spec to conversiontest_conversion.go v2")
err = pluginutil.ReplaceInFile(filepath.Join(kbc.Dir, "api/v2/conversiontest_conversion.go"),
"// TODO(user): Implement conversion logic from v1 to v2",
`src.Spec.Size = dst.Spec.Replicas`)
Expect(err).NotTo(HaveOccurred(), "failed to implement conversion logic from v1 to v2")
err = pluginutil.ReplaceInFile(filepath.Join(kbc.Dir, "api/v2/conversiontest_conversion.go"),
"// TODO(user): Implement conversion logic from v2 to v1",
`src.Spec.Replicas = dst.Spec.Size`)
Expect(err).NotTo(HaveOccurred(), "failed to implement conversion logic from v2 to v1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. testing
Projects
None yet
Development

No branches or pull requests

3 participants