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

update validation for core types #71

Merged
merged 1 commit into from
Apr 17, 2018

Conversation

Liujingfang1
Copy link
Contributor

@Liujingfang1 Liujingfang1 commented Apr 16, 2018

This is the test I did. With type defined as

type MyKindSpec struct {
    Replica int `json:"replica,omitempty"`
    Pod v1.PodTemplate `json:"pod,omitempty"`
}

// MyKindStatus defines the observed state of MyKind
type MyKindStatus struct {
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// MyKind
// +k8s:openapi-gen=true
// +resource:path=mykinds
type MyKind struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`

    Spec   MyKindSpec   `json:"spec,omitempty"`
    Status MyKindStatus `json:"status,omitempty"`
}

Then create example yaml as

apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
  name: mykind-example
spec:
  foo: bar
  replica: 2
  pod:
    name: "something"
    metadata:
      name: "something"

This object passed validation and can be created.

A different example yaml as

apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
  name: mykind-example
spec:
  foo: bar
  replica: 2
  pod: 3

failed validation and can't be created.

The MyKind "mykind-example" is invalid: []: Invalid value: map[string]interface {}{"spec":map[string]interface {}{"foo":"bar", "pod":3, "replica":2}, "apiVersion":"jingfang.example.com/v1beta1", "kind":"MyKind", "metadata":map[string]interface {}{"uid":"f9639d38-428e-11e8-bcf0-42010a800002", "selfLink":"", "clusterName":"", "name":"mykind-example", "namespace":"default", "generation":1, "creationTimestamp":"2018-04-17T22:30:47Z"}}: validation failure list:
spec.pod in body must be of type object: "integer"

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 16, 2018
@Liujingfang1 Liujingfang1 changed the title A hacky way to skip validation of core API update validation for core types Apr 17, 2018
@pwittrock pwittrock merged commit 88f0bdd into kubernetes-sigs:master Apr 17, 2018
@Liujingfang1 Liujingfang1 deleted the kube branch May 1, 2018 17:08
luffyao added a commit to luffyao/kubebuilder that referenced this pull request Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants