java
java copied to clipboard
Generating manifests from argo-rollouts CRDs fails
Describe the bug Attempting to generate java crds from argo-rollouts fails to create fully valid models.
For example, instead of generating a file with import io.kubernetes.client.openapi.models.V1ObjectMeta, it instead tries to generate io.argoproj.models.IoK8sApimachineryPkgApisMetaV1ObjectMetaV2 (which doesn't exist, and fails to compile).
Additionally none of the generated models implement KubernetesObject. This is a compile-time error. A few objects correctly implement KubernetesListObject tho.
Client Version n/a
Kubernetes Version n/a
Java Version n/a this is due to the sources generated
To Reproduce Steps to reproduce the behavior (using a modified version of the example usage):
docker run \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(pwd)":"$(pwd)" \
-ti \
--network host \
ghcr.io/kubernetes-client/java/crd-model-gen:v1.0.6 \
/generate.sh \
-u https://github.com/argoproj/argo-rollouts/releases/download/v1.6.4/install.yaml \
-n io.argoproj \
-p io.argoproj \
-o "$(pwd)"
There are few logs that might be related
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
[WARNING] #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta_v2 is not defined
[WARNING] #/components/schemas/v1.ListMeta is not defined
See src.zip for a pre-generated list of the failing sources.
Expected behavior Expected valid models, usable with java client.
KubeConfig n/a
Server (please complete the following information): n/a
Additional context n/a
Ok so the first issue appears to be argo-rollouts' manifest has all of it's objects inlined. Therefore things like v1 podspec generate impossible classes. After generating a 'fixed' swagger openapi doc I ran into more issues. Argo-rollouts has CRDs that look k8s-ish, but aren't so the preprocess_spec.py trips up on them. I've opened https://github.com/kubernetes-client/gen/pull/258 to fix.
It looks like the preprocess_spec.py script is guessing what's a kubernetes object and what's not. Perhaps it should inspect the root level openapi response objects and mark those as kubernetes objects/lists instead?
There are also a few broken models, in cases where argo-rollouts references upstream kubernetes objects.
For example, instead of java.time.OffsetDateTime it generates an import to a non-existing class io.argoproj.models.IoK8sApimachineryPkgApisMetaV1Time.
Same with io.kubernetes.client.custom.IntOrString, it tries to generate io.argoproj.models.IoK8sApimachineryPkgUtilIntstrIntOrString.
Then for every instance of a 'normal' kubernetes resource, it generates for example io.argoproj.models.IoK8sApiBatchV1JobSpec instead of importing io.kubernetes.client.openapi.models.V1JobSpec.
Not sure if this is a bug in the openapi generator or something to be fixed in post-process.
The CRD workflow is definitely hacky and probably broken in places. Fixing upstream in the gen repo is the preferred solution. I'm happy to review your PRs there.
/kind bug