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

Introduce specific annotations for the generators #4348

Merged
merged 2 commits into from Sep 5, 2022

Conversation

andreaTP
Copy link
Member

@andreaTP andreaTP commented Aug 24, 2022

Description

Fix #4224
Fix #2959
Follow up from #4298 , introducing annotations for the fields that we want to support/map.

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

Comment on lines +22 to +24
public @interface Max {
double value();
}
Copy link
Member

Choose a reason for hiding this comment

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

For the follow-ups, it might be interesting to add Javadoc to each annotation properly documenting its usage, and maybe linking the Kubernetes spec equivalent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm failing to find a good "linkable" source with the specific field description, e.g.:
https://kubernetes.io/docs/reference/kubernetes-api/extend-resources/custom-resource-definition-v1/

Do you have any idea?

Copy link
Member

Choose a reason for hiding this comment

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

No, I only found the go types sources when I was evaluating the field precision of the Max and Min configurations.

Copy link
Member Author

Choose a reason for hiding this comment

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

added a generic reference to: jsonschemaprops K8s API reference ... the best I have found in the wild ...

@@ -78,6 +79,11 @@
public static final String ANNOTATION_JSON_IGNORE = "com.fasterxml.jackson.annotation.JsonIgnore";
public static final String ANNOTATION_JSON_ANY_GETTER = "com.fasterxml.jackson.annotation.JsonAnyGetter";
public static final String ANNOTATION_JSON_ANY_SETTER = "com.fasterxml.jackson.annotation.JsonAnySetter";
public static final String ANNOTATION_MIN = "io.fabric8.generator.annotation.Min";
Copy link
Collaborator

Choose a reason for hiding this comment

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

All annotations should be put in the same package, imo.

Copy link
Member Author

@andreaTP andreaTP Aug 26, 2022

Choose a reason for hiding this comment

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

At this point we have annotations in 2 places:

  • io.fabric8.generator.annotation -> generic modifiers to represent CRD properties in Java code
  • io.fabric8.crd.generator.annotation -> specific annotations to tweak specifically the crd-generator

Do you see any other invariant @metacosm ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As soon as the annotations are used in different contexts, it would be better for users to help discoverability, in particular, for the annotations to be in the same location even though they initially were developed for different purposes… Obviously, changing annotations location at this point wouldn't be backwards compatible so maybe just a matter of documentation? It might make sense to explain why they live in different packages so that users (and future maintainers, down the line 😸) don't think it's an arbitrary decision.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a brief JavaDoc on each annotation, let me know if you want other/more changes for this 🙂

@sonarcloud
Copy link

sonarcloud bot commented Aug 26, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

87.5% 87.5% Coverage
4.4% 4.4% Duplication

@manusa manusa requested a review from metacosm August 29, 2022 07:35
@andreaTP
Copy link
Member Author

andreaTP commented Sep 1, 2022

@manusa ready to merge?

@manusa
Copy link
Member

manusa commented Sep 1, 2022

Releasing 6.1.1 ATM
Once released and checked I'll start merging the pending PRs

@manusa manusa added this to the 6.2.0 milestone Sep 1, 2022
@andreaTP
Copy link
Member Author

andreaTP commented Sep 1, 2022

Thanks for the heads up @manusa !

Copy link
Contributor

@fabiobrz fabiobrz left a comment

Choose a reason for hiding this comment

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

Hi @andreaTP (CC @manusa) - I was about to deal with #3870 by rebasing on this PR branch and implement the generation of validation annotations in the java-generator but I am thinking that it wouldn't solve the original issue, since no runtime ser/de validation would occur (see my comment to the initial PR you provided).

WDYT? Should we move on with a separate java-generator issue?

@manusa
Copy link
Member

manusa commented Sep 5, 2022

WDYT? Should we move on with a separate java-generator issue?

I'm merging this one, so please, do so.

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.

[crd-gen] Support openAPIV3Schema fields: minimum, maximum, pattern, nullable crd-generator and annotations
4 participants