From 830a4a9915db313c15fa5f1aeea326f8c0dc99fc Mon Sep 17 00:00:00 2001 From: TheAlain <43777839+asaintsever@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:04:48 +0100 Subject: [PATCH] Preserve existing annotations in submitted pod (#3) --- CHANGELOG.md | 4 ++++ VERSION_CHART | 2 +- VERSION_OVAI | 2 +- pkg/webhook/utils.go | 11 ++++------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b793c..e5085aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - [OVAI #2](https://github.com/asaintsever/open-vault-agent-injector/pull/2) - Add issuer on [vault k8s config](https://www.vaultproject.io/docs/auth/kubernetes#discovering-the-service-account-issuer) for Kubernetes 1.21+ +**Fixed** + +- [OVAI #3](https://github.com/asaintsever/open-vault-agent-injector/pull/3) - Preserve existing annotations in submitted pod + ## Release v1.0.0 - 2021-09-21 **Changed** diff --git a/VERSION_CHART b/VERSION_CHART index afaf360..7f20734 100644 --- a/VERSION_CHART +++ b/VERSION_CHART @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.0.1 \ No newline at end of file diff --git a/VERSION_OVAI b/VERSION_OVAI index afaf360..7f20734 100644 --- a/VERSION_OVAI +++ b/VERSION_OVAI @@ -1 +1 @@ -1.0.0 \ No newline at end of file +1.0.1 \ No newline at end of file diff --git a/pkg/webhook/utils.go b/pkg/webhook/utils.go index 05f0c6e..177be8d 100644 --- a/pkg/webhook/utils.go +++ b/pkg/webhook/utils.go @@ -119,18 +119,15 @@ Loop: func updateAnnotation(target map[string]string, added map[string]string) (patch []ctx.PatchOperation) { for key, value := range added { if target == nil || target[key] == "" { - target = map[string]string{} patch = append(patch, ctx.PatchOperation{ - Op: ctx.JsonPatchOpAdd, - Path: ctx.JsonPathAnnotations, - Value: map[string]string{ - key: value, - }, + Op: ctx.JsonPatchOpAdd, + Path: ctx.JsonPathAnnotations + "/" + strings.Replace(key, "/", "~1", -1), // as per http://jsonpatch.com/#json-pointer + Value: value, }) } else { patch = append(patch, ctx.PatchOperation{ Op: ctx.JsonPatchOpReplace, - Path: ctx.JsonPathAnnotations + "/" + key, + Path: ctx.JsonPathAnnotations + "/" + strings.Replace(key, "/", "~1", -1), // as per http://jsonpatch.com/#json-pointer Value: value, }) }