Open fengyinqiao opened 5 months ago
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!
Hi @fengyinqiao thanks for the interest and sorry for the delay, I missed this issue!
We are talking about two things here:
integer
default representation: AFAIK there is no defined "default" from the spec so we decided to default to the int64
representation as it's going to cause less issues with overflows and similar. You can have an integer by adding format: int32
to the property in your CRD. There are alternative workarounds, but this would be the suggested resolution.
missing fields in the generated Builder
: I encourage you to open an issue to the relevant project: sundrio
missing fields in the generated Builder: I encourage you to open an issue to the relevant project: sundrio
There's several things that don't work well here with sundrio. It doesn't understand get/set_ where the next letter is not capitalized. If you try to use get_Class / set_Class sundrio will normalize the name to Class and you end up with compilation failures because getClass conflicts with the built-in java method.
Also any simple non-alpha sufix seems to get stripped by sundrio normalization, so doing something like class_ doesn't work either.
The only thing that will work with sundrio currently is not use the root word class without additional alpha characters - stringClass or sClass will work just fine for example.
Thanks for the additional context @shawkins :+1:
In this case, I'd suggest avoiding <extraAnnotations>true</extraAnnotations>
for this CRD definition.
stringClass or sClass will work just fine for example.
@shawkins This field was named by the Strimzi-Kafka community, not by us. Changing the name of a field involves compatibility issues, because field in the production environment already has this name.
In this case, I'd suggest avoiding
<extraAnnotations>true</extraAnnotations>
for this CRD definition.
@andreaTP why ?
- The
class
field involumes
is missing in the builder and fluent classes.If you try to use get_Class / set_Class sundrio will normalize the name to Class and you end up with compilation failures because getClass conflicts with the built-in java method.
The get_Class and set_Class methods are already generated in the pojo, and theoretically should be used directly in the builder and fluent, otherwise why generate the set and get methods? @shawkins
@fengyinqiao I understand that the field name is not determined by you, my comments are more about what will currently work with sundrio. For this case to work without changes to sundrio, then changes are needed to the java generator. Alternattively opening an issue against sundrio as @andreaTP suggested may eventually address this - but it will proabably take a while before that is picked up.
@fengyinqiao I understand that the field name is not determined by you, my comments are more about what will currently work with sundrio. For this case to work without changes to sundrio, then changes are needed to the java generator. Alternattively opening an issue against sundrio as @andreaTP suggested may eventually address this - but it will proabably take a while before that is picked up.
@shawkins ok. Anyway, thanks for your reply.
Thinking about this twice, one possible viable workaround would be to make the field names configurable through configuration. The result is not going to be extremely nice to configure, but it will be effective.
fieldName
substitution herefieldName
can diverge from what is used in other places like: fields.keySet()
from the user perspective, the result should be something like this:
Maven configuration:
<fieldNameMappings>
<com.example.v1.fieldnames.Volume.class>
clazz
</com.example.v1.fieldnames.Volume.class>
</fieldNameMappings>
Java generator result Volume.java
:
@com.fasterxml.jackson.annotation.JsonProperty("class")
@com.fasterxml.jackson.annotation.JsonPropertyDescription("The storage class to use for dynamic volume allocation.")
@com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
private String clazz;
public String getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz;
}
and even sundrio
should be happy with it.
I'm completely swamped those days but would be happy to review an implementation if someone can help (maybe @matteriben is interested?).
@andreaTP nice trick from the user's perspective, hhh.
@fengyinqiao would you like to step up? :slightly_smiling_face:
@fengyinqiao would you like to step up? 🙂
I can give it a try, but I have to wait until I'm free. I'm a little busy right now, my company has a lot of things to do. Maybe two months later? @andreaTP
There is no rush at all from my point of view, disabling sundrio
should work for most of the users for the time being as a workaround.
Describe the bug
Description:
When generating Java classes from CRDs using fabric8 Kubernetes client, there are issues with incorrect field types and missing fields in the generated classes.
Issues:
Field Type Error:
Generated Java Class:
The
replicas
field should be generated as anInteger
instead ofLong
.Missing Fields:
CRD Specification:
Generated Java Class (
Volumes.java
):Generated Builder Class (
VolumesBuilder.java
):Generated Fluent Class (
VolumesFluent.java
):Dependencies:
Please investigate and provide a fix for these issues.
Thank you!
Fabric8 Kubernetes Client version
6.12.0
Steps to reproduce
java-generator-maven-plugin
to generate the Java classes.Expected behavior
replicas
field should be generated as anInteger
.volumes
field should include all properties as specified in the CRD, including theclass
field.Actual Behavior:
replicas
field is generated as aLong
.class
field involumes
is missing in the builder and fluent classes.Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.25.3@latest
Environment
macOS 13.5
Fabric8 Kubernetes Client Logs
No response
Additional context
No response