From 34a114f6a92a028dcccb5a7e209bba72ecd5dca0 Mon Sep 17 00:00:00 2001 From: Shiyang Wang Date: Sun, 23 Apr 2017 14:52:05 +0800 Subject: [PATCH] Update to use Semantic.DeepEqual in regsitry --- pkg/registry/apps/petset/BUILD | 1 + pkg/registry/apps/petset/strategy.go | 4 ++-- pkg/registry/core/replicationcontroller/BUILD | 1 + pkg/registry/core/replicationcontroller/strategy.go | 6 +++--- pkg/registry/extensions/deployment/BUILD | 1 + pkg/registry/extensions/deployment/strategy.go | 6 +++--- pkg/registry/extensions/ingress/BUILD | 1 + pkg/registry/extensions/ingress/strategy.go | 4 ++-- pkg/registry/extensions/networkpolicy/BUILD | 1 + pkg/registry/extensions/networkpolicy/strategy.go | 4 ++-- pkg/registry/extensions/replicaset/BUILD | 1 + pkg/registry/extensions/replicaset/strategy.go | 4 ++-- pkg/registry/policy/poddisruptionbudget/BUILD | 1 + pkg/registry/policy/poddisruptionbudget/strategy.go | 4 ++-- 14 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkg/registry/apps/petset/BUILD b/pkg/registry/apps/petset/BUILD index 5db2487ccda..fb2f8298a42 100644 --- a/pkg/registry/apps/petset/BUILD +++ b/pkg/registry/apps/petset/BUILD @@ -19,6 +19,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/apps:go_default_library", "//pkg/apis/apps/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/registry/apps/petset/strategy.go b/pkg/registry/apps/petset/strategy.go index 4a61860baab..46c337c1951 100644 --- a/pkg/registry/apps/petset/strategy.go +++ b/pkg/registry/apps/petset/strategy.go @@ -18,8 +18,8 @@ package petset import ( "fmt" - "reflect" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -73,7 +73,7 @@ func (statefulSetStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, // Any changes to the spec increment the generation number, any changes to the // status should reflect the generation number of the corresponding object. // See metav1.ObjectMeta description for more information on Generation. - if !reflect.DeepEqual(oldStatefulSet.Spec, newStatefulSet.Spec) { + if !apiequality.Semantic.DeepEqual(oldStatefulSet.Spec, newStatefulSet.Spec) { newStatefulSet.Generation = oldStatefulSet.Generation + 1 } diff --git a/pkg/registry/core/replicationcontroller/BUILD b/pkg/registry/core/replicationcontroller/BUILD index 90c1116c32a..2082af00556 100644 --- a/pkg/registry/core/replicationcontroller/BUILD +++ b/pkg/registry/core/replicationcontroller/BUILD @@ -20,6 +20,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/api/helper:go_default_library", "//pkg/api/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", diff --git a/pkg/registry/core/replicationcontroller/strategy.go b/pkg/registry/core/replicationcontroller/strategy.go index d4d7cfebe26..d3ff54cf8b1 100644 --- a/pkg/registry/core/replicationcontroller/strategy.go +++ b/pkg/registry/core/replicationcontroller/strategy.go @@ -20,10 +20,10 @@ package replicationcontroller import ( "fmt" - "reflect" "strconv" "strings" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -81,7 +81,7 @@ func (rcStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runti // status its own object, and even if we don't, writes may be the result of a // read-update-write loop, so the contents of spec may not actually be the spec that // the controller has *seen*. - if !reflect.DeepEqual(oldController.Spec, newController.Spec) { + if !apiequality.Semantic.DeepEqual(oldController.Spec, newController.Spec) { newController.Generation = oldController.Generation + 1 } } @@ -120,7 +120,7 @@ func (rcStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime switch { case strings.Contains(brokenField, "selector"): - if !reflect.DeepEqual(oldRc.Spec.Selector, newRc.Spec.Selector) { + if !apiequality.Semantic.DeepEqual(oldRc.Spec.Selector, newRc.Spec.Selector) { errs = append(errs, field.Invalid(field.NewPath("spec").Child("selector"), newRc.Spec.Selector, "cannot update non-convertible selector")) } default: diff --git a/pkg/registry/extensions/deployment/BUILD b/pkg/registry/extensions/deployment/BUILD index e32747f51ff..c4280eaaed3 100644 --- a/pkg/registry/extensions/deployment/BUILD +++ b/pkg/registry/extensions/deployment/BUILD @@ -20,6 +20,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/extensions:go_default_library", "//pkg/apis/extensions/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", diff --git a/pkg/registry/extensions/deployment/strategy.go b/pkg/registry/extensions/deployment/strategy.go index 059e1b20998..2dd0574ff88 100644 --- a/pkg/registry/extensions/deployment/strategy.go +++ b/pkg/registry/extensions/deployment/strategy.go @@ -18,8 +18,8 @@ package deployment import ( "fmt" - "reflect" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -86,8 +86,8 @@ func (deploymentStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, o // Spec updates bump the generation so that we can distinguish between // scaling events and template changes, annotation updates bump the generation // because annotations are copied from deployments to their replica sets. - if !reflect.DeepEqual(newDeployment.Spec, oldDeployment.Spec) || - !reflect.DeepEqual(newDeployment.Annotations, oldDeployment.Annotations) { + if !apiequality.Semantic.DeepEqual(newDeployment.Spec, oldDeployment.Spec) || + !apiequality.Semantic.DeepEqual(newDeployment.Annotations, oldDeployment.Annotations) { newDeployment.Generation = oldDeployment.Generation + 1 } } diff --git a/pkg/registry/extensions/ingress/BUILD b/pkg/registry/extensions/ingress/BUILD index 34dc8a98e77..d849d82d872 100644 --- a/pkg/registry/extensions/ingress/BUILD +++ b/pkg/registry/extensions/ingress/BUILD @@ -19,6 +19,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/extensions:go_default_library", "//pkg/apis/extensions/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/registry/extensions/ingress/strategy.go b/pkg/registry/extensions/ingress/strategy.go index e17f58a0a67..2f619237618 100644 --- a/pkg/registry/extensions/ingress/strategy.go +++ b/pkg/registry/extensions/ingress/strategy.go @@ -18,8 +18,8 @@ package ingress import ( "fmt" - "reflect" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -66,7 +66,7 @@ func (ingressStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old // Any changes to the spec increment the generation number, any changes to the // status should reflect the generation number of the corresponding object. // See metav1.ObjectMeta description for more information on Generation. - if !reflect.DeepEqual(oldIngress.Spec, newIngress.Spec) { + if !apiequality.Semantic.DeepEqual(oldIngress.Spec, newIngress.Spec) { newIngress.Generation = oldIngress.Generation + 1 } diff --git a/pkg/registry/extensions/networkpolicy/BUILD b/pkg/registry/extensions/networkpolicy/BUILD index 76cf0555a07..782847dde18 100644 --- a/pkg/registry/extensions/networkpolicy/BUILD +++ b/pkg/registry/extensions/networkpolicy/BUILD @@ -19,6 +19,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/extensions:go_default_library", "//pkg/apis/extensions/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/registry/extensions/networkpolicy/strategy.go b/pkg/registry/extensions/networkpolicy/strategy.go index 1af7651baf9..327262f73dc 100644 --- a/pkg/registry/extensions/networkpolicy/strategy.go +++ b/pkg/registry/extensions/networkpolicy/strategy.go @@ -18,8 +18,8 @@ package networkpolicy import ( "fmt" - "reflect" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -61,7 +61,7 @@ func (networkPolicyStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj // Any changes to the spec increment the generation number, any changes to the // status should reflect the generation number of the corresponding object. // See metav1.ObjectMeta description for more information on Generation. - if !reflect.DeepEqual(oldNetworkPolicy.Spec, newNetworkPolicy.Spec) { + if !apiequality.Semantic.DeepEqual(oldNetworkPolicy.Spec, newNetworkPolicy.Spec) { newNetworkPolicy.Generation = oldNetworkPolicy.Generation + 1 } } diff --git a/pkg/registry/extensions/replicaset/BUILD b/pkg/registry/extensions/replicaset/BUILD index 68b780b6f54..e798f6e15a9 100644 --- a/pkg/registry/extensions/replicaset/BUILD +++ b/pkg/registry/extensions/replicaset/BUILD @@ -20,6 +20,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/extensions:go_default_library", "//pkg/apis/extensions/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", diff --git a/pkg/registry/extensions/replicaset/strategy.go b/pkg/registry/extensions/replicaset/strategy.go index daee90f9f27..260bafedd8b 100644 --- a/pkg/registry/extensions/replicaset/strategy.go +++ b/pkg/registry/extensions/replicaset/strategy.go @@ -20,9 +20,9 @@ package replicaset import ( "fmt" - "reflect" "strconv" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -80,7 +80,7 @@ func (rsStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runti // status its own object, and even if we don't, writes may be the result of a // read-update-write loop, so the contents of spec may not actually be the spec that // the ReplicaSet has *seen*. - if !reflect.DeepEqual(oldRS.Spec, newRS.Spec) { + if !apiequality.Semantic.DeepEqual(oldRS.Spec, newRS.Spec) { newRS.Generation = oldRS.Generation + 1 } } diff --git a/pkg/registry/policy/poddisruptionbudget/BUILD b/pkg/registry/policy/poddisruptionbudget/BUILD index 3d1985d633f..b492e7221ed 100644 --- a/pkg/registry/policy/poddisruptionbudget/BUILD +++ b/pkg/registry/policy/poddisruptionbudget/BUILD @@ -19,6 +19,7 @@ go_library( "//pkg/api:go_default_library", "//pkg/apis/policy:go_default_library", "//pkg/apis/policy/validation:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library", "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library", "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", diff --git a/pkg/registry/policy/poddisruptionbudget/strategy.go b/pkg/registry/policy/poddisruptionbudget/strategy.go index 8314f3cbc40..5a68bf6623f 100644 --- a/pkg/registry/policy/poddisruptionbudget/strategy.go +++ b/pkg/registry/policy/poddisruptionbudget/strategy.go @@ -18,8 +18,8 @@ package poddisruptionbudget import ( "fmt" - "reflect" + apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -66,7 +66,7 @@ func (podDisruptionBudgetStrategy) PrepareForUpdate(ctx genericapirequest.Contex // Any changes to the spec increment the generation number, any changes to the // status should reflect the generation number of the corresponding object. // See metav1.ObjectMeta description for more information on Generation. - if !reflect.DeepEqual(oldPodDisruptionBudget.Spec, newPodDisruptionBudget.Spec) { + if !apiequality.Semantic.DeepEqual(oldPodDisruptionBudget.Spec, newPodDisruptionBudget.Spec) { newPodDisruptionBudget.Generation = oldPodDisruptionBudget.Generation + 1 } }