Procházet zdrojové kódy

add database option to turn off notifs per cluster

Alexander Belanger před 4 roky
rodič
revize
c6bd47d49a

+ 5 - 0
api/server/handlers/kube_events/create.go

@@ -113,6 +113,11 @@ func notifyPodCrashing(
 	cluster *models.Cluster,
 	event *types.CreateKubeEventRequest,
 ) error {
+	// if cluster has notifications turned off, don't alert
+	if cluster.NotificationsDisabled {
+		return nil
+	}
+
 	// attempt to get a matching Porter release to get the notification configuration
 	var conf *models.NotificationConfig
 	var notifConfig *types.NotificationConfig

+ 6 - 2
api/server/handlers/release/ugprade.go

@@ -157,7 +157,9 @@ func (c *UpgradeReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 		notifyOpts.Status = slack.StatusHelmFailed
 		notifyOpts.Info = upgradeErr.Error()
 
-		notifier.Notify(notifyOpts)
+		if !cluster.NotificationsDisabled {
+			notifier.Notify(notifyOpts)
+		}
 
 		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
 			upgradeErr,
@@ -171,7 +173,9 @@ func (c *UpgradeReleaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 		notifyOpts.Status = slack.StatusHelmDeployed
 		notifyOpts.Version = helmRelease.Version
 
-		notifier.Notify(notifyOpts)
+		if !cluster.NotificationsDisabled {
+			notifier.Notify(notifyOpts)
+		}
 	}
 
 	// update the github actions env if the release exists and is built from source

+ 6 - 2
api/server/handlers/release/upgrade_webhook.go

@@ -172,7 +172,9 @@ func (c *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		notifyOpts.Status = slack.StatusHelmFailed
 		notifyOpts.Info = err.Error()
 
-		notifier.Notify(notifyOpts)
+		if !cluster.NotificationsDisabled {
+			notifier.Notify(notifyOpts)
+		}
 
 		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
 			err,
@@ -186,7 +188,9 @@ func (c *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		notifyOpts.Status = slack.StatusHelmDeployed
 		notifyOpts.Version = rel.Version
 
-		notifier.Notify(notifyOpts)
+		if !cluster.NotificationsDisabled {
+			notifier.Notify(notifyOpts)
+		}
 	}
 
 	c.Config().AnalyticsClient.Track(analytics.ApplicationDeploymentWebhookTrack(&analytics.ApplicationDeploymentWebhookTrackOpts{

+ 2 - 0
internal/models/cluster.go

@@ -51,6 +51,8 @@ type Cluster struct {
 
 	InfraID uint `json:"infra_id"`
 
+	NotificationsDisabled bool `json:"notifications_disabled"`
+
 	// ------------------------------------------------------------------
 	// All fields below this line are encrypted before storage
 	// ------------------------------------------------------------------