kubernetes: CRD cannot have a field named 'items'

Is this a BUG REPORT or FEATURE REQUEST?: /kind bug

What happened: I cannot have a resource which has a field named items it doesn’t pass validation. As an example I will modify sample-controller (https://github.com/kubernetes/sample-controller) and add items to artifacts/examples/example-foo.yaml:

apiVersion: samplecontroller.k8s.io/v1alpha1
kind: Foo
metadata:
  name: example-foo
spec:
  deploymentName: example-foo
  replicas: 1
  items: # <-- cannot be set
  - "foo"
  - "bar"

after executing:

kubectl create -f artifacts/examples/example-foo.yaml

I receive an error:

The Foo "example-foo" is invalid: []: Invalid value: map[string]interface {}{"apiVersion":"samplecontroller.k8s.io/v1alpha1", "kind":"Foo", "metadata":map[string]interface {}{"name":"example-foo", "namespace":"default", "generation":1, "creationTimestamp":"2018-09-10T10:31:05Z", "uid":"9f41ebca-b4e4-11e8-ab9b-525500d15501", "selfLink":"", "clusterName":""}, "spec":map[string]interface {}{"deploymentName":"example-foo", "items":[]interface {}{"foo", "bar"}, "replicas":1}}: validation failure list:
type in spec is required

Validation expects that I will set a type field as well, spec below doesn’t return the error:

apiVersion: samplecontroller.k8s.io/v1alpha1
kind: Foo
metadata:
  name: example-foo
spec:
  deploymentName: example-foo
  replicas: 1
  items:
  - "foo"
  - "bar"
  type: array  # <-- with 'type' it works

After all, in my opinion, it is a bug. I think this connected to OpenApi schema validation, that items keyword should always be in pair with type.

What you expected to happen: I would expect that I am able to use a field named items in CRD spec and it passes validation. Similar to ConfigMap, it has an items field, https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-specific-path-in-the-volume.

How to reproduce it (as minimally and precisely as possible): The easiest way is to use https://github.com/kubernetes/sample-controller, change artifacts/examples/example-foo.yaml from:

apiVersion: samplecontroller.k8s.io/v1alpha1
kind: Foo
metadata:
  name: example-foo
spec:
  deploymentName: example-foo
  replicas: 1

to:

apiVersion: samplecontroller.k8s.io/v1alpha1
kind: Foo
metadata:
  name: example-foo
spec:
  deploymentName: example-foo
  replicas: 1
  items:
  - "foo"
  - "bar"

then execute:

kubectl -f create artifacts/examples/crd-validation.yaml (it doesn’t matter if you will change something here)

kubectl -f create artifacts/examples/example-foo.yaml

After mentioned steps, you should receive the error (btw you don’t have to change the Foo structure to reproduce this)

Anything else we need to know?: No.

Environment:

  • Kubernetes version (use kubectl version): Client Version: version.Info{Major:“1”, Minor:“10”, GitVersion:“v1.10.4”, GitCommit:“5ca598b4ba5abb89bb773071ce452e33fb66339d”, GitTreeState:“clean”, BuildDate:“2018-06-06T08:13:03Z”, GoVersion:“go1.9.3”, Compiler:“gc”, Platform:“linux/amd64”} Server Version: version.Info{Major:“1”, Minor:“10”, GitVersion:“v1.10.4”, GitCommit:“5ca598b4ba5abb89bb773071ce452e33fb66339d”, GitTreeState:“clean”, BuildDate:“2018-06-06T08:00:59Z”, GoVersion:“go1.9.3”, Compiler:“gc”, Platform:“linux/amd64”} Tested as well with k8s-1.11.0, the same problem occurred.
  • OS (e.g. from /etc/os-release): Fedora27
  • Kernel (e.g. uname -a) :4.17.19-100.fc27.x86_64

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 25 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Bug in go-openapi I believe, misunderstanding of the OpenAPI spec: https://github.com/go-openapi/validate/pull/35#issuecomment-420380325

@nikhita / @sttts , is there an workaround for this issue? And am I right to assume that this will need a server side fix?

@sttts This is the PR go-openapi/validate#106, and I will submit a PR later in k8s.