فهرست منبع

Merge branch 'master' of github.com:porter-dev/porter into nico/implement-new-previous-logs

jnfrati 4 سال پیش
والد
کامیت
edd954bcbd

+ 22 - 2
api/server/handlers/kube_events/create.go

@@ -90,7 +90,9 @@ func (c *CreateKubeEventHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 
 	w.WriteHeader(http.StatusCreated)
 
-	if strings.ToLower(string(request.EventType)) == "critical" && strings.ToLower(request.ResourceType) == "pod" {
+	if strings.ToLower(string(request.EventType)) == "critical" &&
+		strings.ToLower(request.ResourceType) == "pod" &&
+		request.Message != "Unable to determine the root cause of the error" {
 		agent, err := c.GetAgent(r, cluster, request.Namespace)
 
 		if err != nil {
@@ -106,6 +108,19 @@ func (c *CreateKubeEventHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 	}
 }
 
+func mapKubeEventToMessage(event *types.CreateKubeEventRequest) string {
+	if strings.HasSuffix(event.Reason, "RunContainerError") {
+		if strings.Contains(event.Message, "exec:") {
+			return fmt.Sprintf("Application launch error: %s\n",
+				strings.Split(strings.SplitAfter(event.Message, "exec: ")[1], ": unknown")[0])
+		}
+	} else if strings.HasSuffix(event.Reason, "ImagePullBackOff") {
+		return "Deployment error: The application image could not be pulled from the registry"
+	}
+
+	return event.Message
+}
+
 func notifyPodCrashing(
 	config *config.Config,
 	agent *kubernetes.Agent,
@@ -113,6 +128,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
@@ -231,7 +251,7 @@ func notifyPodCrashing(
 			ClusterName: cluster.Name,
 			Name:        event.OwnerName,
 			Namespace:   event.Namespace,
-			Info:        fmt.Sprintf("%s:%s", event.Reason, event.Message),
+			Info:        mapKubeEventToMessage(event),
 			URL: fmt.Sprintf(
 				"%s/applications/%s/%s/%s?project_id=%d",
 				config.ServerConf.ServerURL,

+ 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{

+ 1 - 2
dashboard/src/shared/common.tsx

@@ -20,8 +20,7 @@ export const integrationList: any = {
     buttonText: "Add a Cluster",
   },
   repo: {
-    icon:
-      "https://3.bp.blogspot.com/-xhNpNJJyQhk/XIe4GY78RQI/AAAAAAAAItc/ouueFUj2Hqo5dntmnKqEaBJR4KQ4Q2K3ACK4BGAYYCw/s1600/logo%2Bgit%2Bicon.png",
+    icon: "https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png",
     label: "Git Repository",
     buttonText: "Link a Github Account",
   },

+ 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
 	// ------------------------------------------------------------------