diff --git a/web/src/components/apps/HelmVMClusterManagement.jsx b/web/src/components/apps/HelmVMClusterManagement.jsx index 5d2ef854af..28d2c56860 100644 --- a/web/src/components/apps/HelmVMClusterManagement.jsx +++ b/web/src/components/apps/HelmVMClusterManagement.jsx @@ -1,6 +1,6 @@ import classNames from "classnames"; import dayjs from "dayjs"; -import React, { useEffect, useReducer } from "react"; +import React, { useEffect, useReducer, useState } from "react"; import Modal from "react-modal"; import { useQuery } from "react-query"; @@ -111,6 +111,8 @@ const HelmVMClusterManagement = () => { drainNodeSuccessful: false, } ); + const [selectedNodeTypes, setSelectedNodeTypes] = useState([]); + const [useStaticToken, setUseStaticToken] = useState(false); const { data: nodes, isLoading: nodesLoading } = useQuery({ queryKey: "helmVmNodes", @@ -309,37 +311,57 @@ const HelmVMClusterManagement = () => { }; const onAddNodeClick = () => { - setState( - { - displayAddNode: true, - }, - async () => { - await generateWorkerAddNodeCommand(); - } - ); - }; - - const onSelectNodeType = (event) => { - const value = event.currentTarget.value; - setState( - { - selectedNodeType: value, - }, - async () => { - if (state.selectedNodeType === "secondary") { - await generateWorkerAddNodeCommand(); - } else { - await generatePrimaryAddNodeCommand(); - } - } - ); + setState({ + displayAddNode: true, + }); }; const ackDeleteNodeError = () => { setState({ deleteNodeError: "" }); }; - const { displayAddNode, generateCommandErrMsg } = state; + const NODE_TYPES = [ + "controlplane", + "db", + "app", + "search", + "webserver", + "jobs", + ]; + + const determineDisabledState = (nodeType, selectedNodeTypes) => { + if (nodeType === "controlplane") { + const numControlPlanes = testData.nodes.reduce((acc, node) => { + if (node.labels.includes("controlplane")) { + acc++; + } + return acc; + }); + return numControlPlanes === 3; + } + if ( + (nodeType === "db" || nodeType === "search") && + selectedNodeTypes.includes("webserver") + ) { + return true; + } + return false; + }; + + const handleSelectNodeType = (e) => { + const nodeType = e.currentTarget.value; + let types = selectedNodeTypes; + + if (nodeType === "webserver") { + types = types.filter((type) => type !== "db" && type !== "search"); + } + + if (selectedNodeTypes.includes(nodeType)) { + setSelectedNodeTypes(types.filter((type) => type !== nodeType)); + } else { + setSelectedNodeTypes([...types, nodeType]); + } + }; if (nodesLoading) { return ( @@ -350,7 +372,7 @@ const HelmVMClusterManagement = () => { } return ( -
+
@@ -358,7 +380,7 @@ const HelmVMClusterManagement = () => {

Cluster Nodes

-

+

This section lists the nodes that are configured and shows the status/health of each. To add additional nodes to this cluster, click the "Add node" button at the bottom of this page. @@ -377,146 +399,113 @@ const HelmVMClusterManagement = () => { ))}

- {(nodes?.isHelmVMEnabled || testData.isHelmVMEnabled) && - Utilities.sessionRolesHasOneOf([rbacRoles.CLUSTER_ADMIN]) ? ( - !displayAddNode ? ( -
- -
- ) : ( -
-
-

- Add a node -

-
-
-
- - -
-
- - -
-
- {state.generating && ( -
- -
- )} - {!state.generating && state.command?.length > 0 ? ( - <> -

- Run this command on the node you wish to join the cluster -

- - Command has been copied to your clipboard - - } - > - {[state.command.join(" \\\n ")]} - - {state.expiry && ( - - {`Expires on ${dayjs(state.expiry).format( - "MMM Do YYYY, h:mm:ss a z" - )} UTC${(-1 * new Date().getTimezoneOffset()) / 60}`} - - )} - - ) : ( - <> - {generateCommandErrMsg && ( -
- - {generateCommandErrMsg} - -
- )} - - )} -
- ) - ) : null} + {Utilities.sessionRolesHasOneOf([rbacRoles.CLUSTER_ADMIN]) && ( +
+ +
+ )}
+ setState({ displayAddNode: false })} + contentLabel="Add Node" + className="Modal" + ariaHideApp={false} + > +
+
+

+ Add A Node +

+ setState({ displayAddNode: false })} + /> +
+

+ To add a node to this cluster, select the type of node you are + adding, and then select an installation method below. This screen + will automatically show the status when the node successfully joins + the cluster. +

+
+ {NODE_TYPES.map((nodeType) => ( +
+ + +
+ ))} +
+
+ Copied!} + > + {`curl http://node.something/join?token=abc&labels=${selectedNodeTypes.join( + "," + )}`} + +
+
+ setUseStaticToken(e.target.checked)} + /> + +
+ {/* buttons */} +
+ + +
+
+
{state.deleteNodeError && ( {node?.name}