Selaa lähdekoodia

Merge pull request #455 from porter-dev/master

Merge pod deletion into staging
abelanger5 5 vuotta sitten
vanhempi
sitoutus
12c813f95f

+ 1 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricsSection.tsx

@@ -236,7 +236,7 @@ export default class MetricsSection extends Component<PropsType, StateType> {
 
 
     if (this.state.selectedMetric == "nginx:errors") {
     if (this.state.selectedMetric == "nginx:errors") {
       pods = [this.state.selectedIngress?.name];
       pods = [this.state.selectedIngress?.name];
-      namespace = this.state.selectedIngress?.namespace || "default"
+      namespace = this.state.selectedIngress?.namespace || "default";
       shouldsum = false;
       shouldsum = false;
     }
     }
 
 

+ 22 - 12
dashboard/src/main/home/cluster-dashboard/expanded-chart/status/ControllerTab.tsx

@@ -4,6 +4,7 @@ import api from "shared/api";
 import { Context } from "shared/Context";
 import { Context } from "shared/Context";
 
 
 import ResourceTab from "components/ResourceTab";
 import ResourceTab from "components/ResourceTab";
+import ConfirmOverlay from "components/ConfirmOverlay";
 
 
 type PropsType = {
 type PropsType = {
   controller: any;
   controller: any;
@@ -19,6 +20,7 @@ type StateType = {
   pods: any[];
   pods: any[];
   raw: any[];
   raw: any[];
   showTooltip: boolean[];
   showTooltip: boolean[];
+  podPendingDelete: any;
 };
 };
 
 
 // Controller tab in log section that displays list of pods on click.
 // Controller tab in log section that displays list of pods on click.
@@ -26,7 +28,8 @@ export default class ControllerTab extends Component<PropsType, StateType> {
   state = {
   state = {
     pods: [] as any[],
     pods: [] as any[],
     raw: [] as any[],
     raw: [] as any[],
-    showTooltip: [] as boolean[]
+    showTooltip: [] as boolean[],
+    podPendingDelete: null as any
   };
   };
 
 
   updatePods = () => {
   updatePods = () => {
@@ -64,7 +67,7 @@ export default class ControllerTab extends Component<PropsType, StateType> {
       )
       )
       .then(res => {
       .then(res => {
         let pods = res?.data?.map((pod: any) => {
         let pods = res?.data?.map((pod: any) => {
-          console.log(pod?.metadata?.namespace)
+          console.log(pod?.metadata?.namespace);
           return {
           return {
             namespace: pod?.metadata?.namespace,
             namespace: pod?.metadata?.namespace,
             name: pod?.metadata?.name,
             name: pod?.metadata?.name,
@@ -92,7 +95,7 @@ export default class ControllerTab extends Component<PropsType, StateType> {
         setCurrentError(JSON.stringify(err));
         setCurrentError(JSON.stringify(err));
         return;
         return;
       });
       });
-  }
+  };
 
 
   componentDidMount() {
   componentDidMount() {
     this.updatePods();
     this.updatePods();
@@ -156,10 +159,6 @@ export default class ControllerTab extends Component<PropsType, StateType> {
   };
   };
 
 
   handleDeletePod = (pod: any) => {
   handleDeletePod = (pod: any) => {
-    console.log("clusterId", this.context.currentCluster.id);
-    console.log("name", pod.metadata?.name);
-    console.log("namespace", pod.metadata?.namespace);
-    console.log("id", this.context.currentProject.id);
     api
     api
       .deletePod(
       .deletePod(
         "<token>",
         "<token>",
@@ -169,27 +168,29 @@ export default class ControllerTab extends Component<PropsType, StateType> {
         {
         {
           name: pod.metadata?.name,
           name: pod.metadata?.name,
           namespace: pod.metadata?.namespace,
           namespace: pod.metadata?.namespace,
-          id: this.context.currentProject.id,
+          id: this.context.currentProject.id
         }
         }
       )
       )
       .then(res => {
       .then(res => {
         this.updatePods();
         this.updatePods();
+        this.setState({ podPendingDelete: null });
       })
       })
       .catch(err => {
       .catch(err => {
         this.context.setCurrentError(JSON.stringify(err));
         this.context.setCurrentError(JSON.stringify(err));
+        this.setState({ podPendingDelete: null });
       });
       });
-  }
+  };
 
 
   renderDeleteButton = (pod: any) => {
   renderDeleteButton = (pod: any) => {
     return (
     return (
-      <CloseIcon 
+      <CloseIcon
         className="material-icons-outlined"
         className="material-icons-outlined"
-        onClick={() => this.handleDeletePod(pod)}
+        onClick={() => this.setState({ podPendingDelete: pod })}
       >
       >
         close
         close
       </CloseIcon>
       </CloseIcon>
     );
     );
-  }
+  };
 
 
   render() {
   render() {
     let { controller, selectedPod, isLast, selectPod, isFirst } = this.props;
     let { controller, selectedPod, isLast, selectPod, isFirst } = this.props;
@@ -211,6 +212,9 @@ export default class ControllerTab extends Component<PropsType, StateType> {
       >
       >
         {this.state.raw.map((pod, i) => {
         {this.state.raw.map((pod, i) => {
           let status = this.getPodStatus(pod.status);
           let status = this.getPodStatus(pod.status);
+          if (i === 2) {
+            status = "failed";
+          }
           return (
           return (
             <Tab
             <Tab
               key={pod.metadata?.name}
               key={pod.metadata?.name}
@@ -251,6 +255,12 @@ export default class ControllerTab extends Component<PropsType, StateType> {
             </Tab>
             </Tab>
           );
           );
         })}
         })}
+        <ConfirmOverlay
+          message="Are you sure you want to delete this pod?"
+          show={this.state.podPendingDelete}
+          onYes={() => this.handleDeletePod(this.state.podPendingDelete)}
+          onNo={() => this.setState({ podPendingDelete: null })}
+        />
       </ResourceTab>
       </ResourceTab>
     );
     );
   }
   }

+ 3 - 5
dashboard/src/main/home/navbar/Navbar.tsx

@@ -44,15 +44,13 @@ export default class Navbar extends Component<PropsType, StateType> {
     return (
     return (
       <StyledNavbar>
       <StyledNavbar>
         <Feedback currentView={this.props.currentView} />
         <Feedback currentView={this.props.currentView} />
-        <NavButton 
-          selected={this.state.showDropdown} 
+        <NavButton
+          selected={this.state.showDropdown}
           onClick={() =>
           onClick={() =>
             this.setState({ showDropdown: !this.state.showDropdown })
             this.setState({ showDropdown: !this.state.showDropdown })
           }
           }
         >
         >
-          <I className="material-icons-outlined">
-            account_circle
-          </I>
+          <I className="material-icons-outlined">account_circle</I>
           {this.context.user.email}
           {this.context.user.email}
           {this.renderSettingsDropdown()}
           {this.renderSettingsDropdown()}
         </NavButton>
         </NavButton>

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

@@ -221,12 +221,12 @@ const deleteInvite = baseApi<{}, { id: number; invId: number }>(
 );
 );
 
 
 const deletePod = baseApi<
 const deletePod = baseApi<
-{
-  cluster_id: number;
-},
-{ name: string; namespace: string; id: number }
+  {
+    cluster_id: number;
+  },
+  { name: string; namespace: string; id: number }
 >("DELETE", pathParams => {
 >("DELETE", pathParams => {
-  return `/api/projects/${pathParams.id}/k8s/pods`;
+  return `/api/projects/${pathParams.id}/k8s/pods/${pathParams.namespace}/${pathParams.name}`;
 });
 });
 
 
 const deleteProject = baseApi<{}, { id: number }>("DELETE", pathParams => {
 const deleteProject = baseApi<{}, { id: number }>("DELETE", pathParams => {

+ 3 - 1
dashboard/src/shared/baseApi.tsx

@@ -31,7 +31,9 @@ export const baseApi = <T extends {}, S = {}>(
         }
         }
       });
       });
     } else if (requestType === "DELETE") {
     } else if (requestType === "DELETE") {
-      return axios.delete(endpointString, params);
+      return axios.delete(
+        endpointString + "?" + qs.stringify(params, { arrayFormat: "repeat" })
+      );
     } else {
     } else {
       return axios.get(endpointString, {
       return axios.get(endpointString, {
         params,
         params,

+ 1 - 1
server/router/router.go

@@ -1184,7 +1184,7 @@ func New(a *api.App) *chi.Mux {
 
 
 		r.Method(
 		r.Method(
 			"DELETE",
 			"DELETE",
-			"/projects/{project_id}/k8s/pods",
+			"/projects/{project_id}/k8s/pods/{namespace}/{name}",
 			auth.DoesUserHaveProjectAccess(
 			auth.DoesUserHaveProjectAccess(
 				auth.DoesUserHaveClusterAccess(
 				auth.DoesUserHaveClusterAccess(
 					requestlog.NewHandler(a.HandleDeletePod, l),
 					requestlog.NewHandler(a.HandleDeletePod, l),