kubernetes-client / gen

Common generator scripts for all client libraries
Apache License 2.0
148 stars 145 forks source link

Resources starting with "io.k8s" being considered builtin prevents Volume Snapshot models generation #212

Closed gregth closed 2 years ago

gregth commented 2 years ago

I tried to generate models for Volume Snapshots, as follows:

$ bash ./python-crd-cmd.sh -n io.k8s.storage.snapshot < swagger.json

This produced no models.

I inspected the code and it turns out that resources starting with "io.k8s" are considered built:

https://github.com/kubernetes-client/gen/blob/291f9a6ca5004cc91cfc4a744abf129c639d5682/openapi/preprocess_spec.py#L307-L316

This does not hold for (at least) Volume Snapshot resources which are well-known CRDs.

I tweaked a few lines of the script and here is a list of the Resources that were initially ignored, in my case:

io.k8s.storage.snapshot.v1alpha1.VolumeSnapshot
io.k8s.storage.snapshot.v1alpha1.VolumeSnapshotClass
io.k8s.storage.snapshot.v1alpha1.VolumeSnapshotClassList
io.k8s.storage.snapshot.v1alpha1.VolumeSnapshotContent
io.k8s.storage.snapshot.v1alpha1.VolumeSnapshotContentList
io.k8s.storage.snapshot.v1alpha1.VolumeSnapshotList
gregth commented 2 years ago

Let's discuss if anyone else has bumped onto this before, possible solutions, and I proceed with a PR to fix this, if you'd like to.

brendandburns commented 2 years ago

I don't think anyone else has hit this. Feel free to add a flag to optionally disable that check

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

gregth commented 2 years ago

Instead of adding an extra argument, we can fix this by modifying this if-else statement: https://github.com/kubernetes-client/gen/blob/34ea9c4d4e0c6aeb1c41858b2b230adac3bacfe3/openapi/preprocess_spec.py#L311-L320

so that it does not ignore io.k8s if the user has explicitly specified a KUBERNETES_CRD_GROUP_PREFIX that contains k8s.io:

def filter_api_group(spec):
    models = {}
    for k, v in spec['definitions'].items():
        if k.startswith(os.environ.get('KUBERNETES_CRD_GROUP_PREFIX')):
            models[k] = v
        elif k.startswith("io.k8s"):
            print("Removing builtin Kubernetes Resource %s" %k)
        else:
            print("Ignoring Custom Resource %s" %k)
    spec['definitions'] = models

@brendandburns what do you think? If we agree I can PR this and close this issue.

gregth commented 2 years ago

This issue was resolved by PR https://github.com/kubernetes-client/gen/pull/223.