Skip to content

Commit

Permalink
Merge pull request #776 from SchSeba/fix_render
Browse files Browse the repository at this point in the history
Fix merge annotation function
  • Loading branch information
zeeke authored Sep 20, 2024
2 parents 60c6404 + 6aedb8c commit e2d0611
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/apply/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func mergeAnnotations(current, updated *uns.Unstructured) {
for k, v := range updatedAnnotations {
curAnnotations[k] = v
}
if len(curAnnotations) > 1 {
if len(curAnnotations) > 0 {
updated.SetAnnotations(curAnnotations)
}
}
Expand All @@ -238,7 +238,7 @@ func mergeLabels(current, updated *uns.Unstructured) {
for k, v := range updatedLabels {
curLabels[k] = v
}
if len(curLabels) > 1 {
if len(curLabels) > 0 {
updated.SetLabels(curLabels)
}
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/apply/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ metadata:
}))
}

func TestMergeOne(t *testing.T) {
g := NewGomegaWithT(t)

cur := UnstructuredFromYaml(t, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d1
labels:
label-c: cur
annotations:
annotation-c: cur`)

upd := UnstructuredFromYaml(t, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d1`)

// this mutates updated
err := MergeObjectForUpdate(cur, upd)
g.Expect(err).NotTo(HaveOccurred())

g.Expect(upd.GetLabels()).To(Equal(map[string]string{
"label-c": "cur",
}))

g.Expect(upd.GetAnnotations()).To(Equal(map[string]string{
"annotation-c": "cur",
}))
}

func TestMergeNilCur(t *testing.T) {
g := NewGomegaWithT(t)

Expand Down

0 comments on commit e2d0611

Please sign in to comment.