From c0cf95fd9090d022777edebc5ce4e9546796e776 Mon Sep 17 00:00:00 2001 From: Alexandre Lamarre Date: Thu, 26 Oct 2023 13:57:33 -0400 Subject: [PATCH] when uninstalling set the alarm metadata to inactive --- .../pkg/alerting/alarms/v1/teardown.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/alerting/pkg/alerting/alarms/v1/teardown.go b/plugins/alerting/pkg/alerting/alarms/v1/teardown.go index da459eb1ab..60f491e4b3 100644 --- a/plugins/alerting/pkg/alerting/alarms/v1/teardown.go +++ b/plugins/alerting/pkg/alerting/alarms/v1/teardown.go @@ -2,6 +2,7 @@ package alarms import ( "context" + "errors" "fmt" "github.com/rancher/opni/pkg/alerting/drivers/cortex" @@ -22,13 +23,20 @@ func (p *AlarmServerComponent) teardownCondition( cleanup bool, ) (retErr error) { defer func() { - if cleanup && retErr == nil { - condStorage, err := p.conditionStorage.GetContext(ctx) - if err != nil { + condStorage, err := p.conditionStorage.GetContext(ctx) + if err != nil { + retErr = errors.Join(retErr, err) + } + if cleanup && retErr == nil { // user has requested a delete + if err := condStorage.Group(req.GroupId).Delete(ctx, id); err != nil { retErr = err - return } - if err := condStorage.Group(req.GroupId).Delete(ctx, id); err != nil { + } else if !cleanup && retErr == nil { // user has requested an uninstall without purging data + if req.Metadata == nil { + req.Metadata = map[string]string{} + } + req.Metadata[metadataInactiveAlarm] = "true" + if err := condStorage.Group(req.GroupId).Put(ctx, id, req); err != nil { retErr = err } }