Skip to content

Commit

Permalink
Fix adding labels and annotations to a resource that didn't have any
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Feb 12, 2018
1 parent 54aebed commit 2efcfc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 9 additions & 0 deletions kubernetes/patch_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ func diffStringMap(pathPrefix string, oldV, newV map[string]interface{}) PatchOp

pathPrefix = strings.TrimRight(pathPrefix, "/")

// If old value was empty, just create the object
if len(oldV) == 0 {
ops = append(ops, &AddOperation{
Path: pathPrefix,
Value: newV,
})
return ops
}

// This is suboptimal for adding whole new map from scratch
// or deleting the whole map, but it's actually intention.
// There may be some other map items managed outside of TF
Expand Down
11 changes: 5 additions & 6 deletions kubernetes/patch_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ func TestDiffStringMap(t *testing.T) {
},
ExpectedOps: []PatchOperation{
&AddOperation{
Path: "/parent/one",
Value: "111",
},
&AddOperation{
Path: "/parent/two",
Value: "222",
Path: "/parent",
Value: map[string]interface{}{
"one": "111",
"two": "222",
},
},
},
},
Expand Down

0 comments on commit 2efcfc9

Please sign in to comment.