Created
May 9, 2019 16:58
-
-
Save sttts/c8fe06007b5db03c3783ff27113a79c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/BUILD b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/BUILD | |
index d92c4a9ef0c..79552370574 100644 | |
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/BUILD | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/BUILD | |
@@ -7,12 +7,14 @@ go_library( | |
"convert.go", | |
"structural.go", | |
"validation.go", | |
+ "zz_generated.deepcopy.go", | |
], | |
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/pkg/apiserver/schema", | |
importpath = "k8s.io/apiextensions-apiserver/pkg/apiserver/schema", | |
visibility = ["//visibility:public"], | |
deps = [ | |
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library", | |
+ "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", | |
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", | |
], | |
) | |
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/convert.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/convert.go | |
index b791f864c01..3e5a72c8734 100644 | |
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/convert.go | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/convert.go | |
@@ -22,7 +22,7 @@ import ( | |
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" | |
) | |
-// NewStructural converts ann OpenAPI v3 schema into a structural schema. | |
+// NewStructural converts an OpenAPI v3 schema into a structural schema. | |
func NewStructural(s *apiextensions.JSONSchemaProps) (*Structural, error) { | |
if s == nil { | |
return nil, nil | |
@@ -86,7 +86,7 @@ func newGenerics(s *apiextensions.JSONSchemaProps) (*Generic, error) { | |
Nullable: s.Nullable, | |
} | |
if s.Default != nil { | |
- g.Default = interface{}(*s.Default) | |
+ g.Default = JSON{interface{}(*s.Default)} | |
} | |
if s.AdditionalProperties != nil { | |
@@ -132,7 +132,7 @@ func newValueValidation(s *apiextensions.JSONSchemaProps) (*ValueValidation, err | |
} | |
for _, e := range s.Enum { | |
- v.Enum = append(v.Enum, e) | |
+ v.Enum = append(v.Enum, JSON{e}) | |
} | |
for _, x := range s.AllOf { | |
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/structural.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/structural.go | |
index 9964c0b2dca..0127b4258d1 100644 | |
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/structural.go | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/structural.go | |
@@ -16,6 +16,12 @@ limitations under the License. | |
package schema | |
+import ( | |
+ "k8s.io/apimachinery/pkg/runtime" | |
+) | |
+ | |
+// +k8s:deepcopy-gen=true | |
+ | |
// Structural represents a structural schema. | |
type Structural struct { | |
Items *Structural | |
@@ -27,12 +33,16 @@ type Structural struct { | |
*ValueValidation | |
} | |
+// +k8s:deepcopy-gen=true | |
+ | |
// StructuralOrBool is either a structural schema or a boolean. | |
type StructuralOrBool struct { | |
Structural *Structural | |
Bool bool | |
} | |
+// +k8s:deepcopy-gen=true | |
+ | |
// Generic contains the generic schema fields not allowed in value validation. | |
type Generic struct { | |
// type specifies the type of a value. | |
@@ -45,9 +55,11 @@ type Generic struct { | |
Description string | |
Title string | |
Nullable bool | |
- Default interface{} | |
+ Default JSON | |
} | |
+// +k8s:deepcopy-gen=true | |
+ | |
// Extensions contains the Kubernetes OpenAPI v3 vendor extensions. | |
type Extensions struct { | |
// x-kubernetes-preserve-unknown-fields stops the API server | |
@@ -81,6 +93,8 @@ type Extensions struct { | |
XIntOrString bool | |
} | |
+// +k8s:deepcopy-gen=true | |
+ | |
// ValueValidation contains all schema fields not contributing to the structure of the schema. | |
type ValueValidation struct { | |
Format string | |
@@ -95,7 +109,7 @@ type ValueValidation struct { | |
MinItems *int64 | |
UniqueItems bool | |
MultipleOf *float64 | |
- Enum []interface{} | |
+ Enum []JSON | |
MaxProperties *int64 | |
MinProperties *int64 | |
Required []string | |
@@ -105,6 +119,8 @@ type ValueValidation struct { | |
Not *NestedValueValidation | |
} | |
+// +k8s:deepcopy-gen=true | |
+ | |
// NestedValueValidation contains value validations, items and properties usable when nested | |
// under a logical junctor, and catch all structs for generic and vendor extensions schema fields. | |
type NestedValueValidation struct { | |
@@ -128,3 +144,18 @@ type NestedValueValidation struct { | |
ForbiddenGenerics Generic | |
ForbiddenExtensions Extensions | |
} | |
+ | |
+// JSON wraps an arbitrary JSON value. | |
+type JSON struct { | |
+ Object interface{} | |
+} | |
+ | |
+// DeepCopy creates a deep copy of the wrapped JSON value. | |
+func (j JSON) DeepCopy() JSON { | |
+ return JSON{runtime.DeepCopyJSONValue(j.Object)} | |
+} | |
+ | |
+// DeepCopyInto creates a deep copy of the wrapped JSON value and stores it in into. | |
+func (j JSON) DeepCopyInto(into *JSON) { | |
+ into.Object = runtime.DeepCopyJSONValue(j.Object) | |
+} | |
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/validation.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/validation.go | |
index 15154b71ff1..ba1bbb90535 100644 | |
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/validation.go | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/validation.go | |
@@ -168,7 +168,7 @@ func ValidateNestedValueValidation(v *NestedValueValidation, skipAnyOf, skipAllO | |
if v.ForbiddenGenerics.AdditionalProperties != nil { | |
allErrs = append(allErrs, field.Forbidden(fldPath.Child("additionalProperties"), "must be undefined to be structural")) | |
} | |
- if v.ForbiddenGenerics.Default != nil { | |
+ if v.ForbiddenGenerics.Default.Object != nil { | |
allErrs = append(allErrs, field.Forbidden(fldPath.Child("default"), "must be undefined to be structural")) | |
} | |
if len(v.ForbiddenGenerics.Title) > 0 { | |
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/zz_generated.deepcopy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/zz_generated.deepcopy.go | |
new file mode 100644 | |
index 00000000000..ca314b135a8 | |
--- /dev/null | |
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/zz_generated.deepcopy.go | |
@@ -0,0 +1,245 @@ | |
+// +build !ignore_autogenerated | |
+ | |
+/* | |
+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. | |
+*/ | |
+ | |
+// Code generated by deepcopy-gen. DO NOT EDIT. | |
+ | |
+package schema | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *Extensions) DeepCopyInto(out *Extensions) { | |
+ *out = *in | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Extensions. | |
+func (in *Extensions) DeepCopy() *Extensions { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(Extensions) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *Generic) DeepCopyInto(out *Generic) { | |
+ *out = *in | |
+ if in.AdditionalProperties != nil { | |
+ in, out := &in.AdditionalProperties, &out.AdditionalProperties | |
+ *out = new(StructuralOrBool) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ out.Default = in.Default.DeepCopy() | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Generic. | |
+func (in *Generic) DeepCopy() *Generic { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(Generic) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *NestedValueValidation) DeepCopyInto(out *NestedValueValidation) { | |
+ *out = *in | |
+ in.ValueValidation.DeepCopyInto(&out.ValueValidation) | |
+ if in.Items != nil { | |
+ in, out := &in.Items, &out.Items | |
+ *out = new(NestedValueValidation) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ if in.Properties != nil { | |
+ in, out := &in.Properties, &out.Properties | |
+ *out = make(map[string]NestedValueValidation, len(*in)) | |
+ for key, val := range *in { | |
+ (*out)[key] = *val.DeepCopy() | |
+ } | |
+ } | |
+ in.ForbiddenGenerics.DeepCopyInto(&out.ForbiddenGenerics) | |
+ out.ForbiddenExtensions = in.ForbiddenExtensions | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NestedValueValidation. | |
+func (in *NestedValueValidation) DeepCopy() *NestedValueValidation { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(NestedValueValidation) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *Structural) DeepCopyInto(out *Structural) { | |
+ *out = *in | |
+ if in.Items != nil { | |
+ in, out := &in.Items, &out.Items | |
+ *out = new(Structural) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ if in.Properties != nil { | |
+ in, out := &in.Properties, &out.Properties | |
+ *out = make(map[string]Structural, len(*in)) | |
+ for key, val := range *in { | |
+ (*out)[key] = *val.DeepCopy() | |
+ } | |
+ } | |
+ in.Generic.DeepCopyInto(&out.Generic) | |
+ out.Extensions = in.Extensions | |
+ if in.ValueValidation != nil { | |
+ in, out := &in.ValueValidation, &out.ValueValidation | |
+ *out = new(ValueValidation) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Structural. | |
+func (in *Structural) DeepCopy() *Structural { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(Structural) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *StructuralOrBool) DeepCopyInto(out *StructuralOrBool) { | |
+ *out = *in | |
+ if in.Structural != nil { | |
+ in, out := &in.Structural, &out.Structural | |
+ *out = new(Structural) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StructuralOrBool. | |
+func (in *StructuralOrBool) DeepCopy() *StructuralOrBool { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(StructuralOrBool) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} | |
+ | |
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | |
+func (in *ValueValidation) DeepCopyInto(out *ValueValidation) { | |
+ *out = *in | |
+ if in.Maximum != nil { | |
+ in, out := &in.Maximum, &out.Maximum | |
+ *out = new(float64) | |
+ **out = **in | |
+ } | |
+ if in.Minimum != nil { | |
+ in, out := &in.Minimum, &out.Minimum | |
+ *out = new(float64) | |
+ **out = **in | |
+ } | |
+ if in.MaxLength != nil { | |
+ in, out := &in.MaxLength, &out.MaxLength | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.MinLength != nil { | |
+ in, out := &in.MinLength, &out.MinLength | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.MaxItems != nil { | |
+ in, out := &in.MaxItems, &out.MaxItems | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.MinItems != nil { | |
+ in, out := &in.MinItems, &out.MinItems | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.MultipleOf != nil { | |
+ in, out := &in.MultipleOf, &out.MultipleOf | |
+ *out = new(float64) | |
+ **out = **in | |
+ } | |
+ if in.Enum != nil { | |
+ in, out := &in.Enum, &out.Enum | |
+ *out = make([]JSON, len(*in)) | |
+ for i := range *in { | |
+ (*in)[i].DeepCopyInto(&(*out)[i]) | |
+ } | |
+ } | |
+ if in.MaxProperties != nil { | |
+ in, out := &in.MaxProperties, &out.MaxProperties | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.MinProperties != nil { | |
+ in, out := &in.MinProperties, &out.MinProperties | |
+ *out = new(int64) | |
+ **out = **in | |
+ } | |
+ if in.Required != nil { | |
+ in, out := &in.Required, &out.Required | |
+ *out = make([]string, len(*in)) | |
+ copy(*out, *in) | |
+ } | |
+ if in.AllOf != nil { | |
+ in, out := &in.AllOf, &out.AllOf | |
+ *out = make([]NestedValueValidation, len(*in)) | |
+ for i := range *in { | |
+ (*in)[i].DeepCopyInto(&(*out)[i]) | |
+ } | |
+ } | |
+ if in.OneOf != nil { | |
+ in, out := &in.OneOf, &out.OneOf | |
+ *out = make([]NestedValueValidation, len(*in)) | |
+ for i := range *in { | |
+ (*in)[i].DeepCopyInto(&(*out)[i]) | |
+ } | |
+ } | |
+ if in.AnyOf != nil { | |
+ in, out := &in.AnyOf, &out.AnyOf | |
+ *out = make([]NestedValueValidation, len(*in)) | |
+ for i := range *in { | |
+ (*in)[i].DeepCopyInto(&(*out)[i]) | |
+ } | |
+ } | |
+ if in.Not != nil { | |
+ in, out := &in.Not, &out.Not | |
+ *out = new(NestedValueValidation) | |
+ (*in).DeepCopyInto(*out) | |
+ } | |
+ return | |
+} | |
+ | |
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValueValidation. | |
+func (in *ValueValidation) DeepCopy() *ValueValidation { | |
+ if in == nil { | |
+ return nil | |
+ } | |
+ out := new(ValueValidation) | |
+ in.DeepCopyInto(out) | |
+ return out | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment