-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feature: add a v2 crd generator based on jackson #5949
Conversation
closes: fabric8io#5948 also removes v1beta1 from the new code
I went with crdv2 as the package name - but that can be changed of course. |
I think we should handle this as a bug for the v1 generator and also fix it. If not, the new approval tests (#5943) would also fail sometimes. The outcome should be always deterministic. |
@baloo42 I've updated the test for v2 to keep this pr moving forward. @matteriben based upon #5942 (reply in thread) it sounds like we're moving forward with leaving the type as string for those shape tests, which puts us in a similar situation as sorting the required list - the v1 implementation should be updated to match. We'll track making these changes with #5951. That just leaves two differences (that we currently know of) to account for. |
This is a feature, great!
IIRC that's it, in any case printer columns are just for human consumption, we can solve any issue at a later stage without a significant risk of breaking user code badly.
Looking at how ppl are using things I would not be surprised if we take the opinionated decision to add Currently on the phone and I'll be out until Mon, but let me know if any additional input from me is needed to progress here and I'll try to answer asap. |
also removing another reference to CustomResource
Ok, to keep this pr moving forward I'll update the results here to expect the actual type.
The logic here is a little broader - so I'm wondering if it needs to be more limited. The concern is that the object model's intent with using additional properties is to increase compatibility - not that the real schema of ObjectMeta etc. actually calls for preserve unknown. I'm thinking that we'll either need to just look for the PreserveUnknownFields annotation or let it be user configurable in some other way to elect whether anyGetter / anySetter means preserve unknown fields. |
Marking as ready for review as all current tests pass. Let me know what needs addressed before this gets committed. This also wires up parallel execution (should likely now default to true) #5952 and exposes two new options for the crd generator:
Recap of some other changes:
@metacosm this should be good now to test out with quarkus |
c61f03b
to
73997e3
Compare
* This class encapsulates the common behavior between different CRD generation logic. The | ||
* intent is that each CRD spec version is implemented as a sub-class of this one. | ||
*/ | ||
public abstract class AbstractCustomResourceHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why this is a class instead of an interface?
It's my understanding that we can have a interface CustomResourceHandler
and then an implementation V1CustomResourceHandler
or CustomResourceHandlerV1
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why this is a class instead of an interface?
Not really. It used to hold common state and have a common method for dealing with printer columns. My intent was to add back the method for printer columns, but didn't bother yet.
It's my understanding that we can have a interface CustomResourceHandler and then an implementation V1CustomResourceHandler or CustomResourceHandlerV1, right?
Correct, it seemed fine to leave in the abstraction layer, used here and for AbstractJsonSchema, but it's not really needed at the moment.
// TODO: why not rely on the standard fabric8 yaml mapping | ||
public static final ObjectMapper YAML_MAPPER = JsonMapper.builder(new YAMLFactory() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment was lost from @metacosm about how this format seemed different. Haven't looked at it more deeply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, the format of the default mapper was different from observed CRDs in the wild so I tweaked it to make it closer. Not sure if it's a big deal anymore (or even if it ever was).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two main changes I see are the standard generator includes the explicit start ---, and it quotes string values. The ordering changes aren't really needed as they should be handled by the construction of the crd object.
I agree that we don't need explicit start, the question is does it matter if there's additional quoting? It shouldn't but we can account for one or both of these differences with an KubernetesSerialization.asYaml method that takes some style options - we are just creating the Dump / DumpSettings on every call anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it more, I don't think we should add yaml options. They really aren't needed for this case either. We could just remove this yaml mapper - the only practical issue is that string comparison of the existing crd output yaml won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can confirm that the start marker is causing issues, in particular with OLM validation, at least. The marker is what's causing: https://github.com/quarkiverse/quarkus-operator-sdk/actions/runs/8903104778/job/24450250852#step:23:10
I haven't tried applying the CRDs to a cluster, yet, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applying the CRD to the cluster seems to work OK, as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking @metacosm - the explicit start has been removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stripping the marker solved the issue as expected. Thank you!
For reference, here's the successful QOSDK build with the changes from this PR: https://github.com/quarkiverse/quarkus-operator-sdk/actions/runs/8903462629/job/24459014817
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you for testing. The only other thing that could change is supplying the ObjectMapper / KuberenetesSerialization so that we can pick up any changes the user may have made to the mapper configuration
cc @manusa
crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/CRDInfo.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it with a few internal projects and looks very good so far.
Beside of the printer columns and the ordering of the required properties list I haven't found any differences to v1.
crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/AbstractJsonSchema.java
Outdated
Show resolved
Hide resolved
crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/v1/CustomResourceHandler.java
Outdated
Show resolved
Hide resolved
f1b5490
to
1ea658d
Compare
More general feedback: x-kubernetes-embedded-resource
👍 Nice Printer Columns
Kubernetes allows for printer columns only the following types: I would suggest to silently filter printer colums on other types. At the moment it produces an invalid CRD. "Arrays" are only supported if we generate something like the following, which would be an own story:
(the target property must by one of the above types) See also upcoming "FieldSelectors" feature: Preserve Unknown FieldsI like the current behaviour of v2 regarding this topic. It behaves as I would expect it.
In my opinion using x-kubernetes-preserve-unknown everywhere could be "dangerous" because Kubernetes behaves differently. Removed fields in a CR won't get cleaned up (see control-pruning) |
I'd be more in favor of producing a hard error or emitting a warning. |
1ea658d
to
abe9a2a
Compare
crd-generator/api-v2/src/main/java/io/fabric8/crdv2/generator/CRDInfo.java
Show resolved
Hide resolved
also using string instead of object or array types
Added the warning and extracted common printer column handling. |
6c2ce80
to
8ee3f06
Compare
8ee3f06
to
7f14fbb
Compare
Signed-off-by: Chris Laprun <[email protected]>
Is this ready to be merged then? |
I think so. We can certianly refine things from here. There's quite a few follow-on tasks that have already been logged and more that are mentioned in the PR description. |
Quality Gate failedFailed conditions |
Yes, this can be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx!
Description
closes: #5948
also removes v1beta1 from the new code
This is not yet ready to merge. For the tests to pass we need to:
Recap of some other possible follow-on issues:
Approval test changes came in after the fork was created, those would need to be added again here, or in a subsequent pr.
Deprecate:
Other possible work:
I'll add a changelog entry as well once we're ready.
cc @matteriben @baloo42
Type of change
test, version modification, documentation, etc.)
Checklist