Skip to content

Generating Java from CRD with empty spec or status generates inconsistent class. #7328

@qvantmiral

Description

@qvantmiral

Describe the bug

When using a CRD with an empty spec or status the resulting Java file cannot be compiled as the Spec and Status classes are not generated.

(See file in "steps to reproduce" for example)

Both spec and status are almost empty, they have only x-kubernetes-preserve-unknown-fields: true. The generator will then generate the following Java file:

package io.cattle.management.v3;

@io.fabric8.kubernetes.model.annotation.Version(value = "v3" , storage = true , served = true)
@io.fabric8.kubernetes.model.annotation.Group("management.cattle.io")
@io.fabric8.kubernetes.model.annotation.Singular("cluster")
@io.fabric8.kubernetes.model.annotation.Plural("clusters")
@javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner")
public class Cluster extends io.fabric8.kubernetes.client.CustomResource<io.cattle.management.v3.ClusterSpec, io.cattle.management.v3.ClusterStatus> {
}

Which notably references ClusterSpec and ClusterStatus. However the generator does not generate either of these files.

I believe either those must be generated, possibly empty, or the Cluster.java should be generated differently, maybe extends CustomResource<Void, Void> ?

Fabric8 Kubernetes Client version

7.3.1 and 7.4.0

Steps to reproduce

Have a CRD with an empty spec or status, for example:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    objectset.rio.cattle.io/applied: H4sIAAAAAAAA/5STXavbPAzHv8qDrt0+p0tPaAO7GBuDMRhjL70Zu1BttfXi2MaSc84o+e7DSXteBi1nl1Kkn/5/WTkCRruhxDZ4aEpA90K+hDxvVzy34f9+AQpa6w008DazhO4LcchJ0zvaWW+l9CroSNCgIDRHQO+DYPnAJQzbX6SFSebJhrlGEUeFbAsS1MXv4c5Tmu379rI09d9H683rK7quwz12BA1ol1ko8bxDj3vqyMtj6YsgHFEXEgwKdKLR/DfbEQt2ERqfnVPgcEvu6koOyAdooNb1Gm8W6+p2tUSqlje39ap+ZfRirevVYmvqqq7WtFyWaS+yMCjgSLqM3qeQIzRwwepoptSdn3zigoLockL3ZBQoYOv32WF6zJZRMRFT6um7b3248+8tOcPQ7NAxKWAdIj0j99MFMjQ/jmc/fVXw+kDdeFIhkn/z+cOm+vqQiilESmInuWd797M2byl5EuLZWcgsT0pmu5MUSZnKTgQl8z+2DQrk9+hgekUombHeTBWFGxLu6dTw89kk1JqikPn016Kfbni8ouCNPf1D0/kUKpnNw7JKdhj+BAAA//8+JR2KxAMAAA
    objectset.rio.cattle.io/id: ""
    objectset.rio.cattle.io/owner-gvk: apiextensions.k8s.io/v1, Kind=CustomResourceDefinition
    objectset.rio.cattle.io/owner-name: clusters.management.cattle.io
    objectset.rio.cattle.io/owner-namespace: ""
  creationTimestamp: "2023-09-28T07:50:02Z"
  generation: 1
  labels:
    objectset.rio.cattle.io/hash: 6c69a0193584ae34056862dc19c681bd63639e44
  name: clusters.management.cattle.io
  resourceVersion: "1572"
  uid: ad953352-a84e-4645-94bf-2b57e264f39e
spec:
  conversion:
    strategy: None
  group: management.cattle.io
  names:
    kind: Cluster
    listKind: ClusterList
    plural: clusters
    singular: cluster
  scope: Cluster
  versions:
    - name: v3
      schema:
        openAPIV3Schema:
          properties:
            spec:
              x-kubernetes-preserve-unknown-fields: true
            status:
              x-kubernetes-preserve-unknown-fields: true
          type: object
      served: true
      storage: true
status:
  acceptedNames:
    kind: Cluster
    listKind: ClusterList
    plural: clusters
    singular: cluster
  conditions:
    - lastTransitionTime: "2023-09-28T07:50:02Z"
      message: no conflicts found
      reason: NoConflicts
      status: "True"
      type: NamesAccepted
    - lastTransitionTime: "2023-09-28T07:50:02Z"
      message: the initial names have been accepted
      reason: InitialNamesAccepted
      status: "True"
      type: Established
  storedVersions:
    - v3

Run the crd2java goal in gradle or execute the cli with this input file.

Expected behavior

One to three Java files are generated, which can be compiled.

Runtime

other (please specify in additional context)

Kubernetes API Server version

1.32

Environment

other (please specify in additional context)

Fabric8 Kubernetes Client Logs

Additional context

The CRD was extracted from a Rancher cluster, but the actual execution does not require any kubernetes interaction at all.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions