Skip to content

Commit c39bac3

Browse files
committed
Don't crash when Amending hosts that don't yet have their provider attribute set
This can happen when merging hosts in providers. Wasn't triggered before, because those merges should be of completely disjoint sets, but we have some garbage in consul kv now that triggered this.
1 parent 68e973f commit c39bac3

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

host.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ func (h *Host) Amend(h2 *Host) {
181181
if h.Address == "" {
182182
h.Address = h2.Address
183183
}
184-
h.Attributes["herd_provider"] = append(h.Attributes["herd_provider"].([]string), h2.Attributes["herd_provider"].([]string)[0])
184+
if h2.Attributes["herd_provider"] != nil {
185+
if h.Attributes["herd_provider"] == nil {
186+
h.Attributes["herd_provider"] = make([]string, 0)
187+
}
188+
h.Attributes["herd_provider"] = append(h.Attributes["herd_provider"].([]string), h2.Attributes["herd_provider"].([]string)[0])
189+
}
185190
for attr, value := range h2.Attributes {
186191
if attr == "herd_provider" {
187192
continue

host_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ func TestHostDeserialization(t *testing.T) {
3636
t.Errorf("float attribute did not survive the json trip: %v", host.Attributes)
3737
}
3838
}
39+
40+
func TestAmendWithoutProvider(t *testing.T) {
41+
h := NewHost("test-host.herd.ci", "127.0.0.1", HostAttributes{})
42+
h2 := NewHost("test-host.herd.ci", "127.0.0.1", HostAttributes{})
43+
h.Amend(h2)
44+
}

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
const (
88
majorVersion = 0
99
minorVersion = 12
10-
patchVersion = 0
10+
patchVersion = 1
1111
)
1212

1313
func Version() string {

0 commit comments

Comments
 (0)