From 92c3e20e93954bb7f029a09d1a10d310891ee7d2 Mon Sep 17 00:00:00 2001 From: Marcin Wielgus Date: Thu, 10 Nov 2016 01:52:25 +0100 Subject: [PATCH] Make null and empty as equivalent in ObjectMetaEquivalent --- federation/pkg/federation-controller/util/meta.go | 4 ++-- .../pkg/federation-controller/util/meta_test.go | 14 ++++++++++++++ .../federation-controller/util/test/test_helper.go | 8 ++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/federation/pkg/federation-controller/util/meta.go b/federation/pkg/federation-controller/util/meta.go index ca2c0e61939..ed40df5b3dc 100644 --- a/federation/pkg/federation-controller/util/meta.go +++ b/federation/pkg/federation-controller/util/meta.go @@ -65,10 +65,10 @@ func ObjectMetaEquivalent(a, b api_v1.ObjectMeta) bool { if a.Namespace != b.Namespace { return false } - if !reflect.DeepEqual(a.Labels, b.Labels) { + if !reflect.DeepEqual(a.Labels, b.Labels) && (len(a.Labels) != 0 || len(b.Labels) != 0) { return false } - if !reflect.DeepEqual(a.Annotations, b.Annotations) { + if !reflect.DeepEqual(a.Annotations, b.Annotations) && (len(a.Annotations) != 0 || len(b.Annotations) != 0) { return false } return true diff --git a/federation/pkg/federation-controller/util/meta_test.go b/federation/pkg/federation-controller/util/meta_test.go index c5638add590..f0c2c88c4f2 100644 --- a/federation/pkg/federation-controller/util/meta_test.go +++ b/federation/pkg/federation-controller/util/meta_test.go @@ -56,6 +56,18 @@ func TestObjectMeta(t *testing.T) { ResourceVersion: "1231255531412", Annotations: map[string]string{"A": "B"}, } + o7 := api_v1.ObjectMeta{ + Namespace: "ns1", + Name: "s1", + ResourceVersion: "1231255531412", + Annotations: map[string]string{}, + Labels: map[string]string{}, + } + o8 := api_v1.ObjectMeta{ + Namespace: "ns1", + Name: "s1", + ResourceVersion: "1231255531412", + } assert.Equal(t, 0, len(o2.UID)) assert.Equal(t, 0, len(o2.ResourceVersion)) assert.Equal(t, o1.Name, o2.Name) @@ -64,6 +76,8 @@ func TestObjectMeta(t *testing.T) { assert.True(t, ObjectMetaEquivalent(o3, o4)) assert.True(t, ObjectMetaEquivalent(o5, o6)) assert.True(t, ObjectMetaEquivalent(o3, o5)) + assert.True(t, ObjectMetaEquivalent(o7, o8)) + assert.True(t, ObjectMetaEquivalent(o8, o7)) } func TestObjectMetaAndSpec(t *testing.T) { diff --git a/federation/pkg/federation-controller/util/test/test_helper.go b/federation/pkg/federation-controller/util/test/test_helper.go index 91657924224..e7011ed4b61 100644 --- a/federation/pkg/federation-controller/util/test/test_helper.go +++ b/federation/pkg/federation-controller/util/test/test_helper.go @@ -242,11 +242,11 @@ func CompareObjectMeta(a, b api_v1.ObjectMeta) error { if a.Name != b.Name { return fmt.Errorf("Different name expected:%s observed:%s", a.Namespace, b.Namespace) } - if !reflect.DeepEqual(a.Annotations, b.Annotations) { - return fmt.Errorf("Annotations are different expected:%v observerd:%v", a.Annotations, b.Annotations) + if !reflect.DeepEqual(a.Labels, b.Labels) && (len(a.Labels) != 0 || len(b.Labels) != 0) { + return fmt.Errorf("Labels are different expected:%v observerd:%v", a.Labels, b.Labels) } - if !reflect.DeepEqual(a.Labels, b.Labels) { - return fmt.Errorf("Annotations are different expected:%v observerd:%v", a.Labels, b.Labels) + if !reflect.DeepEqual(a.Annotations, b.Annotations) && (len(a.Annotations) != 0 || len(b.Annotations) != 0) { + return fmt.Errorf("Annotations are different expected:%v observerd:%v", a.Annotations, b.Annotations) } return nil }