Prechádzať zdrojové kódy

Merge branch 'belanger/agent-v3-integration' of github.com-meehawk:porter-dev/porter into belanger/agent-v3-integration

Soham Parekh 3 rokov pred
rodič
commit
f73b24591c

+ 27 - 19
api/server/handlers/cluster/install_agent.go

@@ -97,24 +97,8 @@ func (c *InstallAgentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		return
 	}
 
-	lokiValues := make(map[string]interface{})
-
-	// case on whether a node with porter.run/workload-kind=monitoring exists. If it does, we place loki in that node group.
-	if nodes, err := nodes.ListNodesByLabels(k8sAgent.Clientset, "porter.run/workload-kind=monitoring"); err == nil && len(nodes) >= 1 {
-		lokiValues = map[string]interface{}{
-			"nodeSelector": map[string]interface{}{
-				"porter.run/workload-kind": "monitoring",
-			},
-			"tolerations": []map[string]interface{}{
-				{
-					"key":      "porter.run/workload-kind",
-					"operator": "Equal",
-					"value":    "monitoring",
-					"effect":   "NoSchedule",
-				},
-			},
-		}
-	}
+	nodes, err := nodes.ListNodesByLabels(k8sAgent.Clientset, "porter.run/workload-kind=monitoring")
+	hasMonitoringNodes := err == nil && len(nodes) >= 1
 
 	porterAgentValues := map[string]interface{}{
 		"agent": map[string]interface{}{
@@ -124,7 +108,31 @@ func (c *InstallAgentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 			"clusterID":   fmt.Sprintf("%d", cluster.ID),
 			"projectID":   fmt.Sprintf("%d", proj.ID),
 		},
-		"loki": lokiValues,
+		"loki": map[string]interface{}{},
+	}
+
+	// case on whether a node with porter.run/workload-kind=monitoring exists. If it does, we place loki in that node group.
+	if hasMonitoringNodes {
+		sharedNS := map[string]interface{}{
+			"porter.run/workload-kind": "monitoring",
+		}
+
+		sharedTolerations := []map[string]interface{}{
+			{
+				"key":      "porter.run/workload-kind",
+				"operator": "Equal",
+				"value":    "monitoring",
+				"effect":   "NoSchedule",
+			},
+		}
+
+		porterAgentValues["loki"] = map[string]interface{}{
+			"nodeSelector": sharedNS,
+			"tolerations":  sharedTolerations,
+		}
+
+		porterAgentValues["nodeSelector"] = sharedNS
+		porterAgentValues["tolerations"] = sharedTolerations
 	}
 
 	conf := &helm.InstallChartConfig{

+ 13 - 8
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -604,6 +604,13 @@ const ExpandedChart: React.FC<Props> = (props) => {
   };
 
   const setRevision = (chart: ChartType, isCurrent?: boolean) => {
+    // if we've set the revision, we also override the revision in log data
+    let newLogData = logData;
+
+    newLogData.revision = `${chart.version}`;
+
+    setLogData(newLogData);
+
     setIsPreview(!isCurrent);
     getChartData(chart);
   };
@@ -739,7 +746,7 @@ const ExpandedChart: React.FC<Props> = (props) => {
   useEffect(() => {
     if (logData.revision) {
       api
-        .getRevisions(
+        .getChart(
           "<token>",
           {},
           {
@@ -747,15 +754,11 @@ const ExpandedChart: React.FC<Props> = (props) => {
             namespace: props.currentChart.namespace,
             cluster_id: currentCluster.id,
             name: props.currentChart.name,
+            revision: parseInt(logData.revision),
           }
         )
         .then((res) => {
-          const chart = res.data?.find(
-            (revision: ChartType) =>
-              revision.version.toString() === logData.revision
-          );
-
-          setCurrentChart(chart ?? props.currentChart);
+          setCurrentChart(res.data || props.currentChart);
         })
         .catch(console.log);
 
@@ -983,7 +986,9 @@ const ExpandedChart: React.FC<Props> = (props) => {
                             onTabChange={(newTab) => {
                               if (newTab !== "logs") {
                                 setOverrideCurrentTab("");
-                                setLogData({});
+                                setLogData({
+                                  revision: `${currentChart.version}`,
+                                });
                               }
                             }}
                           />