Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get wrong node ip on k8s #100

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ResultDTO<Void> addNode(@RequestBody SaveNodeRequest req) throws IOExcept
NodeInfoVO k8sNodeInfoVO = items.stream().filter(new Predicate<Node>() {
@Override
public boolean test(Node node) {
String nodeIp = node.getStatus().getAddresses().get(0).getAddress();
String nodeIp = getNodeIp(node);
return ip.equals(nodeIp);
}
}).map(new Function<Node, NodeInfoVO>() {
Expand Down Expand Up @@ -149,7 +149,7 @@ public ResultDTO<List<NodeInfoVO>> listNode(Integer clusterId) {
Map<String, Node> nodeMap = items.stream().collect(Collectors.toMap(new Function<Node, String>() {
@Override
public String apply(Node node) {
return node.getStatus().getAddresses().get(0).getAddress();
return getNodeIp(node);
}
}, node -> node));
// 从数据库查出当前集群绑定的节点
Expand Down Expand Up @@ -187,7 +187,7 @@ public String apply(ClusterNodeEntity clusterNodeEntity) {
List<NodeInfoVO> result = items.stream().filter(new Predicate<Node>() {
@Override
public boolean test(Node node) {
String ip = node.getStatus().getAddresses().get(0).getAddress();
String ip = getNodeIp(node);
// 过滤出未绑定的节点
return !clusterIpSets.contains(ip);
}
Expand All @@ -205,13 +205,8 @@ private NodeInfoVO getNodeInfoVO(Node e) {
int cpu = e.getStatus().getCapacity().get("cpu").getNumericalAmount().intValue();
long memory = e.getStatus().getCapacity().get("memory").getNumericalAmount().longValue();
long storage = e.getStatus().getCapacity().get("ephemeral-storage").getNumericalAmount().longValue();
List<NodeAddress> nodeAddresses = e.getStatus().getAddresses();
String ip = nodeAddresses.stream().filter(n -> {
return n.getType().equals("InternalIP");
}).findFirst().get().getAddress();
String hostname = nodeAddresses.stream().filter(n -> {
return n.getType().equals("Hostname");
}).findFirst().get().getAddress();
String ip = getNodeIp(e);
String hostname = getNodeHostname(e);
String architecture = e.getStatus().getNodeInfo().getArchitecture();
String containerRuntimeVersion = e.getStatus().getNodeInfo().getContainerRuntimeVersion();
String kubeletVersion = e.getStatus().getNodeInfo().getKubeletVersion();
Expand All @@ -232,4 +227,16 @@ private NodeInfoVO getNodeInfoVO(Node e) {
.build();
return nodeInfoVO;
}

private String getNodeIp(Node e) {
return e.getStatus().getAddresses().stream().filter(n -> {
return n.getType().equals("InternalIP");
}).findFirst().get().getAddress();
}

private String getNodeHostname(Node e) {
return e.getStatus().getAddresses().stream().filter(n -> {
return n.getType().equals("Hostname");
}).findFirst().get().getAddress();
}
}