kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
317 stars 205 forks source link

Generating openAPIV3Schema YAML file #426

Closed aabouzaid closed 1 year ago

aabouzaid commented 1 year ago

Hi :wave:

I'm looking for a tool to generate openAPIV3Schema YAML file like in KRMFunctionDefinition or CustomResourceDefinition. I was able to generate the openapi_generated.go (GetOpenAPIDefinitions) using openapi-gen CLI tool.

However, it's not clear to me how to generate the actual KFD or CRD YAML out of that :thinking:

I want to generate something like this:

apiVersion: config.kubernetes.io/v1alpha1
kind: KRMFunctionDefinition
metadata:
  name: kubeconformvalidator
spec:
  group: validators.kustomize.aabouzaid.com
  names:
    kind: KubeconformValidator
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        properties:
          apiVersion:
            type: string
          kind:
            type: string
          metadata:
            type: object
            properties:
              name:
                type: string
                minLength: 1
            required:
            - name
          spec:
          [...]
aabouzaid commented 1 year ago

OK, I've found the answer.

What I need are KubeBuilder markers with controller-gen (from controller-tools) should be used to auto-generate the CRD YAML schema.