Skip to content

Commit

Permalink
Fix warning log in slack event notifier (#895)
Browse files Browse the repository at this point in the history
* Format warning log in slack.go correctly

* change how we log slack email warning
  • Loading branch information
ptnapoleon authored Aug 7, 2024
1 parent f4c5261 commit 9947edb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions eventnotifier/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (n *Notifier) notifyForDisruption(dis *v1beta1.Disruption, event corev1.Eve
return nil
}

if err := n.sendMessageToUserChannel(dis, slackMsg, logger); err != nil {
if err := n.sendMessageToUserChannel(slackMsg, logger); err != nil {
return fmt.Errorf("slack notifier: %w", err)
}

Expand All @@ -169,7 +169,7 @@ func (n *Notifier) notifyForDisruptionCron(disruptionCron *v1beta1.DisruptionCro
}
}

if err := n.sendMessageToUserChannel(disruptionCron, slackMsg, logger); err != nil {
if err := n.sendMessageToUserChannel(slackMsg, logger); err != nil {
return fmt.Errorf("slack notifier: %w", err)
}

Expand All @@ -178,12 +178,10 @@ func (n *Notifier) notifyForDisruptionCron(disruptionCron *v1beta1.DisruptionCro
return nil
}

func (n *Notifier) sendMessageToUserChannel(obj client.Object, slackMsg slackMessage, logger *zap.SugaredLogger) error {
objKind := obj.GetObjectKind().GroupVersionKind().Kind

func (n *Notifier) sendMessageToUserChannel(slackMsg slackMessage, logger *zap.SugaredLogger) error {
emailAddr, err := mail.ParseAddress(slackMsg.UserInfo.Username)
if err != nil {
logger.Warnw("invalid user info email in %s %s: %w", objKind, obj.GetName(), err)
logger.Infow("username could not be parsed as an email address", "err", err, "username", slackMsg.UserInfo.Username)

return nil
}
Expand Down

0 comments on commit 9947edb

Please sign in to comment.