Przeglądaj źródła

Merge branch 'master' into dev

Mohammed Nafees 3 lat temu
rodzic
commit
73e0154f2e

+ 42 - 41
dashboard/src/main/home/cluster-dashboard/expanded-chart/logs-section/LogsSection.tsx

@@ -138,13 +138,13 @@ const LogsSection: React.FC<Props> = ({
     selectedDate
   );
 
-  useEffect(() => {
+  const refreshPodLogsValues = async () => {
     if (overridingPodName) {
       return;
     }
 
-    var filters = {
-      namespace: currentChart?.namespace,
+    const filters = {
+      namespace: currentChart.namespace,
       revision: initData.revision ?? currentChart.version.toString(),
       match_prefix: currentChart.name,
     };
@@ -161,48 +161,49 @@ const LogsSection: React.FC<Props> = ({
       }
     }
 
-    api
-      .getLogPodValues("<TOKEN>", filters, {
-        project_id: currentProject.id,
-        cluster_id: currentCluster.id,
-      })
-      .then((res: any) => {
-        // 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;
-              });
+    const logPodValuesResp = await api.getLogPodValues("<TOKEN>", filters, {
+      project_id: currentProject.id,
+      cluster_id: currentCluster.id,
+    });
 
-              setPodFilterOpts(podList);
+    if (logPodValuesResp.data?.length != 0) {
+      setPodFilterOpts(_.uniq(logPodValuesResp.data ?? []));
 
-              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]);
-          }
+      // only set pod filter if the current pod is not found in the resulting data
+      if (!logPodValuesResp.data?.includes(podFilter)) {
+        setPodFilter(logPodValuesResp.data[0]);
+      }
+
+      return;
+    }
+
+    // if we're on the latest revision and no pod values were returned, query for all release pods
+    if (currentChart.info.status == "deployed") {
+      const allReleasePodsResp = await api.getAllReleasePods(
+        "<TOKEN>",
+        {},
+        {
+          id: currentProject.id,
+          name: currentChart.name,
+          namespace: currentChart.namespace,
+          cluster_id: currentCluster.id,
         }
+      );
+
+      let podList = allReleasePodsResp.data.map((pod: any) => {
+        return pod.metadata.name;
       });
+
+      setPodFilterOpts(podList);
+
+      if (!podFilter || !podList.includes(podFilter)) {
+        setPodFilter(podList[0]);
+      }
+    }
+  };
+
+  useEffect(() => {
+    refreshPodLogsValues();
   }, [initData]);
 
   useEffect(() => {

+ 1 - 1
dashboard/src/shared/api.tsx

@@ -1086,7 +1086,7 @@ const getAllReleasePods = baseApi<
     cluster_id: number;
   }
 >("GET", (pathParams) => {
-  let { id, name, cluster_id, namespace } = pathParams;
+  const { id, name, cluster_id, namespace } = pathParams;
 
   return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/pods/all`;
 });