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

CRD validation doesn't support validating maps #26

Closed
pwittrock opened this issue Feb 16, 2018 · 2 comments
Closed

CRD validation doesn't support validating maps #26

pwittrock opened this issue Feb 16, 2018 · 2 comments
Assignees

Comments

@pwittrock
Copy link
Member

According the openapi spec maps are represented as a:

{
  "type": "object",
  "additionalProperties": {
    "type": "string"
  }
}

However when using a CRD with that validation it accepts requests that shouldn't validate:

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  version: v1
  scope: Namespaced
  names:
    kind: CronTab
  validation:
   # openAPIV3Schema is the schema for validating custom objects.
    openAPIV3Schema:
      properties:
        labels:
          type: object
          properties:
            additionalProperties: 
              type: string

Successfully created this yaml (shouldn't have)

apiVersion: stable.example.com/v1
kind: CronTab
labels:
  foo:
  - bar
metadata:
  name: name
spec:

Note: I have also gotten this error when using the go-client library to create the CRD spec:

[spec.validation.openAPIV3Schema.properties[metadata].properties[annotations].additionalProperties: Forbidden: additionalProperties cannot be set to false, spec.validation.openAPIV3Schema.properties[metadata].properties[labels].additionalProperties: Forbidden: additionalProperties cannot be set to false]

I suspect this is because when unmarshalling the json, Allows is not set to true:

https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/apis/apiextensions/v1beta1/marshal.go#L43

@pwittrock pwittrock changed the title CRD doesn't support maps CRD validation doesn't support validating maps Feb 16, 2018
@nikhita
Copy link
Member

nikhita commented Feb 16, 2018

@pwittrock This is already being tracked in kubernetes/kubernetes#59485.

@nikhita
Copy link
Member

nikhita commented Feb 20, 2018

Closing in favor of kubernetes/kubernetes#59485.

/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants