Explorar o código

Merge branch 'belanger/add-pod-query-for-logging' into dev

Alexander Belanger %!s(int64=3) %!d(string=hai) anos
pai
achega
6103d166ee

+ 55 - 16
dashboard/src/main/home/cluster-dashboard/expanded-chart/logs-section/LogsSection.tsx

@@ -143,25 +143,64 @@ const LogsSection: React.FC<Props> = ({
       return;
       return;
     }
     }
 
 
+    var filters = {
+      namespace: currentChart?.namespace,
+      revision: initData.revision ?? currentChart.version.toString(),
+      match_prefix: currentChart.name,
+    };
+
+    // if the current chart is set to a blue-green deployment, we don't set a revision, but instead
+    // we set the match prefix to the current chart and the active image tag.
+    if (currentChart.config.bluegreen?.enabled) {
+      filters.revision = null;
+
+      if (currentChart?.name.includes("web")) {
+        filters.match_prefix = `${currentChart.name}-${currentChart.config.bluegreen?.activeImageTag}`;
+      } else {
+        filters.match_prefix = `${currentChart.name}-web-${currentChart.config.bluegreen?.activeImageTag}`;
+      }
+    }
+
     api
     api
-      .getLogPodValues(
-        "<TOKEN>",
-        {
-          namespace: currentChart?.namespace,
-          revision: initData.revision ?? currentChart.version.toString(),
-          match_prefix: currentChart.name,
-        },
-        {
-          project_id: currentProject.id,
-          cluster_id: currentCluster.id,
-        }
-      )
+      .getLogPodValues("<TOKEN>", filters, {
+        project_id: currentProject.id,
+        cluster_id: currentCluster.id,
+      })
       .then((res: any) => {
       .then((res: any) => {
-        setPodFilterOpts(_.uniq(res.data ?? []));
+        // if we're on the latest revision and no pod values are returned, query for all release pods
+        if (
+          currentChart.info.status == "deployed" &&
+          (!res.data || res.data?.length == 0)
+        ) {
+          api
+            .getAllReleasePods(
+              "<TOKEN>",
+              {},
+              {
+                id: currentProject.id,
+                name: currentChart.name,
+                namespace: currentChart.namespace,
+                cluster_id: currentCluster.id,
+              }
+            )
+            .then((res: any) => {
+              let podList = res.data.map((pod: any) => {
+                return pod.metadata.name;
+              });
+
+              setPodFilterOpts(podList);
 
 
-        // only set pod filter if the current pod is not found in the resulting data
-        if (!res.data?.includes(podFilter)) {
-          setPodFilter(res.data[0]);
+              if (!podFilter || !podList.includes(podFilter)) {
+                setPodFilter(podList[0]);
+              }
+            });
+        } else {
+          setPodFilterOpts(_.uniq(res.data ?? []));
+
+          // only set pod filter if the current pod is not found in the resulting data
+          if (!res.data?.includes(podFilter)) {
+            setPodFilter(res.data[0]);
+          }
         }
         }
       });
       });
   }, [initData]);
   }, [initData]);

+ 15 - 0
dashboard/src/shared/api.tsx

@@ -1077,6 +1077,20 @@ const getMatchingPods = baseApi<
   return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/pods`;
   return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/pods`;
 });
 });
 
 
+const getAllReleasePods = baseApi<
+  {},
+  {
+    id: number;
+    name: string;
+    namespace: string;
+    cluster_id: number;
+  }
+>("GET", (pathParams) => {
+  let { id, name, cluster_id, namespace } = pathParams;
+
+  return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/pods/all`;
+});
+
 const getMetrics = baseApi<
 const getMetrics = baseApi<
   {
   {
     metric: string;
     metric: string;
@@ -2470,6 +2484,7 @@ export default {
   getJobPods,
   getJobPods,
   getPodByName,
   getPodByName,
   getMatchingPods,
   getMatchingPods,
+  getAllReleasePods,
   getMetrics,
   getMetrics,
   getNamespaces,
   getNamespaces,
   getNGINXIngresses,
   getNGINXIngresses,