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

test(crd-generator): approval tests for crd-generator-api-v2 #5991

Merged
merged 2 commits into from
May 8, 2024

Conversation

manusa
Copy link
Member

@manusa manusa commented May 7, 2024

Description

Part of #5951 / #5948

Supersedes closes #5978

test(crd-generator): approval tests for crd-generator-api-v2

Relates to:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@manusa manusa added the wip label May 7, 2024
@manusa manusa self-assigned this May 7, 2024
@manusa
Copy link
Member Author

manusa commented May 7, 2024

Hi @shawkins,

Maybe you can help out here.

This PR adds the tests to ensure feature parity for both versions of the crd-generator.

However, there's a misbehavior, but I'm unsure if this is because something is missing in the new implementation or there's a bug in the old one.

The approval file CRDGeneratorApprovalTest.approvalTest.containingjsons.sample.fabric8.io.v1.approved.yml contains the following lines:

foo:
properties:
configAsMap:
additionalProperties:
type: "object"
type: "object"
x-kubernetes-preserve-unknown-fields: true
type: "object"
x-kubernetes-preserve-unknown-fields: true

which are not generated with the new implementation.

This fragment looks instead like:

              foo:
                type: "object"

@manusa manusa added this to the 6.13.0 milestone May 7, 2024 — with automated-tasks
@shawkins
Copy link
Contributor

shawkins commented May 7, 2024

@manusa the new one is correct with the default settings. We now have a CRDGenerator property to control whether x-kubernetes-preserve-unknown-fields is implicitly inferred from anyGetter/Setter - it defaults to false. It would need to use the crd annotation for preserve unknown or turn on the implicit setting for this to be seen as x-kubernetes-preserve-unknown-fields.

At the very least, the old one should not have been adding both a configAsMap property and setting x-kubernetes-preserve-unknown-fields - because that was derived from configAsMap.

@manusa
Copy link
Member Author

manusa commented May 7, 2024

Thx, yes, it looked more like a bug from the former implementation.
However, I'm not sure it's an easy fix (might break other stuff while fixing it). It might be better to just remove this part from the test (Class).

Thoughts?

/cc @metacosm @andreaTP @baloo42

@manusa manusa force-pushed the test/crd-generator-v2 branch from 03da73d to a04ca3d Compare May 8, 2024 07:19
@baloo42
Copy link
Contributor

baloo42 commented May 8, 2024

IMHO fixing the test for now is better here than changing something in v1 or v2.

Maybe we can add some test cases later to show the differences or a Wiki page to document such things.

@manusa
Copy link
Member Author

manusa commented May 8, 2024

👍 I removed the conflicting field + class.
The test case is still valid since it has a JsonNode field that properly maps to x-kubernetes-preserve-unknown-fields: true

@manusa manusa removed the wip label May 8, 2024
@manusa manusa marked this pull request as ready for review May 8, 2024 08:46
Copy link

sonarqubecloud bot commented May 8, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM

@manusa manusa merged commit 8086d29 into fabric8io:main May 8, 2024
21 checks passed
@manusa manusa deleted the test/crd-generator-v2 branch May 8, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants