Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated OpenAPI validation spec with Enum Array is invalid #316

Closed
code0x9 opened this issue Sep 10, 2019 · 3 comments
Closed

Generated OpenAPI validation spec with Enum Array is invalid #316

code0x9 opened this issue Sep 10, 2019 · 3 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@code0x9
Copy link

code0x9 commented Sep 10, 2019

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
@devholic
Copy link

devholic commented Sep 11, 2019

I think this can be resolved by using type alias, like:

// +kubebuilder:validation:Enum=foo;bar;baz
type Foo string

type FooSpec struct {
  Foos []Foo `json:"foos"`
}

@robbie-demuth
Copy link

This is similar to #342. Creating a type alias works, but has other undesirable side effects

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 12, 2020
@code0x9 code0x9 closed this as completed Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

5 participants