diff --git a/cmd/kube-aggregator/pkg/apiserver/handler_apis_test.go b/cmd/kube-aggregator/pkg/apiserver/handler_apis_test.go index 2bf18eed602d4..00c1322cacbbb 100644 --- a/cmd/kube-aggregator/pkg/apiserver/handler_apis_test.go +++ b/cmd/kube-aggregator/pkg/apiserver/handler_apis_test.go @@ -23,6 +23,7 @@ import ( "net/http/httputil" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/diff" @@ -305,7 +306,7 @@ func TestAPIs(t *testing.T) { t.Errorf("%s: %v", tc.name, err) continue } - if !api.Semantic.DeepEqual(tc.expected, actual) { + if !apiequality.Semantic.DeepEqual(tc.expected, actual) { t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual)) continue } @@ -467,7 +468,7 @@ func TestAPIGroup(t *testing.T) { t.Errorf("%s: %v", tc.name, err) continue } - if !api.Semantic.DeepEqual(tc.expected, actual) { + if !apiequality.Semantic.DeepEqual(tc.expected, actual) { t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual)) continue } diff --git a/federation/pkg/kubefed/init/init_test.go b/federation/pkg/kubefed/init/init_test.go index d1a0f846c99a2..025b8573b3b84 100644 --- a/federation/pkg/kubefed/init/init_test.go +++ b/federation/pkg/kubefed/init/init_test.go @@ -30,6 +30,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -767,7 +768,7 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image, if err != nil { return nil, err } - if !api.Semantic.DeepEqual(got, namespace) { + if !apiequality.Semantic.DeepEqual(got, namespace) { return nil, fmt.Errorf("Unexpected namespace object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, namespace)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &namespace)}, nil @@ -781,7 +782,7 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image, if err != nil { return nil, err } - if !api.Semantic.DeepEqual(got, svc) { + if !apiequality.Semantic.DeepEqual(got, svc) { return nil, fmt.Errorf("Unexpected service object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, svc)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &svc)}, nil @@ -812,7 +813,7 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image, case cmKubeconfigSecretName: want = cmKubeconfigSecret } - if !api.Semantic.DeepEqual(got, want) { + if !apiequality.Semantic.DeepEqual(got, want) { return nil, fmt.Errorf("Unexpected secret object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, want)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &want)}, nil @@ -826,7 +827,7 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image, if err != nil { return nil, err } - if !api.Semantic.DeepEqual(got, pvc) { + if !apiequality.Semantic.DeepEqual(got, pvc) { return nil, fmt.Errorf("Unexpected PVC object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, pvc)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &pvc)}, nil @@ -846,7 +847,7 @@ func fakeInitHostFactory(federationName, namespaceName, ip, dnsZoneName, image, case cmName: want = cm } - if !api.Semantic.DeepEqual(got, want) { + if !apiequality.Semantic.DeepEqual(got, want) { return nil, fmt.Errorf("Unexpected deployment object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, want)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(extCodec, &want)}, nil diff --git a/federation/pkg/kubefed/join_test.go b/federation/pkg/kubefed/join_test.go index f9922635bce82..165eab71d472a 100644 --- a/federation/pkg/kubefed/join_test.go +++ b/federation/pkg/kubefed/join_test.go @@ -23,6 +23,7 @@ import ( "net/http" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/dynamic" @@ -189,7 +190,7 @@ func testJoinFederationFactory(clusterName, secretName, server string) cmdutil.F if err != nil { return nil, err } - if !api.Semantic.DeepEqual(got, want) { + if !apiequality.Semantic.DeepEqual(got, want) { return nil, fmt.Errorf("Unexpected cluster object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, want)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &want)}, nil @@ -265,7 +266,7 @@ func fakeJoinHostFactory(clusterName, clusterCtx, secretName, server, token stri if err != nil { return nil, err } - if !api.Semantic.DeepEqual(got, secretObject) { + if !apiequality.Semantic.DeepEqual(got, secretObject) { return nil, fmt.Errorf("Unexpected secret object\n\tDiff: %s", diff.ObjectGoPrintDiff(got, secretObject)) } return &http.Response{StatusCode: http.StatusCreated, Header: kubefedtesting.DefaultHeader(), Body: kubefedtesting.ObjBody(codec, &secretObject)}, nil diff --git a/pkg/api/conversion_test.go b/pkg/api/conversion_test.go index acf79eebbed63..6033ce096dfc1 100644 --- a/pkg/api/conversion_test.go +++ b/pkg/api/conversion_test.go @@ -21,6 +21,7 @@ import ( "math/rand" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" apitesting "k8s.io/apimachinery/pkg/api/testing" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/diff" @@ -80,7 +81,7 @@ func BenchmarkNodeConversion(b *testing.B) { result = obj.(*api.Node) } b.StopTimer() - if !api.Semantic.DeepDerivative(node, *result) { + if !apiequality.Semantic.DeepDerivative(node, *result) { b.Fatalf("Incorrect conversion: %s", diff.ObjectDiff(node, *result)) } } @@ -110,7 +111,7 @@ func BenchmarkReplicationControllerConversion(b *testing.B) { result = obj.(*api.ReplicationController) } b.StopTimer() - if !api.Semantic.DeepDerivative(replicationController, *result) { + if !apiequality.Semantic.DeepDerivative(replicationController, *result) { b.Fatalf("Incorrect conversion: expected %v, got %v", replicationController, *result) } } diff --git a/pkg/api/deep_copy_test.go b/pkg/api/deep_copy_test.go index b1a0e002dc417..1b8423b7cad0b 100644 --- a/pkg/api/deep_copy_test.go +++ b/pkg/api/deep_copy_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -140,7 +141,7 @@ func BenchmarkPodCopy(b *testing.B) { } result = obj.(*api.Pod) } - if !api.Semantic.DeepEqual(benchmarkPod, *result) { + if !apiequality.Semantic.DeepEqual(benchmarkPod, *result) { b.Fatalf("Incorrect copy: expected %v, got %v", benchmarkPod, *result) } } @@ -163,7 +164,7 @@ func BenchmarkNodeCopy(b *testing.B) { } result = obj.(*api.Node) } - if !api.Semantic.DeepEqual(node, *result) { + if !apiequality.Semantic.DeepEqual(node, *result) { b.Fatalf("Incorrect copy: expected %v, got %v", node, *result) } } @@ -186,7 +187,7 @@ func BenchmarkReplicationControllerCopy(b *testing.B) { } result = obj.(*api.ReplicationController) } - if !api.Semantic.DeepEqual(replicationController, *result) { + if !apiequality.Semantic.DeepEqual(replicationController, *result) { b.Fatalf("Incorrect copy: expected %v, got %v", replicationController, *result) } } diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index 282c08cb0f15c..283dc8062c44e 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -67,7 +67,7 @@ func NonConvertibleFields(annotations map[string]string) map[string]string { } // Semantic can do semantic deep equality checks for api objects. -// Example: api.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true +// Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true var Semantic = conversion.EqualitiesOrDie( func(a, b resource.Quantity) bool { // Ignore formatting, only care that numeric value stayed the same. diff --git a/pkg/api/serialization_proto_test.go b/pkg/api/serialization_proto_test.go index f2cd0e1ed9c2b..c4229136d508e 100644 --- a/pkg/api/serialization_proto_test.go +++ b/pkg/api/serialization_proto_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/gogo/protobuf/proto" + apiequality "k8s.io/apimachinery/pkg/api/equality" apitesting "k8s.io/apimachinery/pkg/api/testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -68,7 +69,7 @@ func TestUniversalDeserializer(t *testing.T) { if err != nil { t.Fatalf("%s: %v", mediaType, err) } - if !api.Semantic.DeepEqual(expected, obj) { + if !apiequality.Semantic.DeepEqual(expected, obj) { t.Fatalf("%s: %#v", mediaType, obj) } } @@ -88,7 +89,7 @@ func TestProtobufRoundTrip(t *testing.T) { if err := out.Unmarshal(data); err != nil { t.Fatal(err) } - if !api.Semantic.Equalities.DeepEqual(out, obj) { + if !apiequality.Semantic.Equalities.DeepEqual(out, obj) { t.Logf("marshal\n%s", hex.Dump(data)) t.Fatalf("Unmarshal is unequal\n%s", diff.ObjectGoPrintDiff(out, obj)) } diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index ac55bac72bd73..438abc5f0e542 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -32,6 +32,7 @@ import ( flag "github.com/spf13/pflag" "github.com/ugorji/go/codec" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/meta" apitesting "k8s.io/apimachinery/pkg/api/testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -321,7 +322,7 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) { // ensure that the deep copy is equal to the original; neither the deep // copy or conversion should alter the object - if !api.Semantic.DeepEqual(original, item) { + if !apiequality.Semantic.DeepEqual(original, item) { t.Errorf("0: %v: encode altered the object, diff: %v", name, diff.ObjectReflectDiff(original, item)) return } @@ -335,7 +336,7 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) { // ensure that the object produced from decoding the encoded data is equal // to the original object - if !api.Semantic.DeepEqual(original, obj2) { + if !apiequality.Semantic.DeepEqual(original, obj2) { t.Errorf("\n1: %v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, diff.ObjectReflectDiff(item, obj2), codec, printer.Sprintf("%#v", item), dataAsString(data), printer.Sprintf("%#v", obj2)) return } @@ -350,7 +351,7 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) { // ensure that the new runtime object is equal to the original after being // decoded into - if !api.Semantic.DeepEqual(item, obj3) { + if !apiequality.Semantic.DeepEqual(item, obj3) { t.Errorf("3: %v: diff: %v\nCodec: %#v", name, diff.ObjectReflectDiff(item, obj3), codec) return } @@ -383,7 +384,7 @@ func TestEncodePtr(t *testing.T) { if _, ok := obj2.(*api.Pod); !ok { t.Fatalf("Got wrong type") } - if !api.Semantic.DeepEqual(obj2, pod) { + if !apiequality.Semantic.DeepEqual(obj2, pod) { t.Errorf("\nExpected:\n\n %#v,\n\nGot:\n\n %#vDiff: %v\n\n", pod, obj2, diff.ObjectDiff(obj2, pod)) } } @@ -480,7 +481,7 @@ func TestObjectWatchFraming(t *testing.T) { } resultSecret.Kind = "Secret" resultSecret.APIVersion = "v1" - if !api.Semantic.DeepEqual(v1secret, res) { + if !apiequality.Semantic.DeepEqual(v1secret, res) { t.Fatalf("objects did not match: %s", diff.ObjectGoPrintDiff(v1secret, res)) } @@ -514,7 +515,7 @@ func TestObjectWatchFraming(t *testing.T) { } } - if !api.Semantic.DeepEqual(secret, outEvent.Object.Object) { + if !apiequality.Semantic.DeepEqual(secret, outEvent.Object.Object) { t.Fatalf("%s: did not match after frame decoding: %s", info.MediaType, diff.ObjectGoPrintDiff(secret, outEvent.Object.Object)) } } diff --git a/pkg/api/testing/pod_specs.go b/pkg/api/testing/pod_specs.go index eb7c4e06b7378..1cfd0c5e0eee6 100644 --- a/pkg/api/testing/pod_specs.go +++ b/pkg/api/testing/pod_specs.go @@ -21,7 +21,7 @@ import ( "k8s.io/kubernetes/pkg/api/v1" ) -// DeepEqualSafePodSpec returns a PodSpec which is ready to be used with api.Semantic.DeepEqual +// DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual func DeepEqualSafePodSpec() api.PodSpec { grace := int64(30) return api.PodSpec{ @@ -33,7 +33,7 @@ func DeepEqualSafePodSpec() api.PodSpec { } } -// V1DeepEqualSafePodSpec returns a PodSpec which is ready to be used with api.Semantic.DeepEqual +// V1DeepEqualSafePodSpec returns a PodSpec which is ready to be used with apiequality.Semantic.DeepEqual func V1DeepEqualSafePodSpec() v1.PodSpec { grace := int64(30) return v1.PodSpec{ diff --git a/pkg/api/unstructured_test.go b/pkg/api/unstructured_test.go index 3d2e37fa466ed..189ce64c0e5a8 100644 --- a/pkg/api/unstructured_test.go +++ b/pkg/api/unstructured_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" apitesting "k8s.io/apimachinery/pkg/api/testing" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" @@ -89,7 +90,7 @@ func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { t.Errorf("Error when unmarshaling to object: %v", err) return } - if !api.Semantic.DeepEqual(item, unmarshalledObj) { + if !apiequality.Semantic.DeepEqual(item, unmarshalledObj) { t.Errorf("Object changed during JSON operations, diff: %v", diff.ObjectReflectDiff(item, unmarshalledObj)) return } @@ -111,7 +112,7 @@ func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { return } - if !api.Semantic.DeepEqual(item, newObj) { + if !apiequality.Semantic.DeepEqual(item, newObj) { t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj)) } */ diff --git a/pkg/api/v1/conversion_test.go b/pkg/api/v1/conversion_test.go index 95802f183fb7f..ca4e5bb0650e5 100644 --- a/pkg/api/v1/conversion_test.go +++ b/pkg/api/v1/conversion_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -210,7 +211,7 @@ func TestResourceListConversion(t *testing.T) { if err != nil { t.Fatalf("unexpected error for case %d: %v", i, err) } - if !api.Semantic.DeepEqual(test.expected, output) { + if !apiequality.Semantic.DeepEqual(test.expected, output) { t.Errorf("unexpected conversion for case %d: Expected %+v; Got %+v", i, test.expected, output) } } diff --git a/pkg/api/v1/helpers_test.go b/pkg/api/v1/helpers_test.go index c4716de38e06c..37da086d94a99 100644 --- a/pkg/api/v1/helpers_test.go +++ b/pkg/api/v1/helpers_test.go @@ -20,9 +20,9 @@ import ( "reflect" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/kubernetes/pkg/api" ) func TestAddToNodeAddresses(t *testing.T) { @@ -76,7 +76,7 @@ func TestAddToNodeAddresses(t *testing.T) { for i, tc := range testCases { AddToNodeAddresses(&tc.existing, tc.toAdd...) - if !api.Semantic.DeepEqual(tc.expected, tc.existing) { + if !apiequality.Semantic.DeepEqual(tc.expected, tc.existing) { t.Errorf("case[%d], expected: %v, got: %v", i, tc.expected, tc.existing) } } diff --git a/pkg/api/validation/genericvalidation/objectmeta.go b/pkg/api/validation/genericvalidation/objectmeta.go index 43f1a61be5d58..48cb0c90c8003 100644 --- a/pkg/api/validation/genericvalidation/objectmeta.go +++ b/pkg/api/validation/genericvalidation/objectmeta.go @@ -20,6 +20,7 @@ import ( "fmt" "strings" + apiequality "k8s.io/apimachinery/pkg/api/equality" apimachineyvalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" @@ -133,7 +134,7 @@ func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fld func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} - if !api.Semantic.DeepEqual(oldVal, newVal) { + if !apiequality.Semantic.DeepEqual(oldVal, newVal) { allErrs = append(allErrs, field.Invalid(fldPath, newVal, FieldImmutableErrorMsg)) } return allErrs diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 23dbcf6a7c850..0316f7e6e5a55 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -28,6 +28,7 @@ import ( "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -1092,7 +1093,7 @@ func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeCla } // changes to Spec are not allowed, but updates to label/and some annotations are OK. // no-op updates pass validation. - if !api.Semantic.DeepEqual(newPvc.Spec, oldPvc.Spec) { + if !apiequality.Semantic.DeepEqual(newPvc.Spec, oldPvc.Spec) { allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "field is immutable after creation")) } @@ -2253,7 +2254,7 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) field.ErrorList { activeDeadlineSeconds := *oldPod.Spec.ActiveDeadlineSeconds mungedPod.Spec.ActiveDeadlineSeconds = &activeDeadlineSeconds } - if !api.Semantic.DeepEqual(mungedPod.Spec, oldPod.Spec) { + if !apiequality.Semantic.DeepEqual(mungedPod.Spec, oldPod.Spec) { //TODO: Pinpoint the specific field that causes the invalid error after we have strategic merge diff allErrs = append(allErrs, field.Forbidden(specPath, "pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`")) } @@ -2789,7 +2790,7 @@ func ValidateNodeUpdate(node, oldNode *api.Node) field.ErrorList { // TODO: Enable the code once we have better api object.status update model. Currently, // anyone can update node status. - // if !api.Semantic.DeepEqual(node.Status, api.NodeStatus{}) { + // if !apiequality.Semantic.DeepEqual(node.Status, api.NodeStatus{}) { // allErrs = append(allErrs, field.Invalid("status", node.Status, "must be empty")) // } @@ -2832,7 +2833,7 @@ func ValidateNodeUpdate(node, oldNode *api.Node) field.ErrorList { oldNode.Status = node.Status // TODO: Add a 'real' error type for this error and provide print actual diffs. - if !api.Semantic.DeepEqual(oldNode, node) { + if !apiequality.Semantic.DeepEqual(oldNode, node) { glog.V(4).Infof("Update failed validation %#v vs %#v", oldNode, node) allErrs = append(allErrs, field.Forbidden(field.NewPath(""), "node updates may only change labels or capacity")) } diff --git a/pkg/apimachinery/tests/runtime_serializer_protobuf_protobuf_test.go b/pkg/apimachinery/tests/runtime_serializer_protobuf_protobuf_test.go index 87ff680264c8e..325636ebee6a4 100644 --- a/pkg/apimachinery/tests/runtime_serializer_protobuf_protobuf_test.go +++ b/pkg/apimachinery/tests/runtime_serializer_protobuf_protobuf_test.go @@ -24,6 +24,7 @@ import ( "strings" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -344,7 +345,7 @@ func TestDecodeObjects(t *testing.T) { continue } - if !api.Semantic.DeepEqual(obj, test.obj) { + if !apiequality.Semantic.DeepEqual(obj, test.obj) { t.Errorf("%d: unexpected object:\n%s", i, diff.ObjectGoPrintDiff(test.obj, obj)) continue } diff --git a/pkg/apis/authorization/validation/validation.go b/pkg/apis/authorization/validation/validation.go index 77757e546e4ae..725e6f0b2f082 100644 --- a/pkg/apis/authorization/validation/validation.go +++ b/pkg/apis/authorization/validation/validation.go @@ -17,9 +17,9 @@ limitations under the License. package validation import ( + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/kubernetes/pkg/api" authorizationapi "k8s.io/kubernetes/pkg/apis/authorization" ) @@ -52,7 +52,7 @@ func ValidateSelfSubjectAccessReviewSpec(spec authorizationapi.SelfSubjectAccess func ValidateSubjectAccessReview(sar *authorizationapi.SubjectAccessReview) field.ErrorList { allErrs := ValidateSubjectAccessReviewSpec(sar.Spec, field.NewPath("spec")) - if !api.Semantic.DeepEqual(metav1.ObjectMeta{}, sar.ObjectMeta) { + if !apiequality.Semantic.DeepEqual(metav1.ObjectMeta{}, sar.ObjectMeta) { allErrs = append(allErrs, field.Invalid(field.NewPath("metadata"), sar.ObjectMeta, `must be empty`)) } return allErrs @@ -60,7 +60,7 @@ func ValidateSubjectAccessReview(sar *authorizationapi.SubjectAccessReview) fiel func ValidateSelfSubjectAccessReview(sar *authorizationapi.SelfSubjectAccessReview) field.ErrorList { allErrs := ValidateSelfSubjectAccessReviewSpec(sar.Spec, field.NewPath("spec")) - if !api.Semantic.DeepEqual(metav1.ObjectMeta{}, sar.ObjectMeta) { + if !apiequality.Semantic.DeepEqual(metav1.ObjectMeta{}, sar.ObjectMeta) { allErrs = append(allErrs, field.Invalid(field.NewPath("metadata"), sar.ObjectMeta, `must be empty`)) } return allErrs @@ -71,7 +71,7 @@ func ValidateLocalSubjectAccessReview(sar *authorizationapi.LocalSubjectAccessRe objectMetaShallowCopy := sar.ObjectMeta objectMetaShallowCopy.Namespace = "" - if !api.Semantic.DeepEqual(metav1.ObjectMeta{}, objectMetaShallowCopy) { + if !apiequality.Semantic.DeepEqual(metav1.ObjectMeta{}, objectMetaShallowCopy) { allErrs = append(allErrs, field.Invalid(field.NewPath("metadata"), sar.ObjectMeta, `must be empty except for namespace`)) } diff --git a/pkg/client/unversioned/testclient/simple/simple_testclient.go b/pkg/client/unversioned/testclient/simple/simple_testclient.go index a9f948dd920c3..34649d0f0de5f 100644 --- a/pkg/client/unversioned/testclient/simple/simple_testclient.go +++ b/pkg/client/unversioned/testclient/simple/simple_testclient.go @@ -24,6 +24,7 @@ import ( "strings" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" @@ -99,7 +100,7 @@ func (c *Client) ServerURL() string { func (c *Client) Validate(t *testing.T, received runtime.Object, err error) { c.ValidateCommon(t, err) - if c.Response.Body != nil && !api.Semantic.DeepDerivative(c.Response.Body, received) { + if c.Response.Body != nil && !apiequality.Semantic.DeepDerivative(c.Response.Body, received) { t.Errorf("bad response for request %#v: \nexpected %#v\ngot %#v\n", c.Request, c.Response.Body, received) } } diff --git a/pkg/controller/controller_utils_test.go b/pkg/controller/controller_utils_test.go index 5c4df7244302a..a3d6df03d5a8f 100644 --- a/pkg/controller/controller_utils_test.go +++ b/pkg/controller/controller_utils_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -273,7 +274,7 @@ func TestCreatePods(t *testing.T) { if err != nil { t.Fatalf("Unexpected error: %v", err) } - if !api.Semantic.DeepDerivative(&expectedPod, actualPod) { + if !apiequality.Semantic.DeepDerivative(&expectedPod, actualPod) { t.Logf("Body: %s", fakeHandler.RequestBody) t.Errorf("Unexpected mismatch. Expected\n %#v,\n Got:\n %#v", &expectedPod, actualPod) } diff --git a/pkg/controller/deployment/deployment_controller.go b/pkg/controller/deployment/deployment_controller.go index aadc8f0052e7a..f3e3102be783c 100644 --- a/pkg/controller/deployment/deployment_controller.go +++ b/pkg/controller/deployment/deployment_controller.go @@ -27,6 +27,7 @@ import ( "time" "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -35,7 +36,6 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/cache" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" @@ -285,7 +285,7 @@ func (dc *DeploymentController) updateReplicaSet(old, cur interface{}) { } // A number of things could affect the old deployment: labels changing, // pod template changing, etc. - if !api.Semantic.DeepEqual(oldRS, curRS) { + if !apiequality.Semantic.DeepEqual(oldRS, curRS) { if oldD := dc.getDeploymentForReplicaSet(oldRS); oldD != nil { dc.enqueueDeployment(oldD) } diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index 977dfc470c157..7ad13c5edc0a7 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -25,6 +25,7 @@ import ( "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -605,7 +606,7 @@ func EqualIgnoreHash(template1, template2 v1.PodTemplateSpec) bool { } // Then, compare the templates without comparing their labels template1.Labels, template2.Labels = nil, nil - return api.Semantic.DeepEqual(template1, template2) + return apiequality.Semantic.DeepEqual(template1, template2) } // FindNewReplicaSet returns the new RS this given deployment targets (the one with the same pod template). diff --git a/pkg/controller/deployment/util/deployment_util_test.go b/pkg/controller/deployment/util/deployment_util_test.go index 267ecaeab83d8..e8edfde391a09 100644 --- a/pkg/controller/deployment/util/deployment_util_test.go +++ b/pkg/controller/deployment/util/deployment_util_test.go @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" core "k8s.io/client-go/testing" @@ -256,7 +257,7 @@ func TestGetNewRC(t *testing.T) { if err != nil { t.Errorf("In test case %s, got unexpected error %v", test.test, err) } - if !api.Semantic.DeepEqual(rs, test.expected) { + if !apiequality.Semantic.DeepEqual(rs, test.expected) { t.Errorf("In test case %s, expected %#v, got %#v", test.test, test.expected, rs) } } diff --git a/pkg/controller/job/jobcontroller_test.go b/pkg/controller/job/jobcontroller_test.go index 42415704bb5f2..f1f2c73f5b20e 100644 --- a/pkg/controller/job/jobcontroller_test.go +++ b/pkg/controller/job/jobcontroller_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/wait" @@ -656,7 +657,7 @@ func TestWatchJobs(t *testing.T) { t.Errorf("Expected to find job under key %v: %v", key, err) return nil } - if !api.Semantic.DeepDerivative(*job, testJob) { + if !apiequality.Semantic.DeepDerivative(*job, testJob) { t.Errorf("Expected %#v, but got %#v", testJob, *job) } return nil @@ -699,7 +700,7 @@ func TestWatchPods(t *testing.T) { if err != nil { t.Errorf("Expected to find job under key %v: %v", key, err) } - if !api.Semantic.DeepDerivative(job, testJob) { + if !apiequality.Semantic.DeepDerivative(job, testJob) { t.Errorf("\nExpected %#v,\nbut got %#v", testJob, job) close(received) return nil diff --git a/pkg/controller/node/nodecontroller.go b/pkg/controller/node/nodecontroller.go index 06567819dce80..49be5766e504b 100644 --- a/pkg/controller/node/nodecontroller.go +++ b/pkg/controller/node/nodecontroller.go @@ -24,6 +24,7 @@ import ( "time" "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" @@ -777,7 +778,7 @@ func (nc *NodeController) tryUpdateNodeStatus(node *v1.Node) (time.Duration, v1. } _, currentCondition := v1.GetNodeCondition(&node.Status, v1.NodeReady) - if !api.Semantic.DeepEqual(currentCondition, &observedReadyCondition) { + if !apiequality.Semantic.DeepEqual(currentCondition, &observedReadyCondition) { if _, err = nc.kubeClient.Core().Nodes().UpdateStatus(node); err != nil { glog.Errorf("Error updating node %s: %v", node.Name, err) return gracePeriod, observedReadyCondition, currentReadyCondition, err diff --git a/pkg/controller/node/nodecontroller_test.go b/pkg/controller/node/nodecontroller_test.go index 102c99c37def1..4415a5b0d11a8 100644 --- a/pkg/controller/node/nodecontroller_test.go +++ b/pkg/controller/node/nodecontroller_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -29,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" testcore "k8s.io/client-go/testing" "k8s.io/client-go/tools/cache" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" @@ -1524,10 +1524,10 @@ func TestMonitorNodeStatusUpdateStatus(t *testing.T) { if item.expectedRequestCount != item.fakeNodeHandler.RequestCount { t.Errorf("expected %v call, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount) } - if len(item.fakeNodeHandler.UpdatedNodes) > 0 && !api.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodes) { + if len(item.fakeNodeHandler.UpdatedNodes) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodes) { t.Errorf("Case[%d] unexpected nodes: %s", i, diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodes[0])) } - if len(item.fakeNodeHandler.UpdatedNodeStatuses) > 0 && !api.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodeStatuses) { + if len(item.fakeNodeHandler.UpdatedNodeStatuses) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodeStatuses) { t.Errorf("Case[%d] unexpected nodes: %s", i, diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodeStatuses[0])) } } diff --git a/pkg/controller/replicaset/replica_set_test.go b/pkg/controller/replicaset/replica_set_test.go index 739bed38b16fb..c830afa73a66c 100644 --- a/pkg/controller/replicaset/replica_set_test.go +++ b/pkg/controller/replicaset/replica_set_test.go @@ -28,6 +28,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -541,7 +542,7 @@ func TestWatchControllers(t *testing.T) { t.Errorf("Expected to find replica set under key %v", key) } rsSpec := *obj.(*extensions.ReplicaSet) - if !api.Semantic.DeepDerivative(rsSpec, testRSSpec) { + if !apiequality.Semantic.DeepDerivative(rsSpec, testRSSpec) { t.Errorf("Expected %#v, but got %#v", testRSSpec, rsSpec) } close(received) @@ -583,7 +584,7 @@ func TestWatchPods(t *testing.T) { t.Errorf("Expected to find replica set under key %v", key) } rsSpec := obj.(*extensions.ReplicaSet) - if !api.Semantic.DeepDerivative(rsSpec, testRSSpec) { + if !apiequality.Semantic.DeepDerivative(rsSpec, testRSSpec) { t.Errorf("\nExpected %#v,\nbut got %#v", testRSSpec, rsSpec) } close(received) diff --git a/pkg/controller/replication/replication_controller_test.go b/pkg/controller/replication/replication_controller_test.go index e23bdbe9f0fb5..b8b43558abbed 100644 --- a/pkg/controller/replication/replication_controller_test.go +++ b/pkg/controller/replication/replication_controller_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -471,7 +472,7 @@ func TestWatchControllers(t *testing.T) { t.Errorf("Expected to find controller under key %v", key) } controllerSpec := *obj.(*v1.ReplicationController) - if !api.Semantic.DeepDerivative(controllerSpec, testControllerSpec) { + if !apiequality.Semantic.DeepDerivative(controllerSpec, testControllerSpec) { t.Errorf("Expected %#v, but got %#v", testControllerSpec, controllerSpec) } close(received) @@ -512,7 +513,7 @@ func TestWatchPods(t *testing.T) { t.Errorf("Expected to find controller under key %v", key) } controllerSpec := obj.(*v1.ReplicationController) - if !api.Semantic.DeepDerivative(controllerSpec, testControllerSpec) { + if !apiequality.Semantic.DeepDerivative(controllerSpec, testControllerSpec) { t.Errorf("\nExpected %#v,\nbut got %#v", testControllerSpec, controllerSpec) } close(received) diff --git a/pkg/controller/resourcequota/resource_quota_controller.go b/pkg/controller/resourcequota/resource_quota_controller.go index 68c2f174d6849..55405d07f20aa 100644 --- a/pkg/controller/resourcequota/resource_quota_controller.go +++ b/pkg/controller/resourcequota/resource_quota_controller.go @@ -21,6 +21,7 @@ import ( "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -174,7 +175,7 @@ func (rq *ResourceQuotaController) addQuota(obj interface{}) { resourceQuota := obj.(*v1.ResourceQuota) // if we declared an intent that is not yet captured in status (prioritize it) - if !api.Semantic.DeepEqual(resourceQuota.Spec.Hard, resourceQuota.Status.Hard) { + if !apiequality.Semantic.DeepEqual(resourceQuota.Spec.Hard, resourceQuota.Status.Hard) { rq.missingUsageQueue.Add(key) return } @@ -268,7 +269,7 @@ func (rq *ResourceQuotaController) syncResourceQuotaFromKey(key string) (err err // syncResourceQuota runs a complete sync of resource quota status across all known kinds func (rq *ResourceQuotaController) syncResourceQuota(v1ResourceQuota v1.ResourceQuota) (err error) { // quota is dirty if any part of spec hard limits differs from the status hard limits - dirty := !api.Semantic.DeepEqual(v1ResourceQuota.Spec.Hard, v1ResourceQuota.Status.Hard) + dirty := !apiequality.Semantic.DeepEqual(v1ResourceQuota.Spec.Hard, v1ResourceQuota.Status.Hard) resourceQuota := api.ResourceQuota{} if err := v1.Convert_v1_ResourceQuota_To_api_ResourceQuota(&v1ResourceQuota, &resourceQuota, nil); err != nil { diff --git a/pkg/genericapiserver/endpoints/apiserver_test.go b/pkg/genericapiserver/endpoints/apiserver_test.go index 650ca3085ce04..165791f5eab9b 100644 --- a/pkg/genericapiserver/endpoints/apiserver_test.go +++ b/pkg/genericapiserver/endpoints/apiserver_test.go @@ -34,6 +34,9 @@ import ( "testing" "time" + "github.com/emicklei/go-restful" + + apiequality "k8s.io/apimachinery/pkg/api/equality" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" apitesting "k8s.io/apimachinery/pkg/api/testing" @@ -57,8 +60,6 @@ import ( "k8s.io/kubernetes/pkg/genericapiserver/registry/rest" "k8s.io/kubernetes/plugin/pkg/admission/admit" "k8s.io/kubernetes/plugin/pkg/admission/deny" - - "github.com/emicklei/go-restful" ) // This creates fake API versions, similar to api/latest.go. @@ -1739,7 +1740,7 @@ func TestConnectResponderObject(t *testing.T) { if err != nil { t.Fatal(err) } - if !api.Semantic.DeepEqual(obj, simple) { + if !apiequality.Semantic.DeepEqual(obj, simple) { t.Errorf("Unexpected response: %#v", obj) } } @@ -1969,7 +1970,7 @@ func TestDeleteWithOptions(t *testing.T) { t.Errorf("Unexpected delete: %s, expected %s", simpleStorage.deleted, ID) } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) - if !api.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { + if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) } } @@ -2006,7 +2007,7 @@ func TestDeleteWithOptionsQuery(t *testing.T) { t.Fatalf("Unexpected delete: %s, expected %s", simpleStorage.deleted, ID) } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) - if !api.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { + if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) } } @@ -2046,7 +2047,7 @@ func TestDeleteWithOptionsQueryAndBody(t *testing.T) { t.Errorf("Unexpected delete: %s, expected %s", simpleStorage.deleted, ID) } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) - if !api.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { + if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) } } diff --git a/pkg/genericapiserver/endpoints/handlers/rest_test.go b/pkg/genericapiserver/endpoints/handlers/rest_test.go index 435276f841454..7d6c7f91bdc8f 100644 --- a/pkg/genericapiserver/endpoints/handlers/rest_test.go +++ b/pkg/genericapiserver/endpoints/handlers/rest_test.go @@ -26,6 +26,7 @@ import ( "github.com/emicklei/go-restful" "github.com/evanphx/json-patch" + apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -74,7 +75,7 @@ func TestPatchAnonymousField(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - if !api.Semantic.DeepEqual(actual, expected) { + if !apiequality.Semantic.DeepEqual(actual, expected) { t.Errorf("expected %#v, got %#v", expected, actual) } } diff --git a/pkg/genericapiserver/registry/generic/registry/store_test.go b/pkg/genericapiserver/registry/generic/registry/store_test.go index d9bfae794e741..5df6ef51d1d27 100644 --- a/pkg/genericapiserver/registry/generic/registry/store_test.go +++ b/pkg/genericapiserver/registry/generic/registry/store_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" @@ -204,7 +205,7 @@ func TestStoreList(t *testing.T) { } // DeepDerivative e,a is needed here b/c the storage layer sets ResourceVersion - if e, a := item.out, list; !api.Semantic.DeepDerivative(e, a) { + if e, a := item.out, list; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("%v: Expected %#v, got %#v", name, e, a) } destroyFunc() diff --git a/pkg/genericapiserver/registry/rest/resttest/resttest.go b/pkg/genericapiserver/registry/rest/resttest/resttest.go index 86cfd0d4eeea0..23befacfb731b 100644 --- a/pkg/genericapiserver/registry/rest/resttest/resttest.go +++ b/pkg/genericapiserver/registry/rest/resttest/resttest.go @@ -23,6 +23,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/validation/path" metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" @@ -276,7 +277,7 @@ func (t *Tester) testCreateEquals(obj runtime.Object, getFn GetFunc) { gotMeta := t.getObjectMetaOrFail(got) createdMeta.ResourceVersion = gotMeta.ResourceVersion - if e, a := created, got; !api.Semantic.DeepEqual(e, a) { + if e, a := created, got; !apiequality.Semantic.DeepEqual(e, a) { t.Errorf("unexpected obj: %#v, expected %#v", e, a) } } @@ -484,7 +485,7 @@ func (t *Tester) testUpdateEquals(obj runtime.Object, createFn CreateFunc, getFn gotMeta := t.getObjectMetaOrFail(got) updatedMeta.ResourceVersion = gotMeta.ResourceVersion - if e, a := updated, got; !api.Semantic.DeepEqual(e, a) { + if e, a := updated, got; !apiequality.Semantic.DeepEqual(e, a) { t.Errorf("unexpected obj: %#v, expected %#v", e, a) } } @@ -1091,7 +1092,7 @@ func (t *Tester) testGetFound(obj runtime.Object) { } gotMeta := t.getObjectMetaOrFail(got) gotMeta.ResourceVersion = existingMeta.ResourceVersion - if e, a := existing, got; !api.Semantic.DeepEqual(e, a) { + if e, a := existing, got; !apiequality.Semantic.DeepEqual(e, a) { t.Errorf("unexpected obj: %#v, expected %#v", e, a) } } @@ -1174,7 +1175,7 @@ func (t *Tester) testListFound(obj runtime.Object, assignFn AssignFunc) { if len(items) != len(existing) { t.Errorf("unexpected number of items: %v", len(items)) } - if !api.Semantic.DeepEqual(existing, items) { + if !apiequality.Semantic.DeepEqual(existing, items) { t.Errorf("expected: %#v, got: %#v", existing, items) } } @@ -1209,7 +1210,7 @@ func (t *Tester) testListMatchLabels(obj runtime.Object, assignFn AssignFunc) { if len(items) != len(filtered) { t.Errorf("unexpected number of items: %v", len(items)) } - if !api.Semantic.DeepEqual(filtered, items) { + if !apiequality.Semantic.DeepEqual(filtered, items) { t.Errorf("expected: %#v, got: %#v", filtered, items) } } diff --git a/pkg/kubectl/cmd/config/config_test.go b/pkg/kubectl/cmd/config/config_test.go index 0bd896da66073..e331aaed0861b 100644 --- a/pkg/kubectl/cmd/config/config_test.go +++ b/pkg/kubectl/cmd/config/config_test.go @@ -26,10 +26,10 @@ import ( "strings" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - "k8s.io/kubernetes/pkg/api" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" ) @@ -897,7 +897,7 @@ func (test configCommandTest) run(t *testing.T) string { testSetNilMapsToEmpties(reflect.ValueOf(&actualConfig)) testClearLocationOfOrigin(&actualConfig) - if !api.Semantic.DeepEqual(test.expectedConfig, actualConfig) { + if !apiequality.Semantic.DeepEqual(test.expectedConfig, actualConfig) { t.Errorf("diff: %v", diff.ObjectDiff(test.expectedConfig, actualConfig)) t.Errorf("expected: %#v\n actual: %#v", test.expectedConfig, actualConfig) } diff --git a/pkg/kubectl/cmd/get_test.go b/pkg/kubectl/cmd/get_test.go index b917f27165726..39200512d1f66 100644 --- a/pkg/kubectl/cmd/get_test.go +++ b/pkg/kubectl/cmd/get_test.go @@ -26,6 +26,7 @@ import ( "strings" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -280,7 +281,7 @@ func verifyObjects(t *testing.T, expected, actual []runtime.Object) { if err != nil { t.Fatal(err) } - if !api.Semantic.DeepEqual(expected[i], actualObj) { + if !apiequality.Semantic.DeepEqual(expected[i], actualObj) { t.Errorf("unexpected object: \n%#v\n%#v", expected[i], actualObj) } } diff --git a/pkg/kubectl/describe_test.go b/pkg/kubectl/describe_test.go index b7d0366e1b2d4..bbb10b98f4352 100644 --- a/pkg/kubectl/describe_test.go +++ b/pkg/kubectl/describe_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/federation/apis/federation" @@ -563,7 +564,7 @@ func TestGetPodsTotalRequests(t *testing.T) { if err != nil { t.Errorf("Unexpected error %v", err) } - if !api.Semantic.DeepEqual(reqs, testCase.expectedReqs) { + if !apiequality.Semantic.DeepEqual(reqs, testCase.expectedReqs) { t.Errorf("Expected %v, got %v", testCase.expectedReqs, reqs) } } diff --git a/pkg/kubectl/resource/builder_test.go b/pkg/kubectl/resource/builder_test.go index f7152563c801d..33cfb68c221c7 100644 --- a/pkg/kubectl/resource/builder_test.go +++ b/pkg/kubectl/resource/builder_test.go @@ -31,6 +31,7 @@ import ( "github.com/ghodss/yaml" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -591,7 +592,7 @@ func TestMultipleResourceByTheSameName(t *testing.T) { if err != nil || singleItemImplied || len(test.Infos) != 4 { t.Fatalf("unexpected response: %v %t %#v", err, singleItemImplied, test.Infos) } - if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svcs.Items[0], &svcs.Items[0]}, test.Objects()) { + if !apiequality.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svcs.Items[0], &svcs.Items[0]}, test.Objects()) { t.Errorf("unexpected visited objects: %#v", test.Objects()) } @@ -734,7 +735,7 @@ func TestSelector(t *testing.T) { if err != nil || singleItemImplied || len(test.Infos) != 3 { t.Fatalf("unexpected response: %v %t %#v", err, singleItemImplied, test.Infos) } - if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svc.Items[0]}, test.Objects()) { + if !apiequality.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &svc.Items[0]}, test.Objects()) { t.Errorf("unexpected visited objects: %#v", test.Objects()) } @@ -866,7 +867,7 @@ func TestStream(t *testing.T) { if err != nil || singleItemImplied || len(test.Infos) != 3 { t.Fatalf("unexpected response: %v %t %#v", err, singleItemImplied, test.Infos) } - if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) { + if !apiequality.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) { t.Errorf("unexpected visited objects: %#v", test.Objects()) } } @@ -883,7 +884,7 @@ func TestYAMLStream(t *testing.T) { if err != nil || singleItemImplied || len(test.Infos) != 3 { t.Fatalf("unexpected response: %v %t %#v", err, singleItemImplied, test.Infos) } - if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) { + if !apiequality.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &pods.Items[1], &rc.Items[0]}, test.Objects()) { t.Errorf("unexpected visited objects: %#v", test.Objects()) } } @@ -905,7 +906,7 @@ func TestMultipleObject(t *testing.T) { &svc.Items[0], }, } - if !api.Semantic.DeepDerivative(expected, obj) { + if !apiequality.Semantic.DeepDerivative(expected, obj) { t.Errorf("unexpected visited objects: %#v", obj) } } @@ -1136,7 +1137,7 @@ func TestLatest(t *testing.T) { if err != nil || singleItemImplied || len(test.Infos) != 3 { t.Fatalf("unexpected response: %v %t %#v", err, singleItemImplied, test.Infos) } - if !api.Semantic.DeepDerivative([]runtime.Object{newPod, newPod2, newSvc}, test.Objects()) { + if !apiequality.Semantic.DeepDerivative([]runtime.Object{newPod, newPod2, newSvc}, test.Objects()) { t.Errorf("unexpected visited objects: %#v", test.Objects()) } } diff --git a/pkg/kubelet/config/apiserver_test.go b/pkg/kubelet/config/apiserver_test.go index 501cb496b8a93..5537a70e9493c 100644 --- a/pkg/kubelet/config/apiserver_test.go +++ b/pkg/kubelet/config/apiserver_test.go @@ -19,11 +19,11 @@ package config import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/tools/cache" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" kubetypes "k8s.io/kubernetes/pkg/kubelet/types" ) @@ -71,7 +71,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) { } update := got.(kubetypes.PodUpdate) expected := CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod1v1) - if !api.Semantic.DeepEqual(expected, update) { + if !apiequality.Semantic.DeepEqual(expected, update) { t.Errorf("Expected %#v; Got %#v", expected, update) } @@ -86,7 +86,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) { expectedA := CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod1v1, pod2) expectedB := CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod2, pod1v1) - if !api.Semantic.DeepEqual(expectedA, update) && !api.Semantic.DeepEqual(expectedB, update) { + if !apiequality.Semantic.DeepEqual(expectedA, update) && !apiequality.Semantic.DeepEqual(expectedB, update) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, update) } @@ -100,7 +100,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) { expectedA = CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod1v2, pod2) expectedB = CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod2, pod1v2) - if !api.Semantic.DeepEqual(expectedA, update) && !api.Semantic.DeepEqual(expectedB, update) { + if !apiequality.Semantic.DeepEqual(expectedA, update) && !apiequality.Semantic.DeepEqual(expectedB, update) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, update) } @@ -112,7 +112,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) { } update = got.(kubetypes.PodUpdate) expected = CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource, pod2) - if !api.Semantic.DeepEqual(expected, update) { + if !apiequality.Semantic.DeepEqual(expected, update) { t.Errorf("Expected %#v, Got %#v", expected, update) } @@ -124,7 +124,7 @@ func TestNewSourceApiserver_UpdatesAndMultiplePods(t *testing.T) { } update = got.(kubetypes.PodUpdate) expected = CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource) - if !api.Semantic.DeepEqual(expected, update) { + if !apiequality.Semantic.DeepEqual(expected, update) { t.Errorf("Expected %#v, Got %#v", expected, update) } } @@ -188,7 +188,7 @@ func TestNewSourceApiserverInitialEmptySendsEmptyPodUpdate(t *testing.T) { } update := got.(kubetypes.PodUpdate) expected := CreatePodUpdate(kubetypes.SET, kubetypes.ApiserverSource) - if !api.Semantic.DeepEqual(expected, update) { + if !apiequality.Semantic.DeepEqual(expected, update) { t.Errorf("Expected %#v; Got %#v", expected, update) } } diff --git a/pkg/kubelet/config/config_test.go b/pkg/kubelet/config/config_test.go index 92de495cac5d8..6d16d29dfadab 100644 --- a/pkg/kubelet/config/config_test.go +++ b/pkg/kubelet/config/config_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/api" @@ -101,7 +102,7 @@ func expectPodUpdate(t *testing.T, ch <-chan kubetypes.PodUpdate, expected ...ku // except for "Pods", which are compared separately below. expectedCopy, updateCopy := expected[i], update expectedCopy.Pods, updateCopy.Pods = nil, nil - if !api.Semantic.DeepEqual(expectedCopy, updateCopy) { + if !apiequality.Semantic.DeepEqual(expectedCopy, updateCopy) { t.Fatalf("Expected %#v, Got %#v", expectedCopy, updateCopy) } diff --git a/pkg/kubelet/config/file_linux_test.go b/pkg/kubelet/config/file_linux_test.go index c2091a72fe299..eae27c4660d25 100644 --- a/pkg/kubelet/config/file_linux_test.go +++ b/pkg/kubelet/config/file_linux_test.go @@ -29,6 +29,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -58,7 +59,7 @@ func TestUpdateOnNonExistentFile(t *testing.T) { case got := <-ch: update := got.(kubetypes.PodUpdate) expected := CreatePodUpdate(kubetypes.SET, kubetypes.FileSource) - if !api.Semantic.DeepDerivative(expected, update) { + if !apiequality.Semantic.DeepDerivative(expected, update) { t.Fatalf("expected %#v, Got %#v", expected, update) } @@ -95,7 +96,7 @@ func TestReadPodsFromFileExistAlready(t *testing.T) { t.Fatalf("%s: Invalid pod %#v, %#v", testCase.desc, internalPod, errs) } } - if !api.Semantic.DeepEqual(testCase.expected, update) { + if !apiequality.Semantic.DeepEqual(testCase.expected, update) { t.Fatalf("%s: Expected %#v, Got %#v", testCase.desc, testCase.expected, update) } case <-time.After(wait.ForeverTestTimeout): @@ -159,7 +160,7 @@ func TestExtractFromEmptyDir(t *testing.T) { update := (<-ch).(kubetypes.PodUpdate) expected := CreatePodUpdate(kubetypes.SET, kubetypes.FileSource) - if !api.Semantic.DeepEqual(expected, update) { + if !apiequality.Semantic.DeepEqual(expected, update) { t.Fatalf("expected %#v, Got %#v", expected, update) } } @@ -375,7 +376,7 @@ func expectUpdate(t *testing.T, ch chan interface{}, testCase *testCase) { } } - if !api.Semantic.DeepEqual(testCase.expected, update) { + if !apiequality.Semantic.DeepEqual(testCase.expected, update) { t.Fatalf("%s: Expected: %#v, Got: %#v", testCase.desc, testCase.expected, update) } return diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index 794dbabf5ceb4..2b1bd584b6d81 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -309,7 +310,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { } update := (<-ch).(kubetypes.PodUpdate) - if !api.Semantic.DeepEqual(testCase.expected, update) { + if !apiequality.Semantic.DeepEqual(testCase.expected, update) { t.Errorf("%s: Expected: %#v, Got: %#v", testCase.desc, testCase.expected, update) } for _, pod := range update.Pods { diff --git a/pkg/kubelet/dockertools/docker_manager_test.go b/pkg/kubelet/dockertools/docker_manager_test.go index 77f0d727ad1b3..ab2d5774ef05b 100644 --- a/pkg/kubelet/dockertools/docker_manager_test.go +++ b/pkg/kubelet/dockertools/docker_manager_test.go @@ -37,13 +37,13 @@ import ( "github.com/golang/mock/gomock" cadvisorapi "github.com/google/cadvisor/info/v1" "github.com/stretchr/testify/assert" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" kubetypes "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/util/clock" "k8s.io/client-go/util/flowcontrol" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/apis/componentconfig" @@ -327,10 +327,10 @@ func TestSetEntrypointAndCommand(t *testing.T) { } setEntrypointAndCommand(tc.container, opts, actualOpts) - if e, a := tc.expected.Config.Entrypoint, actualOpts.Config.Entrypoint; !api.Semantic.DeepEqual(e, a) { + if e, a := tc.expected.Config.Entrypoint, actualOpts.Config.Entrypoint; !apiequality.Semantic.DeepEqual(e, a) { t.Errorf("%v: unexpected entrypoint: expected %v, got %v", tc.name, e, a) } - if e, a := tc.expected.Config.Cmd, actualOpts.Config.Cmd; !api.Semantic.DeepEqual(e, a) { + if e, a := tc.expected.Config.Cmd, actualOpts.Config.Cmd; !apiequality.Semantic.DeepEqual(e, a) { t.Errorf("%v: unexpected command: expected %v, got %v", tc.name, e, a) } } diff --git a/pkg/kubelet/kubelet_node_status_test.go b/pkg/kubelet/kubelet_node_status_test.go index ce7fc6ced31bd..026326fb54711 100644 --- a/pkg/kubelet/kubelet_node_status_test.go +++ b/pkg/kubelet/kubelet_node_status_test.go @@ -28,6 +28,7 @@ import ( cadvisorapi "github.com/google/cadvisor/info/v1" cadvisorapiv2 "github.com/google/cadvisor/info/v2" + apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -38,7 +39,6 @@ import ( "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" core "k8s.io/client-go/testing" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/fake" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" @@ -245,7 +245,7 @@ func TestUpdateNewNodeStatus(t *testing.T) { if maxImagesInNodeStatus != len(updatedNode.Status.Images) { t.Errorf("unexpected image list length in node status, expected: %v, got: %v", maxImagesInNodeStatus, len(updatedNode.Status.Images)) } else { - if !api.Semantic.DeepEqual(expectedNode, updatedNode) { + if !apiequality.Semantic.DeepEqual(expectedNode, updatedNode) { t.Errorf("unexpected objects: %s", diff.ObjectDiff(expectedNode, updatedNode)) } } @@ -519,7 +519,7 @@ func TestUpdateExistingNodeStatus(t *testing.T) { t.Errorf("unexpected node condition order. NodeReady should be last.") } - if !api.Semantic.DeepEqual(expectedNode, updatedNode) { + if !apiequality.Semantic.DeepEqual(expectedNode, updatedNode) { t.Errorf("unexpected objects: %s", diff.ObjectDiff(expectedNode, updatedNode)) } } @@ -829,7 +829,7 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) { LastHeartbeatTime: metav1.Time{}, LastTransitionTime: metav1.Time{}, } - if !api.Semantic.DeepEqual(expectedNode, updatedNode) { + if !apiequality.Semantic.DeepEqual(expectedNode, updatedNode) { t.Errorf("unexpected objects: %s", diff.ObjectDiff(expectedNode, updatedNode)) } } diff --git a/pkg/kubelet/kubelet_resources_test.go b/pkg/kubelet/kubelet_resources_test.go index fff5399f0e3f5..2c8096f1545e0 100644 --- a/pkg/kubelet/kubelet_resources_test.go +++ b/pkg/kubelet/kubelet_resources_test.go @@ -23,8 +23,8 @@ import ( cadvisorapi "github.com/google/cadvisor/info/v1" cadvisorapiv2 "github.com/google/cadvisor/info/v2" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/v1" kubetypes "k8s.io/kubernetes/pkg/kubelet/types" ) @@ -78,7 +78,7 @@ func TestPodResourceLimitsDefaulting(t *testing.T) { for idx, tc := range cases { actual, _, err := tk.kubelet.defaultPodLimitsForDownwardApi(tc.pod, nil) as.Nil(err, "failed to default pod limits: %v", err) - if !api.Semantic.DeepEqual(tc.expected, actual) { + if !apiequality.Semantic.DeepEqual(tc.expected, actual) { as.Fail("test case [%d] failed. Expected: %+v, Got: %+v", idx, tc.expected, actual) } } diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index f4a9aaabc55e7..4ff8e7b00a7aa 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -24,6 +24,7 @@ import ( "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "github.com/golang/glog" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -116,7 +117,7 @@ func NewManager(kubeClient clientset.Interface, podManager kubepod.Manager) Mana // This method normalizes the status before comparing so as to make sure that meaningless // changes will be ignored. func isStatusEqual(oldStatus, status *v1.PodStatus) bool { - return api.Semantic.DeepEqual(status, oldStatus) + return apiequality.Semantic.DeepEqual(status, oldStatus) } func (m *manager) Start() { diff --git a/pkg/proxy/config/api_test.go b/pkg/proxy/config/api_test.go index 30ff03c9a82d7..5429325adca19 100644 --- a/pkg/proxy/config/api_test.go +++ b/pkg/proxy/config/api_test.go @@ -20,6 +20,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" @@ -69,7 +70,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected := ServiceUpdate{Op: SET, Services: []api.Service{}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v; Got %#v", expected, got) } @@ -80,7 +81,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = ServiceUpdate{Op: SET, Services: []api.Service{*service1v1}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v; Got %#v", expected, got) } @@ -94,7 +95,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { expectedA := ServiceUpdate{Op: SET, Services: []api.Service{*service1v1, *service2}} expectedB := ServiceUpdate{Op: SET, Services: []api.Service{*service2, *service1v1}} - if !api.Semantic.DeepEqual(expectedA, got) && !api.Semantic.DeepEqual(expectedB, got) { + if !apiequality.Semantic.DeepEqual(expectedA, got) && !apiequality.Semantic.DeepEqual(expectedB, got) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, got) } @@ -107,7 +108,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { expectedA = ServiceUpdate{Op: SET, Services: []api.Service{*service1v2, *service2}} expectedB = ServiceUpdate{Op: SET, Services: []api.Service{*service2, *service1v2}} - if !api.Semantic.DeepEqual(expectedA, got) && !api.Semantic.DeepEqual(expectedB, got) { + if !apiequality.Semantic.DeepEqual(expectedA, got) && !apiequality.Semantic.DeepEqual(expectedB, got) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, got) } @@ -118,7 +119,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = ServiceUpdate{Op: SET, Services: []api.Service{*service2}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v, Got %#v", expected, got) } @@ -129,7 +130,7 @@ func TestNewServicesSourceApi_UpdatesAndMultipleServices(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = ServiceUpdate{Op: SET, Services: []api.Service{}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v, Got %#v", expected, got) } } @@ -180,7 +181,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected := EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v; Got %#v", expected, got) } @@ -191,7 +192,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints1v1}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v; Got %#v", expected, got) } @@ -205,7 +206,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { expectedA := EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints1v1, *endpoints2}} expectedB := EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints2, *endpoints1v1}} - if !api.Semantic.DeepEqual(expectedA, got) && !api.Semantic.DeepEqual(expectedB, got) { + if !apiequality.Semantic.DeepEqual(expectedA, got) && !apiequality.Semantic.DeepEqual(expectedB, got) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, got) } @@ -218,7 +219,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { expectedA = EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints1v2, *endpoints2}} expectedB = EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints2, *endpoints1v2}} - if !api.Semantic.DeepEqual(expectedA, got) && !api.Semantic.DeepEqual(expectedB, got) { + if !apiequality.Semantic.DeepEqual(expectedA, got) && !apiequality.Semantic.DeepEqual(expectedB, got) { t.Errorf("Expected %#v or %#v, Got %#v", expectedA, expectedB, got) } @@ -229,7 +230,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{*endpoints2}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v, Got %#v", expected, got) } @@ -240,7 +241,7 @@ func TestNewEndpointsSourceApi_UpdatesAndMultipleEndpoints(t *testing.T) { t.Errorf("Unable to read from channel when expected") } expected = EndpointsUpdate{Op: SET, Endpoints: []api.Endpoints{}} - if !api.Semantic.DeepEqual(expected, got) { + if !apiequality.Semantic.DeepEqual(expected, got) { t.Errorf("Expected %#v, Got %#v", expected, got) } } diff --git a/pkg/registry/core/persistentvolume/storage/storage_test.go b/pkg/registry/core/persistentvolume/storage/storage_test.go index 1deac7dcb888e..bcd19059a793d 100644 --- a/pkg/registry/core/persistentvolume/storage/storage_test.go +++ b/pkg/registry/core/persistentvolume/storage/storage_test.go @@ -19,6 +19,7 @@ package storage import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -190,7 +191,7 @@ func TestUpdateStatus(t *testing.T) { } pvOut := obj.(*api.PersistentVolume) // only compare the relevant change b/c metadata will differ - if !api.Semantic.DeepEqual(pvIn.Status, pvOut.Status) { + if !apiequality.Semantic.DeepEqual(pvIn.Status, pvOut.Status) { t.Errorf("unexpected object: %s", diff.ObjectDiff(pvIn.Status, pvOut.Status)) } } diff --git a/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go b/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go index 45811e744e866..d375344169a9f 100644 --- a/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go +++ b/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go @@ -19,6 +19,7 @@ package storage import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -187,7 +188,7 @@ func TestUpdateStatus(t *testing.T) { } pvcOut := obj.(*api.PersistentVolumeClaim) // only compare relevant changes b/c of difference in metadata - if !api.Semantic.DeepEqual(pvc.Status, pvcOut.Status) { + if !apiequality.Semantic.DeepEqual(pvc.Status, pvcOut.Status) { t.Errorf("unexpected object: %s", diff.ObjectDiff(pvc.Status, pvcOut.Status)) } } diff --git a/pkg/registry/core/pod/storage/storage_test.go b/pkg/registry/core/pod/storage/storage_test.go index a30fbb83bdaf9..3ae64b998aa30 100644 --- a/pkg/registry/core/pod/storage/storage_test.go +++ b/pkg/registry/core/pod/storage/storage_test.go @@ -21,6 +21,7 @@ import ( "testing" "golang.org/x/net/context" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -634,7 +635,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) { } podOut := obj.(*api.Pod) // validChangedPod only changes the Labels, so were checking the update was valid - if !api.Semantic.DeepEqual(podIn.Labels, podOut.Labels) { + if !apiequality.Semantic.DeepEqual(podIn.Labels, podOut.Labels) { t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, podIn)) } } @@ -705,7 +706,7 @@ func TestEtcdUpdateScheduled(t *testing.T) { } podOut := obj.(*api.Pod) // Check to verify the Spec and Label updates match from change above. Those are the fields changed. - if !api.Semantic.DeepEqual(podOut.Spec, podIn.Spec) || !api.Semantic.DeepEqual(podOut.Labels, podIn.Labels) { + if !apiequality.Semantic.DeepEqual(podOut.Spec, podIn.Spec) || !apiequality.Semantic.DeepEqual(podOut.Labels, podIn.Labels) { t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, podIn)) } @@ -788,9 +789,9 @@ func TestEtcdUpdateStatus(t *testing.T) { } podOut := obj.(*api.Pod) // Check to verify the Label, and Status updates match from change above. Those are the fields changed. - if !api.Semantic.DeepEqual(podOut.Spec, expected.Spec) || - !api.Semantic.DeepEqual(podOut.Labels, expected.Labels) || - !api.Semantic.DeepEqual(podOut.Status, expected.Status) { + if !apiequality.Semantic.DeepEqual(podOut.Spec, expected.Spec) || + !apiequality.Semantic.DeepEqual(podOut.Labels, expected.Labels) || + !apiequality.Semantic.DeepEqual(podOut.Status, expected.Status) { t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, expected)) } } diff --git a/pkg/registry/core/replicationcontroller/storage/storage_test.go b/pkg/registry/core/replicationcontroller/storage/storage_test.go index 35bf53b2132ce..9354f1fd731ea 100644 --- a/pkg/registry/core/replicationcontroller/storage/storage_test.go +++ b/pkg/registry/core/replicationcontroller/storage/storage_test.go @@ -19,6 +19,7 @@ package storage import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -284,7 +285,7 @@ func TestScaleGet(t *testing.T) { t.Fatalf("error fetching scale for %s: %v", name, err) } got := obj.(*autoscaling.Scale) - if !api.Semantic.DeepEqual(want, got) { + if !apiequality.Semantic.DeepEqual(want, got) { t.Errorf("unexpected scale: %s", diff.ObjectDiff(want, got)) } } diff --git a/pkg/registry/core/resourcequota/storage/storage_test.go b/pkg/registry/core/resourcequota/storage/storage_test.go index 97d409387e84e..debe206407e0f 100644 --- a/pkg/registry/core/resourcequota/storage/storage_test.go +++ b/pkg/registry/core/resourcequota/storage/storage_test.go @@ -19,6 +19,7 @@ package storage import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -197,7 +198,7 @@ func TestUpdateStatus(t *testing.T) { obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{}) rqOut := obj.(*api.ResourceQuota) // only compare the meaningful update b/c we can't compare due to metadata - if !api.Semantic.DeepEqual(resourcequotaIn.Status, rqOut.Status) { + if !apiequality.Semantic.DeepEqual(resourcequotaIn.Status, rqOut.Status) { t.Errorf("unexpected object: %s", diff.ObjectDiff(resourcequotaIn, rqOut)) } } diff --git a/pkg/registry/extensions/deployment/storage/storage_test.go b/pkg/registry/extensions/deployment/storage/storage_test.go index c60dca5195092..7f6df0220cb1f 100644 --- a/pkg/registry/extensions/deployment/storage/storage_test.go +++ b/pkg/registry/extensions/deployment/storage/storage_test.go @@ -20,6 +20,7 @@ import ( "reflect" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -226,7 +227,7 @@ func TestScaleGet(t *testing.T) { t.Fatalf("error fetching scale for %s: %v", name, err) } got := obj.(*extensions.Scale) - if !api.Semantic.DeepEqual(want, got) { + if !apiequality.Semantic.DeepEqual(want, got) { t.Errorf("unexpected scale: %s", diff.ObjectDiff(want, got)) } } diff --git a/pkg/registry/extensions/replicaset/storage/storage_test.go b/pkg/registry/extensions/replicaset/storage/storage_test.go index 7a5c9e3a62de1..54fd56b6fa147 100644 --- a/pkg/registry/extensions/replicaset/storage/storage_test.go +++ b/pkg/registry/extensions/replicaset/storage/storage_test.go @@ -19,6 +19,7 @@ package storage import ( "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -281,7 +282,7 @@ func TestScaleGet(t *testing.T) { if err != nil { t.Fatalf("error fetching scale for %s: %v", name, err) } - if !api.Semantic.DeepEqual(got, want) { + if !apiequality.Semantic.DeepEqual(got, want) { t.Errorf("unexpected scale: %s", diff.ObjectDiff(got, want)) } } diff --git a/pkg/storage/cacher_test.go b/pkg/storage/cacher_test.go index dac10d5d15099..ac499bb77aab1 100644 --- a/pkg/storage/cacher_test.go +++ b/pkg/storage/cacher_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -282,7 +283,7 @@ func verifyWatchEvent(t *testing.T, w watch.Interface, eventType watch.EventType t.Logf("(called from line %d)", line) t.Errorf("Expected: %s, got: %s", eventType, event.Type) } - if e, a := eventObject, event.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := eventObject, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Logf("(called from line %d)", line) t.Errorf("Expected (%s): %#v, got: %#v", eventType, e, a) } diff --git a/pkg/storage/etcd/etcd_watcher_test.go b/pkg/storage/etcd/etcd_watcher_test.go index c07c189fe70b8..ea700fa2e8131 100644 --- a/pkg/storage/etcd/etcd_watcher_test.go +++ b/pkg/storage/etcd/etcd_watcher_test.go @@ -20,6 +20,7 @@ import ( rt "runtime" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" @@ -139,7 +140,7 @@ func TestWatchInterpretations(t *testing.T) { if e, a := item.expectType, event.Type; e != a { t.Errorf("'%v - %v': expected %v, got %v", name, action, e, a) } - if e, a := item.expectObject, event.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := item.expectObject, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("'%v - %v': expected %v, got %v", name, action, e, a) } } @@ -311,7 +312,7 @@ func TestWatch(t *testing.T) { if e, a := watch.Added, event.Type; e != a { t.Errorf("Expected %v, got %v", e, a) } - if e, a := pod, event.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := pod, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Expected %v, got %v", e, a) } @@ -391,7 +392,7 @@ func TestWatchEtcdState(t *testing.T) { t.Errorf("Unexpected event %#v", event) } - if e, a := endpoint, event.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := endpoint, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Unexpected error: expected %#v, got %#v", e, a) } } @@ -464,7 +465,7 @@ func TestWatchFromZeroIndex(t *testing.T) { t.Errorf("Unexpected event %#v", event) } - if e, a := pod, event.Object; a == nil || !api.Semantic.DeepDerivative(e, a) { + if e, a := pod, event.Object; a == nil || !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Unexpected error: expected %#v, got %#v", e, a) } } @@ -494,7 +495,7 @@ func TestWatchListFromZeroIndex(t *testing.T) { t.Errorf("Unexpected event %#v", event) } - if e, a := pod, event.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := pod, event.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Unexpected error: expected %v, got %v", e, a) } } diff --git a/pkg/storage/watch_cache_test.go b/pkg/storage/watch_cache_test.go index 18fd0ade9a50e..4a82cf1e576cd 100644 --- a/pkg/storage/watch_cache_test.go +++ b/pkg/storage/watch_cache_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -68,7 +69,7 @@ func TestWatchCacheBasic(t *testing.T) { if item, ok, _ := store.Get(pod1); !ok { t.Errorf("didn't find pod") } else { - if !api.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/pod", Object: pod1}, item) { + if !apiequality.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/pod", Object: pod1}, item) { t.Errorf("expected %v, got %v", pod1, item) } } @@ -79,7 +80,7 @@ func TestWatchCacheBasic(t *testing.T) { if item, ok, _ := store.Get(pod2); !ok { t.Errorf("didn't find pod") } else { - if !api.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/pod", Object: pod2}, item) { + if !apiequality.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/pod", Object: pod2}, item) { t.Errorf("expected %v, got %v", pod1, item) } } @@ -154,7 +155,7 @@ func TestEvents(t *testing.T) { t.Errorf("unexpected event type: %v", result[0].Type) } pod := makeTestPod("pod", uint64(3)) - if !api.Semantic.DeepEqual(pod, result[0].Object) { + if !apiequality.Semantic.DeepEqual(pod, result[0].Object) { t.Errorf("unexpected item: %v, expected: %v", result[0].Object, pod) } if result[0].PrevObject != nil { @@ -185,11 +186,11 @@ func TestEvents(t *testing.T) { t.Errorf("unexpected event type: %v", result[i].Type) } pod := makeTestPod("pod", uint64(i+4)) - if !api.Semantic.DeepEqual(pod, result[i].Object) { + if !apiequality.Semantic.DeepEqual(pod, result[i].Object) { t.Errorf("unexpected item: %v, expected: %v", result[i].Object, pod) } prevPod := makeTestPod("pod", uint64(i+3)) - if !api.Semantic.DeepEqual(prevPod, result[i].PrevObject) { + if !apiequality.Semantic.DeepEqual(prevPod, result[i].PrevObject) { t.Errorf("unexpected item: %v, expected: %v", result[i].PrevObject, prevPod) } } @@ -216,7 +217,7 @@ func TestEvents(t *testing.T) { } for i := 0; i < 5; i++ { pod := makeTestPod("pod", uint64(i+5)) - if !api.Semantic.DeepEqual(pod, result[i].Object) { + if !apiequality.Semantic.DeepEqual(pod, result[i].Object) { t.Errorf("unexpected item: %v, expected: %v", result[i].Object, pod) } } @@ -237,11 +238,11 @@ func TestEvents(t *testing.T) { t.Errorf("unexpected event type: %v", result[0].Type) } pod := makeTestPod("pod", uint64(10)) - if !api.Semantic.DeepEqual(pod, result[0].Object) { + if !apiequality.Semantic.DeepEqual(pod, result[0].Object) { t.Errorf("unexpected item: %v, expected: %v", result[0].Object, pod) } prevPod := makeTestPod("pod", uint64(9)) - if !api.Semantic.DeepEqual(prevPod, result[0].PrevObject) { + if !apiequality.Semantic.DeepEqual(prevPod, result[0].PrevObject) { t.Errorf("unexpected item: %v, expected: %v", result[0].PrevObject, prevPod) } } @@ -287,7 +288,7 @@ func TestWaitUntilFreshAndGet(t *testing.T) { if !exists { t.Fatalf("no results returned: %#v", obj) } - if !api.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/bar", Object: makeTestPod("bar", 5)}, obj) { + if !apiequality.Semantic.DeepEqual(&storeElement{Key: "prefix/ns/bar", Object: makeTestPod("bar", 5)}, obj) { t.Errorf("unexpected element returned: %#v", obj) } } diff --git a/pkg/util/io/io_test.go b/pkg/util/io/io_test.go index 86b00394ee1e4..39317427574ba 100644 --- a/pkg/util/io/io_test.go +++ b/pkg/util/io/io_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/pborman/uuid" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/runtime" utiltesting "k8s.io/client-go/util/testing" "k8s.io/kubernetes/pkg/api" @@ -49,7 +50,7 @@ func TestSavePodToFile(t *testing.T) { if err != nil { t.Fatalf("failed to load pod from file: %v", err) } - if !api.Semantic.DeepEqual(pod, podFromFile) { + if !apiequality.Semantic.DeepEqual(pod, podFromFile) { t.Errorf("\nexpected %#v\ngot %#v\n", pod, podFromFile) } } diff --git a/plugin/pkg/admission/gc/gc_admission.go b/plugin/pkg/admission/gc/gc_admission.go index 5f21d16b5ace1..30992f412abca 100644 --- a/plugin/pkg/admission/gc/gc_admission.go +++ b/plugin/pkg/admission/gc/gc_admission.go @@ -20,11 +20,11 @@ import ( "fmt" "io" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/admission" "k8s.io/apiserver/pkg/authorization/authorizer" - "k8s.io/kubernetes/pkg/api" ) func init() { @@ -91,7 +91,7 @@ func isChangingOwnerReference(newObj, oldObj runtime.Object) bool { return true } for i := range oldOwners { - if !api.Semantic.DeepEqual(oldOwners[i], newOwners[i]) { + if !apiequality.Semantic.DeepEqual(oldOwners[i], newOwners[i]) { return true } } diff --git a/plugin/pkg/admission/limitranger/admission_test.go b/plugin/pkg/admission/limitranger/admission_test.go index 4541b25258a97..d445d61340ff4 100644 --- a/plugin/pkg/admission/limitranger/admission_test.go +++ b/plugin/pkg/admission/limitranger/admission_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -166,7 +167,7 @@ func TestDefaultContainerResourceRequirements(t *testing.T) { } actual := defaultContainerResourceRequirements(&limitRange) - if !api.Semantic.DeepEqual(expected, actual) { + if !apiequality.Semantic.DeepEqual(expected, actual) { t.Errorf("actual.Limits != expected.Limits; %v != %v", actual.Limits, expected.Limits) t.Errorf("actual.Requests != expected.Requests; %v != %v", actual.Requests, expected.Requests) t.Errorf("expected != actual; %v != %v", expected, actual) @@ -199,7 +200,7 @@ func TestMergePodResourceRequirements(t *testing.T) { mergePodResourceRequirements(&pod, &defaultRequirements) for i := range pod.Spec.Containers { actual := pod.Spec.Containers[i].Resources - if !api.Semantic.DeepEqual(expected, actual) { + if !apiequality.Semantic.DeepEqual(expected, actual) { t.Errorf("pod %v, expected != actual; %v != %v", pod.Name, expected, actual) } } @@ -218,13 +219,13 @@ func TestMergePodResourceRequirements(t *testing.T) { mergePodResourceRequirements(&pod, &defaultRequirements) for i := range pod.Spec.Containers { actual := pod.Spec.Containers[i].Resources - if !api.Semantic.DeepEqual(expected, actual) { + if !apiequality.Semantic.DeepEqual(expected, actual) { t.Errorf("pod %v, expected != actual; %v != %v", pod.Name, expected, actual) } } for i := range pod.Spec.InitContainers { actual := pod.Spec.InitContainers[i].Resources - if !api.Semantic.DeepEqual(expected, actual) { + if !apiequality.Semantic.DeepEqual(expected, actual) { t.Errorf("pod %v, expected != actual; %v != %v", pod.Name, expected, actual) } } @@ -238,13 +239,13 @@ func TestMergePodResourceRequirements(t *testing.T) { mergePodResourceRequirements(&pod, &defaultRequirements) for i := range pod.Spec.Containers { actual := pod.Spec.Containers[i].Resources - if !api.Semantic.DeepEqual(expected, actual) { + if !apiequality.Semantic.DeepEqual(expected, actual) { t.Errorf("pod %v, expected != actual; %v != %v", pod.Name, expected, actual) } } for i := range pod.Spec.InitContainers { actual := pod.Spec.InitContainers[i].Resources - if !api.Semantic.DeepEqual(initInputs[i], actual) { + if !apiequality.Semantic.DeepEqual(initInputs[i], actual) { t.Errorf("pod %v, expected != actual; %v != %v", pod.Name, initInputs[i], actual) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/api/equality/semantic.go b/staging/src/k8s.io/apimachinery/pkg/api/equality/semantic.go new file mode 100644 index 0000000000000..3ebd8c719d0a6 --- /dev/null +++ b/staging/src/k8s.io/apimachinery/pkg/api/equality/semantic.go @@ -0,0 +1,46 @@ +/* +Copyright 2014 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. +*/ + +package equality + +import ( + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/conversion" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" +) + +// Semantic can do semantic deep equality checks for api objects. +// Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true +var Semantic = conversion.EqualitiesOrDie( + func(a, b resource.Quantity) bool { + // Ignore formatting, only care that numeric value stayed the same. + // TODO: if we decide it's important, it should be safe to start comparing the format. + // + // Uninitialized quantities are equivalent to 0 quantities. + return a.Cmp(b) == 0 + }, + func(a, b metav1.Time) bool { + return a.UTC() == b.UTC() + }, + func(a, b labels.Selector) bool { + return a.String() == b.String() + }, + func(a, b fields.Selector) bool { + return a.String() == b.String() + }, +) diff --git a/staging/src/k8s.io/client-go/pkg/api/helpers.go b/staging/src/k8s.io/client-go/pkg/api/helpers.go index 943ed0afb9739..7a06fc5ab3718 100644 --- a/staging/src/k8s.io/client-go/pkg/api/helpers.go +++ b/staging/src/k8s.io/client-go/pkg/api/helpers.go @@ -67,7 +67,7 @@ func NonConvertibleFields(annotations map[string]string) map[string]string { } // Semantic can do semantic deep equality checks for api objects. -// Example: api.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true +// Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true var Semantic = conversion.EqualitiesOrDie( func(a, b resource.Quantity) bool { // Ignore formatting, only care that numeric value stayed the same. diff --git a/staging/src/k8s.io/client-go/rest/request_test.go b/staging/src/k8s.io/client-go/rest/request_test.go index db6049c925c5c..58b55ff32f69b 100755 --- a/staging/src/k8s.io/client-go/rest/request_test.go +++ b/staging/src/k8s.io/client-go/rest/request_test.go @@ -50,6 +50,7 @@ import ( "k8s.io/client-go/util/clock" "k8s.io/client-go/util/flowcontrol" utiltesting "k8s.io/client-go/util/testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" _ "k8s.io/client-go/pkg/api/install" ) @@ -415,7 +416,7 @@ func TestTransformResponse(t *testing.T) { if test.ErrFn != nil && !test.ErrFn(err) { t.Errorf("%d: error function did not match: %v", i, err) } - if !(test.Data == nil && response == nil) && !api.Semantic.DeepDerivative(test.Data, response) { + if !(test.Data == nil && response == nil) && !apiequality.Semantic.DeepDerivative(test.Data, response) { t.Errorf("%d: unexpected response: %#v %#v", i, test.Data, response) } if test.Created != created { @@ -1043,7 +1044,7 @@ func TestDoRequestNewWay(t *testing.T) { } if obj == nil { t.Error("nil obj") - } else if !api.Semantic.DeepDerivative(expectedObj, obj) { + } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) { t.Errorf("Expected: %#v, got %#v", expectedObj, obj) } requestURL := defaultResourcePathWithPrefix("foo/bar", "", "", "baz") @@ -1276,7 +1277,7 @@ func TestDoRequestNewWayReader(t *testing.T) { } if obj == nil { t.Error("nil obj") - } else if !api.Semantic.DeepDerivative(expectedObj, obj) { + } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) { t.Errorf("Expected: %#v, got %#v", expectedObj, obj) } tmpStr := string(reqBodyExpected) @@ -1316,7 +1317,7 @@ func TestDoRequestNewWayObj(t *testing.T) { } if obj == nil { t.Error("nil obj") - } else if !api.Semantic.DeepDerivative(expectedObj, obj) { + } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) { t.Errorf("Expected: %#v, got %#v", expectedObj, obj) } tmpStr := string(reqBodyExpected) @@ -1370,7 +1371,7 @@ func TestDoRequestNewWayFile(t *testing.T) { } if obj == nil { t.Error("nil obj") - } else if !api.Semantic.DeepDerivative(expectedObj, obj) { + } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) { t.Errorf("Expected: %#v, got %#v", expectedObj, obj) } if wasCreated { @@ -1415,7 +1416,7 @@ func TestWasCreated(t *testing.T) { } if obj == nil { t.Error("nil obj") - } else if !api.Semantic.DeepDerivative(expectedObj, obj) { + } else if !apiequality.Semantic.DeepDerivative(expectedObj, obj) { t.Errorf("Expected: %#v, got %#v", expectedObj, obj) } if !wasCreated { @@ -1623,7 +1624,7 @@ func TestWatch(t *testing.T) { if e, a := item.t, got.Type; e != a { t.Errorf("Expected %v, got %v", e, a) } - if e, a := item.obj, got.Object; !api.Semantic.DeepDerivative(e, a) { + if e, a := item.obj, got.Object; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Expected %v, got %v", e, a) } } diff --git a/staging/src/k8s.io/client-go/rest/watch/decoder_test.go b/staging/src/k8s.io/client-go/rest/watch/decoder_test.go index 559d1e5f772bc..fa7f3957b5e5f 100644 --- a/staging/src/k8s.io/client-go/rest/watch/decoder_test.go +++ b/staging/src/k8s.io/client-go/rest/watch/decoder_test.go @@ -30,6 +30,7 @@ import ( "k8s.io/client-go/pkg/api" "k8s.io/client-go/pkg/api/v1" restclientwatch "k8s.io/client-go/rest/watch" + apiequality "k8s.io/apimachinery/pkg/api/equality" _ "k8s.io/client-go/pkg/api/install" ) @@ -68,7 +69,7 @@ func TestDecoder(t *testing.T) { if e, a := eventType, action; e != a { t.Errorf("Expected %v, got %v", e, a) } - if e, a := expect, got; !api.Semantic.DeepDerivative(e, a) { + if e, a := expect, got; !apiequality.Semantic.DeepDerivative(e, a) { t.Errorf("Expected %v, got %v", e, a) } t.Logf("Exited read") diff --git a/staging/src/k8s.io/client-go/rest/watch/encoder_test.go b/staging/src/k8s.io/client-go/rest/watch/encoder_test.go index 6a8e1e8a3fd98..f2e5aaa764c8f 100644 --- a/staging/src/k8s.io/client-go/rest/watch/encoder_test.go +++ b/staging/src/k8s.io/client-go/rest/watch/encoder_test.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "testing" + apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" @@ -71,7 +72,7 @@ func TestEncodeDecodeRoundTrip(t *testing.T) { t.Errorf("%d: unexpected error: %v", i, err) continue } - if !api.Semantic.DeepDerivative(testCase.Object, obj) { + if !apiequality.Semantic.DeepDerivative(testCase.Object, obj) { t.Errorf("%d: expected %#v, got %#v", i, testCase.Object, obj) } if event != testCase.Type { diff --git a/test/integration/serviceaccount/service_account_test.go b/test/integration/serviceaccount/service_account_test.go index 07dff8ab6490e..330b7f881b844 100644 --- a/test/integration/serviceaccount/service_account_test.go +++ b/test/integration/serviceaccount/service_account_test.go @@ -31,6 +31,7 @@ import ( "testing" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -259,13 +260,13 @@ func TestServiceAccountTokenAutoMount(t *testing.T) { if createdPod.Spec.ServiceAccountName != expectedServiceAccount { t.Fatalf("Expected %s, got %s", expectedServiceAccount, createdPod.Spec.ServiceAccountName) } - if !api.Semantic.DeepEqual(&expectedVolumes, &createdPod.Spec.Volumes) { + if !apiequality.Semantic.DeepEqual(&expectedVolumes, &createdPod.Spec.Volumes) { t.Fatalf("Expected\n\t%#v\n\tgot\n\t%#v", expectedVolumes, createdPod.Spec.Volumes) } - if !api.Semantic.DeepEqual(&expectedContainer1VolumeMounts, &createdPod.Spec.Containers[0].VolumeMounts) { + if !apiequality.Semantic.DeepEqual(&expectedContainer1VolumeMounts, &createdPod.Spec.Containers[0].VolumeMounts) { t.Fatalf("Expected\n\t%#v\n\tgot\n\t%#v", expectedContainer1VolumeMounts, createdPod.Spec.Containers[0].VolumeMounts) } - if !api.Semantic.DeepEqual(&expectedContainer2VolumeMounts, &createdPod.Spec.Containers[1].VolumeMounts) { + if !apiequality.Semantic.DeepEqual(&expectedContainer2VolumeMounts, &createdPod.Spec.Containers[1].VolumeMounts) { t.Fatalf("Expected\n\t%#v\n\tgot\n\t%#v", expectedContainer2VolumeMounts, createdPod.Spec.Containers[1].VolumeMounts) } } diff --git a/test/utils/runners.go b/test/utils/runners.go index ce1d836379714..2778e021d80f6 100644 --- a/test/utils/runners.go +++ b/test/utils/runners.go @@ -23,6 +23,7 @@ import ( "sync" "time" + apiequality "k8s.io/apimachinery/pkg/api/equality" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -845,7 +846,7 @@ func DoCleanupNode(client clientset.Interface, nodeName string, strategy Prepare return fmt.Errorf("Skipping cleanup of Node: failed to get Node %v: %v", nodeName, err) } updatedNode := strategy.CleanupNode(node) - if api.Semantic.DeepEqual(node, updatedNode) { + if apiequality.Semantic.DeepEqual(node, updatedNode) { return nil } if _, err = client.Core().Nodes().Update(updatedNode); err == nil {