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

Java generator generates unusable code when default values are defined for CRD fields #4541

Closed
adriansuarez opened this issue Oct 29, 2022 · 1 comment

Comments

@adriansuarez
Copy link

adriansuarez commented Oct 29, 2022

Describe the bug

If a CustomResourceDefinition defines a default value for a field, the generated code fails to inject that value, generating a ClassCastException whenever the generated class is instantiated.

For example, if the CRD has the following snippet:

                properties:
                  caCertKey:
                    default: ca.cert
                    description: The key in the Secret that provides the Certificate Authority (CA) X509 certificate bundle.
                    type: string

then this will generate the following Java code snippet:

    /**
     * The key in the Secret that provides the Certificate Authority (CA) X509 certificate bundle.
     */
    @com.fasterxml.jackson.annotation.JsonProperty("caCertKey")
    @com.fasterxml.jackson.annotation.JsonPropertyDescription("The key in the Secret that provides the Certificate Authority (CA) X509 certificate bundle.")
    @com.fasterxml.jackson.annotation.JsonSetter(nulls = com.fasterxml.jackson.annotation.Nulls.SKIP)
    private String caCertKey = io.fabric8.kubernetes.client.utils.Serialization.unmarshal("\"ca.cert\"", String.class);

The call to Serialization.unmarshal() always generates the following stacktrace:

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:237)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:360)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:296)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:281)
	at my.organization.v1beta1.TlsConfig.<init>(TlsConfig.java:14)
	...

Fabric8 Kubernetes Client version

6.1.1

Steps to reproduce

  1. Generate Java code for a CustomResourceDefinition that defines a default value for some field.
  2. Try to instantiate the generated Java class, e.g. by simply invoking new TlsConfig() for the example above. This will fail with a ClassCastException.

Expected behavior

It should be possible to instantiate the Java class for the CustomResourceDefinition.

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

Runtime and Kubernetes API versions are not relevant. This is just a Java generator issue.

@shawkins
Copy link
Contributor

Duplicate of #4530

@shawkins shawkins marked this as a duplicate of #4530 Oct 30, 2022
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

No branches or pull requests

2 participants