From 5b5fd2f4be06f87d466517eec99d40b58bb64877 Mon Sep 17 00:00:00 2001 From: Aris Boutselis Date: Sun, 17 Sep 2023 14:47:54 +0100 Subject: [PATCH] feat: add K8sGPT Custom Resource name as a prefix to slack messages (#221) * feat: add K8sGPT Custom Resource name as a prefix to slack messages Signed-off-by: Aris Boutselis * feat: minor fix Signed-off-by: Aris Boutselis --------- Signed-off-by: Aris Boutselis Co-authored-by: Aris Boutselis --- pkg/sinks/slack.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/sinks/slack.go b/pkg/sinks/slack.go index 210389f3..1449bf8b 100644 --- a/pkg/sinks/slack.go +++ b/pkg/sinks/slack.go @@ -13,6 +13,7 @@ var _ ISink = (*SlackSink)(nil) type SlackSink struct { Endpoint string + K8sGPT string Client Client } @@ -28,9 +29,9 @@ type Attachment struct { Title string `json:"title"` } -func buildSlackMessage(kind, name, details string) SlackMessage { +func buildSlackMessage(kind, name, details, k8sgptCR string) SlackMessage { return SlackMessage{ - Text: fmt.Sprintf(">*K8sGPT analysis of the %s %s*", kind, name), + Text: fmt.Sprintf(">*[%s] K8sGPT analysis of the %s %s*", k8sgptCR, kind, name), Attachments: []Attachment{ Attachment{ Type: "mrkdwn", @@ -45,10 +46,12 @@ func buildSlackMessage(kind, name, details string) SlackMessage { func (s *SlackSink) Configure(config v1alpha1.K8sGPT, c Client) { s.Endpoint = config.Spec.Sink.Endpoint s.Client = c + // take the name of the K8sGPT Custom Resource + s.K8sGPT = config.Name } func (s *SlackSink) Emit(results v1alpha1.ResultSpec) error { - message := buildSlackMessage(results.Kind, results.Name, results.Details) + message := buildSlackMessage(results.Kind, results.Name, results.Details, s.K8sGPT) payload, err := json.Marshal(message) if err != nil { return err