yannh / kubeconform

A FAST Kubernetes manifests validator, with support for Custom Resources!
Apache License 2.0
2.15k stars 121 forks source link

openapi2jsonschema.py not working with missing property field. #199

Open jmcgrath207 opened 1 year ago

jmcgrath207 commented 1 year ago

When using the openapi2jsonschema.py with Json Schema output below, I keep getting a failed check from kubeconform. I believe it might be due to the property field missing. While YAML CRD is pretty empty, It is valid and I can deploy it against our cluster.

Json Schema Output for Kubeconform.

{
  "type": "object",
  "x-kubernetes-preserve-unknown-fields": true
}

What I expect

{
  "properties": {
    "apiVersion": {
      "type": "string"
    },
    "kind": {
      "type": "string"
    },
    "metadata": {
      "type": "object"
    },
    "spec": {
...

Kubeconform Command.

kubeconform -summary -kubernetes-version "${version}" -schema-location default -schema-location "${schemas_dir}/{{.ResourceKind}}-stable-{{.ResourceAPIVersion}}.json" -exit-on-error

Example CRD

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: flyteworkflows.flyte.lyft.com
spec:
  conversion:
    strategy: None
  group: flyte.lyft.com
  names:
    kind: FlyteWorkflow
    listKind: FlyteWorkflowList
    plural: flyteworkflows
    shortNames:
    - fly
    singular: flyteworkflow
  scope: Namespaced
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        type: object
        x-kubernetes-preserve-unknown-fields: true
    served: true
    storage: true
eyarz commented 1 year ago

can you add the error that you're getting?

jmcgrath207 commented 1 year ago

Hey @eyarz sorry for the late reply, here is the error I am getting.

Kubeconform Error:
stdin - CustomResourceDefinition flyteworkflows.flyte.lyft.com failed validation: could not find schema for CustomResourceDefinition