Skip to content

Instantly share code, notes, and snippets.

/-

Created Jul 21, 2017
Embed
What would you like to do?
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/deepcopy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/deepcopy.go
index b865f3f746..8d961ce477 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/deepcopy.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/deepcopy.go
@@ -23,17 +23,19 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
out := new(JSONSchemaProps)
- if out.Default != nil {
+ *out = *in
+
+ if in.Default != nil {
out.Default = deepCopyJSON(in.Default)
}
- if out.Type != nil {
+ if in.Type != nil {
in, out := &in.Type, &out.Type
*out = make(StringOrArray, len(*in))
copy(*out, *in)
}
- if out.Maximum != nil {
+ if in.Maximum != nil {
in, out := &in.Maximum, &out.Maximum
if *in == nil {
*out = nil
@@ -43,7 +45,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.Minimum != nil {
+ if in.Minimum != nil {
in, out := &in.Minimum, &out.Minimum
if *in == nil {
*out = nil
@@ -53,7 +55,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MaxLength != nil {
+ if in.MaxLength != nil {
in, out := &in.MaxLength, &out.MaxLength
if *in == nil {
*out = nil
@@ -63,7 +65,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MinLength != nil {
+ if in.MinLength != nil {
in, out := &in.MinLength, &out.MinLength
if *in == nil {
*out = nil
@@ -72,7 +74,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
**out = **in
}
}
- if out.MaxItems != nil {
+ if in.MaxItems != nil {
in, out := &in.MaxItems, &out.MaxItems
if *in == nil {
*out = nil
@@ -82,7 +84,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MinItems != nil {
+ if in.MinItems != nil {
in, out := &in.MinItems, &out.MinItems
if *in == nil {
*out = nil
@@ -92,7 +94,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MultipleOf != nil {
+ if in.MultipleOf != nil {
in, out := &in.MultipleOf, &out.MultipleOf
if *in == nil {
*out = nil
@@ -102,7 +104,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.Enum != nil {
+ if in.Enum != nil {
out.Enum = make([]interface{}, len(in.Enum))
for i := range in.Enum {
out.Enum[i] = deepCopyJSON(in.Enum[i])
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go
index 7ff80d6862..37b2be7771 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/fuzzer/fuzzer.go
@@ -67,7 +67,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
obj.Default = `{"some": {"json": "test"}, "string": 42}` // some valid json
}
if c.RandBool() {
- obj.Enum = []interface{}{c.Int(), c.RandString(), c.RandBool()}
+ obj.Enum = []interface{}{c.Uint64(), c.RandString(), c.RandBool()}
}
},
}
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/deepcopy.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/deepcopy.go
index 956cb91496..3b1bc5f9d3 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/deepcopy.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/deepcopy.go
@@ -23,17 +23,19 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
out := new(JSONSchemaProps)
- if out.Default != nil {
+ *out = *in
+
+ if in.Default != nil {
out.Default = deepCopyJSON(in.Default)
}
- if out.Type != nil {
+ if in.Type != nil {
in, out := &in.Type, &out.Type
*out = make(StringOrArray, len(*in))
copy(*out, *in)
}
- if out.Maximum != nil {
+ if in.Maximum != nil {
in, out := &in.Maximum, &out.Maximum
if *in == nil {
*out = nil
@@ -43,7 +45,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.Minimum != nil {
+ if in.Minimum != nil {
in, out := &in.Minimum, &out.Minimum
if *in == nil {
*out = nil
@@ -53,7 +55,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MaxLength != nil {
+ if in.MaxLength != nil {
in, out := &in.MaxLength, &out.MaxLength
if *in == nil {
*out = nil
@@ -63,7 +65,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MinLength != nil {
+ if in.MinLength != nil {
in, out := &in.MinLength, &out.MinLength
if *in == nil {
*out = nil
@@ -72,7 +74,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
**out = **in
}
}
- if out.MaxItems != nil {
+ if in.MaxItems != nil {
in, out := &in.MaxItems, &out.MaxItems
if *in == nil {
*out = nil
@@ -82,7 +84,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MinItems != nil {
+ if in.MinItems != nil {
in, out := &in.MinItems, &out.MinItems
if *in == nil {
*out = nil
@@ -92,7 +94,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.MultipleOf != nil {
+ if in.MultipleOf != nil {
in, out := &in.MultipleOf, &out.MultipleOf
if *in == nil {
*out = nil
@@ -102,7 +104,7 @@ func (in *JSONSchemaProps) DeepCopy() *JSONSchemaProps {
}
}
- if out.Enum != nil {
+ if in.Enum != nil {
out.Enum = make([]interface{}, len(in.Enum))
for i := range in.Enum {
out.Enum[i] = deepCopyJSON(in.Enum[i])
diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go
index fc57a89060..e43a10df16 100644
--- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go
+++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types.go
@@ -158,8 +158,8 @@ type CustomResourceValidation struct {
// JSONSchemaProps is a JSON-Schema following Specification Draft 4 (http://json-schema.org/).
type JSONSchemaProps struct {
ID string `json:"id,omitempty"`
- Schema JSONSchemaURL `json:"-,omitempty"`
- Ref string `json:"-,omitempty"`
+ Schema JSONSchemaURL `json:"schema,omitempty"`
+ Ref string `json:"$ref,omitempty"`
Description string `json:"description,omitempty"`
Type StringOrArray `json:"type,omitempty"`
Format string `json:"format,omitempty"`
diff --git a/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go b/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go
index 1d452aa804..2ce6b86833 100644
--- a/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go
+++ b/staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip/roundtrip.go
@@ -19,7 +19,6 @@ package roundtrip
import (
"bytes"
"encoding/hex"
- "fmt"
"math/rand"
"reflect"
"strings"
@@ -216,10 +215,12 @@ func roundTripToAllExternalVersions(t *testing.T, scheme *runtime.Scheme, codecF
}
t.Logf("\tround tripping to %v %v", externalGVK, externalGoType)
+ t.Logf("\t\tjson")
roundTrip(t, scheme, apitesting.TestCodec(codecFactory, externalGVK.GroupVersion()), object)
// TODO remove this hack after we're past the intermediate steps
if !skipProtobuf && externalGVK.Group != "kubeadm.k8s.io" {
+ t.Logf("\t\tprotobuf")
s := protobuf.NewSerializer(scheme, scheme, "application/arbitrary.content.type")
protobufCodec := codecFactory.CodecForVersions(s, s, externalGVK.GroupVersion(), nil)
roundTrip(t, scheme, protobufCodec, object)
@@ -269,13 +270,16 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object
original := object
// deep copy the original object
- copied, err := scheme.DeepCopy(object)
- if err != nil {
- panic(fmt.Sprintf("unable to copy: %v", err))
- }
- object = copied.(runtime.Object)
+ object = object.DeepCopyObject()
name := reflect.TypeOf(object).Elem().Name()
+ if !apiequality.Semantic.DeepEqual(original, object) {
+ t.Errorf("%v: DeepCopy altered the object, diff: %v", name, diff.ObjectReflectDiff(original, object))
+ t.Errorf("%s", spew.Sdump(original))
+ t.Errorf("%s", spew.Sdump(object))
+ return
+ }
+
// encode (serialize) the deep copy using the provided codec
data, err := runtime.Encode(codec, object)
if err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment