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.
This commit is contained in:
parent
b68feb9c59
commit
552b84041e
2 changed files with 24 additions and 1 deletions
|
@ -51,7 +51,7 @@ func mergeLocationAnnotations(loc *ingress.Location, anns map[string]interface{}
|
||||||
loc.Denied = anns[DeniedKeyName].(error)
|
loc.Denied = anns[DeniedKeyName].(error)
|
||||||
}
|
}
|
||||||
delete(anns, DeniedKeyName)
|
delete(anns, DeniedKeyName)
|
||||||
err := mergo.Map(loc, anns)
|
err := mergo.MapWithOverwrite(loc, anns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("unexpected error merging extracted annotations in location type: %v", err)
|
glog.Errorf("unexpected error merging extracted annotations in location type: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestIntInSlice(t *testing.T) {
|
||||||
fooTests := []struct {
|
fooTests := []struct {
|
||||||
i int
|
i int
|
||||||
|
|
Loading…
Reference in a new issue