Skip to content

Generated OpenAPI validation spec with Enum Array is invalid #316

Closed
@code0x9

Description

@code0x9

from kubebuilder 2.0, generated openapi validation spec is changed. i was able to circumvent this problem by manually patch generated CRD in crd/kustomization.yaml, but i think this one needs fix.

foo_types.go

type FooSpec struct {
  // +kubebuilder:validation:Enum=foo;bar;baz
  Foos []string `json:"foos"`
}

expected CRD

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: foo.com
spec:
  validation:
    openAPIV3Schema:
      properties:
        spec:
          properties:
            foos:
              items:
                enum:
                - foo
                - bar
                - baz
                type: string
              type: array

actual CRD

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: foo.com
spec:
  validation:
    openAPIV3Schema:
      properties:
        spec:
          properties:
            foos:
              enum:
              - foo
              - bar
              - baz
              items:
                type: string
              type: array

kustomization.yaml patch

patches:
  - patch: |-
      - op: replace
        path: /spec/validation/openAPIV3Schema/properties/spec/properties/foos
        value:
          items:
            enum:
              - foo
              - bar
              - baz
            type: string
          type: array
    target:
      kind: CustomResourceDefinition
      name: foo.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions