mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-02-01 01:12:52 +08:00
b31118a167
Automatic merge from submit-queue (batch tested with PRs 65256, 64236, 64919, 64879, 57932). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix CRD OpenAPI schema fixes #65243 depends on https://github.com/kubernetes/kube-openapi/pull/84 without this PR, kubectl complains about creating this CRD with a validation schema (which worked in 1.10): ```yaml apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: resources.mygroup.example.com spec: group: mygroup.example.com version: v1alpha1 scope: Namespaced names: plural: resources singular: resource kind: Kind listKind: KindList validation: openAPIV3Schema: properties: spec: type: array items: type: number ``` > error: error validating "/Users/jliggitt/projects/snippets/crd/crd.yaml": error validating data: [ValidationError(CustomResourceDefinition.spec.validation.openAPIV3Schema.properties.spec.items): unknown field "type" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaPropsOrArray, ValidationError(CustomResourceDefinition.spec.validation.openAPIV3Schema.properties.spec.items): missing required field "Schema" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaPropsOrArray, ValidationError(CustomResourceDefinition.spec.validation.openAPIV3Schema.properties.spec.items): missing required field "JSONSchemas" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaPropsOrArray]; if you choose to ignore these errors, turn validation off with --validate=false that is because the types used to serialize JSONSchema require custom marshaling/unmarshaling, and the OpenAPI generator was not informed of that, so it produced this: ```json { "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaPropsOrArray": { "description": "JSONSchemaPropsOrArray represents a value that can either be a JSONSchemaProps or an array of JSONSchemaProps. Mainly here for serialization purposes.", "required": [ "Schema", "JSONSchemas" ], "properties": { "JSONSchemas": { "type": "array", "items": { "$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" } }, "Schema": { "$ref": "#/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" } } } } ``` OpenAPI isn't able to represent oneOf/anyOf types correctly currently. Until it can, we definitely shouldn't publish a schema containing required fields which aren't even part of the JSON serialization. This PR implements custom openapi type functions, which omit the properties/required/schema attributes for four specific JSONSchema types. This allows kubectl to continue creating these objects without complaining. /sig api-machinery /assign @sttts ```release-note fixed incorrect OpenAPI schema for CustomResourceDefinition objects ``` Kubernetes-commit: ed6c8b7326bd1a1b845719f4bfb302073a18f03f |
||
---|---|---|
.. | ||
_examples | ||
cmd | ||
Godeps | ||
hack | ||
pkg/util | ||
third_party/forked/golang/reflect | ||
vendor | ||
code-of-conduct.md | ||
CONTRIBUTING.md | ||
generate-groups.sh | ||
generate-internal-groups.sh | ||
LICENSE | ||
OWNERS | ||
README.md | ||
SECURITY_CONTACTS |
code-generator
Golang code-generators used to implement Kubernetes-style API types.
Purpose
These code-generators can be used
- in the context of CustomResourceDefinition to build native, versioned clients, informers and other helpers
- in the context of User-provider API Servers to build conversions between internal and versioned types, defaulters, protobuf codecs, internal and versioned clients and informers.
Resources
- The example sample controller shows a code example of a controller that uses the clients, listers and informers generated by this library.
- The article Kubernetes Deep Dive: Code Generation for CustomResources gives a step by step instruction on how to use this library.
Compatibility
HEAD of this repo will match HEAD of k8s.io/apiserver, k8s.io/apimachinery, and k8s.io/client-go.
Where does it come from?
code-generator
is synced from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/code-generator.
Code changes are made in that location, merged into k8s.io/kubernetes
and later synced here.