From 552b84041e969af7986300e2ae508d9f658f8cda Mon Sep 17 00:00:00 2001 From: Tom Lanyon Date: Thu, 9 Nov 2017 20:18:25 +1100 Subject: [PATCH] Fix merging of ingress-specific annotations. Annotations were not overriding the default values for their Location; this was especially evident on the "/" Location for a host, which gains more defaults than ancillary Locations. Adds a test to detect this case. Fixes #1660. --- pkg/ingress/controller/util.go | 2 +- pkg/ingress/controller/util_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/ingress/controller/util.go b/pkg/ingress/controller/util.go index c527ceaeb..97d170504 100644 --- a/pkg/ingress/controller/util.go +++ b/pkg/ingress/controller/util.go @@ -51,7 +51,7 @@ func mergeLocationAnnotations(loc *ingress.Location, anns map[string]interface{} loc.Denied = anns[DeniedKeyName].(error) } delete(anns, DeniedKeyName) - err := mergo.Map(loc, anns) + err := mergo.MapWithOverwrite(loc, anns) if err != nil { glog.Errorf("unexpected error merging extracted annotations in location type: %v", err) } diff --git a/pkg/ingress/controller/util_test.go b/pkg/ingress/controller/util_test.go index be3e382f6..6a09aef0e 100644 --- a/pkg/ingress/controller/util_test.go +++ b/pkg/ingress/controller/util_test.go @@ -82,6 +82,29 @@ func TestMergeLocationAnnotations(t *testing.T) { } } +func TestMergeLocationAnnotationsExisting(t *testing.T) { + loc := ingress.Location{ + IsDefBackend: true, + Proxy: proxy.Configuration{ReadTimeout: 60}, + } + annotations := map[string]interface{}{ + "Proxy": proxy.Configuration{ReadTimeout: 999}, + } + + mergeLocationAnnotations(&loc, annotations) + + // Existing value should be unmodified. + if got, want := loc.IsDefBackend, true; got != want { + t.Errorf("loc.IsDefBackend = %v, want %v", got, want) + } + + // New value from annotation should be updated. + if got, want := loc.Proxy.ReadTimeout, annotations["Proxy"].(proxy.Configuration).ReadTimeout; got != want { + t.Errorf("loc.Proxy.ReadTimeout = %v, want %v", got, want) + } +} + + func TestIntInSlice(t *testing.T) { fooTests := []struct { i int