From 1e894b1a87c7b4e56741a066f1b1beaa28f74b54 Mon Sep 17 00:00:00 2001 From: afaque Date: Sun, 22 Oct 2023 12:58:50 +0530 Subject: [PATCH 1/2] Implementing a fix for multiple add-label/add-annotation commands Signed-off-by: Afaque Anwar Azad --- CHANGELOG.md | 3 +++ main.go | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f2ded1..00734ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - The `sensu.io/plugins/sensu-entity-manager/config/patch/annotations` and `sensu.io/plugins/sensu-entity-manager/config/patch/subscriptions` annotations are now supported. These were documented in the README previously but there were never implemented. +- Implemented a fix for --add-all attribute to enable support for multiple add-label commands + and multiple add-annotation commands + ### Changed - Q1 '21 handler maintenance: diff --git a/main.go b/main.go index d6e8679..5745006 100644 --- a/main.go +++ b/main.go @@ -304,11 +304,21 @@ func addSubscriptions(subs []string) { } func addLabels(labels []string) { - plugin.Labels = parseKvStringSlice(labels) + if len(plugin.Labels) == 0 { + plugin.Labels = parseKvStringSlice(labels) + } else { + newLabels := parseKvStringSlice(labels) + plugin.Labels = mergeMapStringStrings(plugin.Labels, newLabels) + } } func addAnnotations(annotations []string) { - plugin.Annotations = parseKvStringSlice(annotations) + if len(plugin.Annotations) == 0 { + plugin.Annotations = parseKvStringSlice(annotations) + } else { + newAnnotations = parseKvStringSlice(annotations) + plugin.Annotations = mergeMapStringStrings(plugin.Annotations, newAnnotations) + } } func patchEntity(event *types.Event) *EntityPatch { From 54a69bc209dff45ecd69c0d5555a0cc29fa2758a Mon Sep 17 00:00:00 2001 From: afaque Date: Mon, 23 Oct 2023 13:04:03 +0530 Subject: [PATCH 2/2] Implementing a fix for multiple add-label/add-annotation commands --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5745006..e5a0705 100644 --- a/main.go +++ b/main.go @@ -316,7 +316,7 @@ func addAnnotations(annotations []string) { if len(plugin.Annotations) == 0 { plugin.Annotations = parseKvStringSlice(annotations) } else { - newAnnotations = parseKvStringSlice(annotations) + newAnnotations := parseKvStringSlice(annotations) plugin.Annotations = mergeMapStringStrings(plugin.Annotations, newAnnotations) } }