Skip to content

Commit

Permalink
feat: add K8sGPT Custom Resource name as a prefix to slack messages (#…
Browse files Browse the repository at this point in the history
…221)

* feat: add K8sGPT Custom Resource name as a prefix to slack messages

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>

* feat: minor fix

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>

---------

Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>
Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
  • Loading branch information
Aris Boutselis and arbreezy committed Sep 17, 2023
1 parent f302b0c commit 5b5fd2f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/sinks/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var _ ISink = (*SlackSink)(nil)

type SlackSink struct {
Endpoint string
K8sGPT string
Client Client
}

Expand All @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 5b5fd2f

Please sign in to comment.