mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-02-14 02:32:52 +08:00
![Kubernetes Publisher](/assets/img/avatar_default.png)
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
91 lines
3.6 KiB
Protocol Buffer
91 lines
3.6 KiB
Protocol Buffer
/*
|
|
Copyright The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
|
|
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
|
|
|
|
syntax = 'proto2';
|
|
|
|
package k8s.io.apimachinery.pkg.api.resource;
|
|
|
|
import "k8s.io/apimachinery/pkg/util/intstr/generated.proto";
|
|
|
|
// Package-wide variables from generator "generated".
|
|
option go_package = "resource";
|
|
|
|
// Quantity is a fixed-point representation of a number.
|
|
// It provides convenient marshaling/unmarshaling in JSON and YAML,
|
|
// in addition to String() and Int64() accessors.
|
|
//
|
|
// The serialization format is:
|
|
//
|
|
// <quantity> ::= <signedNumber><suffix>
|
|
// (Note that <suffix> may be empty, from the "" case in <decimalSI>.)
|
|
// <digit> ::= 0 | 1 | ... | 9
|
|
// <digits> ::= <digit> | <digit><digits>
|
|
// <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits>
|
|
// <sign> ::= "+" | "-"
|
|
// <signedNumber> ::= <number> | <sign><number>
|
|
// <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI>
|
|
// <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei
|
|
// (International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)
|
|
// <decimalSI> ::= m | "" | k | M | G | T | P | E
|
|
// (Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)
|
|
// <decimalExponent> ::= "e" <signedNumber> | "E" <signedNumber>
|
|
//
|
|
// No matter which of the three exponent forms is used, no quantity may represent
|
|
// a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal
|
|
// places. Numbers larger or more precise will be capped or rounded up.
|
|
// (E.g.: 0.1m will rounded up to 1m.)
|
|
// This may be extended in the future if we require larger or smaller quantities.
|
|
//
|
|
// When a Quantity is parsed from a string, it will remember the type of suffix
|
|
// it had, and will use the same type again when it is serialized.
|
|
//
|
|
// Before serializing, Quantity will be put in "canonical form".
|
|
// This means that Exponent/suffix will be adjusted up or down (with a
|
|
// corresponding increase or decrease in Mantissa) such that:
|
|
// a. No precision is lost
|
|
// b. No fractional digits will be emitted
|
|
// c. The exponent (or suffix) is as large as possible.
|
|
// The sign will be omitted unless the number is negative.
|
|
//
|
|
// Examples:
|
|
// 1.5 will be serialized as "1500m"
|
|
// 1.5Gi will be serialized as "1536Mi"
|
|
//
|
|
// Note that the quantity will NEVER be internally represented by a
|
|
// floating point number. That is the whole point of this exercise.
|
|
//
|
|
// Non-canonical values will still parse as long as they are well formed,
|
|
// but will be re-emitted in their canonical form. (So always use canonical
|
|
// form, or don't diff.)
|
|
//
|
|
// This format is intended to make it difficult to use these numbers without
|
|
// writing some sort of special handling code in the hopes that that will
|
|
// cause implementors to also use a fixed point implementation.
|
|
//
|
|
// +protobuf=true
|
|
// +protobuf.embed=string
|
|
// +protobuf.options.marshal=false
|
|
// +protobuf.options.(gogoproto.goproto_stringer)=false
|
|
// +k8s:deepcopy-gen=true
|
|
// +k8s:openapi-gen=true
|
|
message Quantity {
|
|
optional string string = 1;
|
|
}
|
|
|