From a6c000803dcbdef4743f560483897fb577988890 Mon Sep 17 00:00:00 2001 From: mofanke Date: Sat, 7 May 2022 17:54:22 +0800 Subject: [PATCH] fix resource compare issues --- components/common/reconcilehelper/util.go | 16 +++++++++------- components/notebook-controller/go.mod | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/common/reconcilehelper/util.go b/components/common/reconcilehelper/util.go index ded19b08ab8..9b6bdf2b4f1 100644 --- a/components/common/reconcilehelper/util.go +++ b/components/common/reconcilehelper/util.go @@ -8,6 +8,8 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + + "k8s.io/apimachinery/pkg/api/equality" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -125,7 +127,7 @@ func CopyStatefulSetFields(from, to *appsv1.StatefulSet) bool { requireUpdate = true } - if !reflect.DeepEqual(to.Spec.Template.Spec, from.Spec.Template.Spec) { + if !equality.Semantic.DeepDerivative(from.Spec.Template.Spec, to.Spec.Template.Spec) { requireUpdate = true } to.Spec.Template.Spec = from.Spec.Template.Spec @@ -149,12 +151,12 @@ func CopyDeploymentSetFields(from, to *appsv1.Deployment) bool { } to.Annotations = from.Annotations - if from.Spec.Replicas != to.Spec.Replicas { - to.Spec.Replicas = from.Spec.Replicas + if *from.Spec.Replicas != *to.Spec.Replicas { + *to.Spec.Replicas = *from.Spec.Replicas requireUpdate = true } - if !reflect.DeepEqual(to.Spec.Template.Spec, from.Spec.Template.Spec) { + if !equality.Semantic.DeepDerivative(from.Spec.Template.Spec, to.Spec.Template.Spec) { requireUpdate = true } to.Spec.Template.Spec = from.Spec.Template.Spec @@ -211,9 +213,9 @@ func CopyVirtualService(from, to *unstructured.Unstructured) bool { return true } - requiresUpdate := !reflect.DeepEqual(fromSpec, toSpec) - if requiresUpdate { + requireUpdate := !reflect.DeepEqual(fromSpec, toSpec) + if requireUpdate { unstructured.SetNestedMap(to.Object, fromSpec, "spec") } - return requiresUpdate + return requireUpdate } diff --git a/components/notebook-controller/go.mod b/components/notebook-controller/go.mod index 585d2025b6e..d0e4ab9994b 100644 --- a/components/notebook-controller/go.mod +++ b/components/notebook-controller/go.mod @@ -73,3 +73,4 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) +replace github.com/kubeflow/kubeflow/components/common => ../common \ No newline at end of file