Skip to content

Commit

Permalink
NGP-6694: fix notification channel provisioning (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
alavrovinfb authored Aug 20, 2020
1 parent dcf49b7 commit f7faf90
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,17 @@ func (r *ReconcileGrafanaNotificationChannel) reconcileNotificationChannels(requ
}

var status GrafanaResponse
// if knownHash is empty channel wasn't added before
// if channel is not in knownNotificationChannels, but already presents in Grafana (in case if operator was restarted) corner case
// API creating call will return response code 500.
// Try to check if channel already present then create/updated existing channel
if knownHash == "" {
rawJson := GrafanaChannel{}
if err := json.Unmarshal(processed, &rawJson); err != nil {
return reconcile.Result{}, err
}
if _, err := grafanaClient.GetNotificationChannel(*rawJson.UID); err != nil {
status, err = grafanaClient.CreateNotificationChannel(processed)
} else {
status, err = grafanaClient.UpdateNotificationChannel(processed, notificationchannel.Status.UID)
}
} else {
status, err = grafanaClient.UpdateNotificationChannel(processed, notificationchannel.Status.UID)
// Create or Update notification channel
rawJson := GrafanaChannel{}
if err := json.Unmarshal(processed, &rawJson); err != nil {
return reconcile.Result{}, err
}

if _, err = grafanaClient.GetNotificationChannel(*rawJson.UID); err != nil {
status, err = grafanaClient.CreateNotificationChannel(processed)
} else {
status, err = grafanaClient.UpdateNotificationChannel(processed, *rawJson.UID)
}
if err != nil {
log.Info(fmt.Sprintf("cannot submit notificationchannel %v/%v", notificationchannel.Namespace, notificationchannel.Name))
r.manageError(&notificationchannel, err)
Expand Down

0 comments on commit f7faf90

Please sign in to comment.