Skip to content

Commit

Permalink
Merge pull request #322 from Smeb/fixup-mutate-annotations
Browse files Browse the repository at this point in the history
bugfix MutateAnnotations
  • Loading branch information
k8s-ci-robot authored Sep 23, 2023
2 parents 8f8d7f7 + c793289 commit 0211908
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion klient/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func MutateAnnotations(overrides map[string]string) DecodeOption {
annotations := obj.GetAnnotations()
if annotations == nil {
annotations = make(map[string]string)
obj.SetLabels(annotations)
obj.SetAnnotations(annotations)
}
for key, value := range overrides {
annotations[key] = value
Expand Down
21 changes: 21 additions & 0 deletions klient/decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

const (
testAnnotation = "annotationvalue"
testLabel = "labelvalue"
serviceAccountPrefix = "example-sa*"
)
Expand Down Expand Up @@ -255,6 +256,26 @@ func TestDecodersWithMutateFunc(t *testing.T) {
})
}

func TestMutateAnnotations(t *testing.T) {
testObj := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{"injected": "original"},
},
}
options := &decoder.Options{}
opt := decoder.MutateAnnotations(map[string]string{"injected": testAnnotation})
opt(options)
for _, fn := range options.MutateFuncs {
if err := fn(testObj); err != nil {
t.Fatal(err)
}
}

if testObj.Annotations["injected"] != testAnnotation {
t.Fatal("expected object annotation to be overwritten")
}
}

func TestHandlerFuncs(t *testing.T) {
handlerNS := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "handler-test"}}
res, err := resources.New(cfg)
Expand Down

0 comments on commit 0211908

Please sign in to comment.