Skip to content

fix(k8s): CRD-generated classes have no metadata when the schema declares only spec #1309

Closed

Description

@lex00

Context

parseCRDSpec derives the constructor surface from the CRD's openAPIV3Schema properties, skipping apiVersion/kind/status. Whatever is left becomes the class's props.

A CRD's schema describes what its controller reads, so authors routinely declare only spec and status. The Fabric8 CRDGenerator emits exactly that, and so do most hand-written CRDs. cert-manager happens to declare metadata: { type: object }, which is why K8s::CertManager::Certificate has a metadata prop and nothing caught this.

All five KubeMicroVM CRDs added in #1306 are Fabric8-generated. The result:

export declare class MicroVM {
  constructor(props: { spec?: Record<string, unknown> });
}

No way to set a name or a namespace on a namespaced resource. Every call site needs as any:

new MicroVM({ metadata: { name: "demo", namespace: "microvm-demo" }, spec: { ... } } as any)

The serializer emits the metadata correctly — this is a typing gap only, but it defeats the point of generating classes at all, since the one field every object has is the one that needs the cast.

Fix

Emit metadata: ObjectMeta unconditionally for every CRD-generated resource, and skip any schema-declared metadata so it cannot duplicate. The API server accepts full ObjectMeta on a custom resource whatever the CRD schema says about it, so the schema is the wrong authority for this one property.

Acceptance

  • new MicroVM({ metadata: { name, namespace }, spec }) type-checks with no cast
  • A CRD whose schema does declare metadata still gets exactly one metadata prop, typed ObjectMeta rather than Record<string, unknown>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions