-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNodes.jsx
291 lines (275 loc) · 7.67 KB
/
Nodes.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import {
Button,
Input,
Modal,
Select,
Menu,
Dropdown,
Switch,
message,
Typography,
} from "antd";
import { MoreOutlined } from "@ant-design/icons";
import { useCallback, useEffect, useState } from "react";
import { getNodes, getNodepools, sendUserRequest } from "../../utils/request";
import RSelect from "../Utils/RefreshableSelect";
import STable from "../Utils/SelectableTable";
import { renderDictCell, copy2clipboard } from "../../utils/utils";
import { Status } from "../Utils/Status";
import { useUserProfile } from "../../utils/hooks";
const { Option } = Select;
const { Search } = Input;
const { Paragraph, Link } = Typography;
// the Node panel
export default function Nodes() {
// table columns
const columns = [
{
title: "名称/IP地址/实例 ID",
dataIndex: "title",
render: (node) => {
return (
<div>
<div>{node.Name}</div>
<div>{node.IP}</div>
<div>{node.uid}</div>
</div>
);
},
},
{
title: "所属节点池",
dataIndex: "nodePool",
},
{
title: "角色/状态",
dataIndex: "role",
render: (node) => {
return (
<div>
{node.role}
<Status
status={node.condition.status === "True" ? "Ready" : "Unready"}
tips={node.condition.message}
/>
</div>
);
},
},
{
title: "节点配置",
dataIndex: "config",
render: (node) => renderDictCell(node),
},
{
title: "节点状态",
dataIndex: "status",
render: (node) => renderDictCell(node),
},
{
title: "Kubelet版本/Runtime版本/OS版本",
dataIndex: "version",
render: (node) => renderDictCell(node),
},
{
title: "创建时间",
dataIndex: "createTime",
},
{
title: "操作",
dataIndex: "operations",
render: ({ Autonomy, NodeName }) => (
<Dropdown
placement="bottomCenter"
overlay={
<Menu>
<Menu.Item key="1">
节点自治:
<Switch
size="small"
defaultChecked={Autonomy === "true"}
onChange={(checked) => {
sendUserRequest("/setNodeAutonomy", {
NodeName,
Autonomy: String(checked),
}).then((res) => {
// if autonomy set fail, refresh the whole table
if (res.status === "error") {
message.info("节点自治设置失败:刷新Node列表");
onRefresh();
} else {
message.info(
`节点自治设置成功: ${checked ? "ON" : "OFF"}`
);
}
});
}}
/>
</Menu.Item>
</Menu>
}
>
<MoreOutlined style={{ cursor: "pointer", width: "100%" }} />
</Dropdown>
),
},
];
// filtering
// for filter components
const [searchOption, setOption] = useState("title");
const [searchValue, setSearchVal] = useState("");
const [selectedNp, setNp] = useState("所有节点池");
const [allNodes, setAllNodes] = useState(null); // all nodes
const [nodes, setNodes] = useState(allNodes); // display nodes after filtering
const filterNodes = (searchContent, selectedNodePool) => {
let filterValue = searchContent ? searchContent : searchValue;
let filterNp = selectedNodePool ? selectedNodePool : selectedNp;
setNodes(
allNodes &&
allNodes
.filter(
// filter by search value
(node) =>
JSON.stringify(node[searchOption]).indexOf(filterValue) >= 0
// searchOptions could be an Object
)
.filter(
// filter by selected nodepool
(node) => filterNp === "所有节点池" || node.nodePool === filterNp
)
);
};
const onSearch = (searchContent) => {
filterNodes(searchContent);
};
// filter options
const options = [
{ content: "名称", dataIndex: "title" },
{ content: "标签", dataIndex: "tag" },
{ content: "标注", dataIndex: "annotations" },
];
// refresh the whole table and reset all filter options
// Note: this won't update nodepool options ( this may cause problems )
async function onRefresh() {
setNodes(null);
setSearchVal("");
setOption("title");
setNp("所有节点池");
return getNodes().then((nodes) => {
setAllNodes(nodes);
setNodes(nodes);
});
}
useEffect(() => {
onRefresh();
}, []);
const filterComponents = (
<div style={{ display: "inline-block" }}>
<Select
defaultValue={searchOption}
style={{ width: 80 }}
onChange={(val) => setOption(val)}
>
{options.map((e, i) => (
<Option key={i} value={e.dataIndex}>
{e.content}
</Option>
))}
</Select>
<Search
placeholder="input search text"
onSearch={onSearch}
style={{ width: 200 }}
value={searchValue}
onChange={(e) => setSearchVal(e.target.value)}
/>
<RSelect
handleRefresh={useCallback(async () => {
// add "所有节点池" in select options anyway
return getNodepools().then((nps) => {
return ["所有节点池", ...nps.map((np) => np.title)];
});
}, [])}
handleChange={(selectedNodePool) => {
setNp(selectedNodePool);
filterNodes(null, selectedNodePool);
}}
config={{
style: { width: 120 },
value: selectedNp,
}}
/>
</div>
);
// nodeaddscript modal
const [visible, setVisible] = useState(false);
const [userProfile] = useUserProfile();
const nodeAddScript = userProfile
? userProfile.spec.nodeAddScript
: "获取接入脚本失败,出现了一些问题";
const onCancel = () => {
setVisible(false);
};
return (
<div className="content">
<div>
<h2 style={{ display: "inline-block" }}>Node</h2>
<Button
type="default"
style={{ float: "right" }}
onClick={() => {
setVisible(true);
}}
>
添加已有节点
</Button>
{
// display help information for users has no nodes joined
allNodes && allNodes.length === 0 ? (
<Paragraph>
<blockquote>
不知道如何添加节点😕?参考
<Link
href="https://openyurt.io/docs/installation/openyurt-experience-center/web_console"
target="_blank"
>
文档➡️
</Link>
快速上手体验中心
</blockquote>
</Paragraph>
) : null
}
</div>
<Modal
visible={visible}
title="节点接入脚本"
onCancel={onCancel}
footer={[
<Button
key="copy"
onClick={() => {
copy2clipboard(nodeAddScript);
setVisible(false);
}}
>
复制并关闭
</Button>,
<Button key="close" type="primary" onClick={onCancel}>
关闭
</Button>,
]}
>
{nodeAddScript}
</Modal>
<STable
config={{
columns: columns,
data: nodes,
filterComponents: filterComponents,
onRefresh: onRefresh,
}}
/>
</div>
);
}