Fix: correct the k8s node type, enhance k8s node check and list cmd

Change-Id: I6da0be677ab4372d7581aa23a6c45dfbfb27ead4
This commit is contained in:
Jian Li 2019-05-03 23:41:19 +09:00
parent 7970b7133f
commit 8a98804520
3 changed files with 32 additions and 11 deletions

View File

@ -27,9 +27,12 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Port; import org.onosproject.net.Port;
import org.onosproject.net.device.DeviceService; import org.onosproject.net.device.DeviceService;
import static org.onosproject.k8snode.api.Constants.EXTERNAL_BRIDGE;
import static org.onosproject.k8snode.api.Constants.GENEVE_TUNNEL; import static org.onosproject.k8snode.api.Constants.GENEVE_TUNNEL;
import static org.onosproject.k8snode.api.Constants.GRE_TUNNEL; import static org.onosproject.k8snode.api.Constants.GRE_TUNNEL;
import static org.onosproject.k8snode.api.Constants.INTEGRATION_BRIDGE; import static org.onosproject.k8snode.api.Constants.INTEGRATION_BRIDGE;
import static org.onosproject.k8snode.api.Constants.INTEGRATION_TO_EXTERNAL_BRIDGE;
import static org.onosproject.k8snode.api.Constants.PHYSICAL_EXTERNAL_BRIDGE;
import static org.onosproject.k8snode.api.Constants.VXLAN_TUNNEL; import static org.onosproject.k8snode.api.Constants.VXLAN_TUNNEL;
import static org.onosproject.net.AnnotationKeys.PORT_NAME; import static org.onosproject.net.AnnotationKeys.PORT_NAME;
@ -61,14 +64,16 @@ public class K8sNodeCheckCommand extends AbstractShellCommand {
} }
print("[Integration Bridge Status]"); print("[Integration Bridge Status]");
Device device = deviceService.getDevice(node.intgBridge()); Device intgBridge = deviceService.getDevice(node.intgBridge());
if (device != null) { if (intgBridge != null) {
print("%s %s=%s available=%s %s", print("%s %s=%s available=%s %s",
deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR, deviceService.isAvailable(intgBridge.id()) ? MSG_OK : MSG_ERROR,
INTEGRATION_BRIDGE, INTEGRATION_BRIDGE,
device.id(), intgBridge.id(),
deviceService.isAvailable(device.id()), deviceService.isAvailable(intgBridge.id()),
device.annotations()); intgBridge.annotations());
printPortState(deviceService, node.intgBridge(), INTEGRATION_BRIDGE);
printPortState(deviceService, node.intgBridge(), INTEGRATION_TO_EXTERNAL_BRIDGE);
if (node.dataIp() != null) { if (node.dataIp() != null) {
printPortState(deviceService, node.intgBridge(), VXLAN_TUNNEL); printPortState(deviceService, node.intgBridge(), VXLAN_TUNNEL);
printPortState(deviceService, node.intgBridge(), GRE_TUNNEL); printPortState(deviceService, node.intgBridge(), GRE_TUNNEL);
@ -80,6 +85,24 @@ public class K8sNodeCheckCommand extends AbstractShellCommand {
INTEGRATION_BRIDGE, INTEGRATION_BRIDGE,
node.intgBridge()); node.intgBridge());
} }
print("[External Bridge Status]");
Device extBridge = deviceService.getDevice(node.extBridge());
if (extBridge != null) {
print("%s %s=%s available=%s %s",
deviceService.isAvailable(extBridge.id()) ? MSG_OK : MSG_ERROR,
EXTERNAL_BRIDGE,
extBridge.id(),
deviceService.isAvailable(extBridge.id()),
extBridge.annotations());
printPortState(deviceService, node.extBridge(), EXTERNAL_BRIDGE);
printPortState(deviceService, node.extBridge(), PHYSICAL_EXTERNAL_BRIDGE);
} else {
print("%s %s=%s is not available",
MSG_ERROR,
EXTERNAL_BRIDGE,
node.extBridge());
}
} }
private void printPortState(DeviceService deviceService, private void printPortState(DeviceService deviceService,

View File

@ -37,7 +37,7 @@ import static org.onosproject.k8snode.util.K8sNodeUtil.prettyJson;
description = "Lists all nodes registered in kubernetes node service") description = "Lists all nodes registered in kubernetes node service")
public class K8sNodeListCommand extends AbstractShellCommand { public class K8sNodeListCommand extends AbstractShellCommand {
private static final String FORMAT = "%-20s%-15s%-24s%-24s%-20s%-15s"; private static final String FORMAT = "%-28s%-15s%-24s%-20s%-15s";
@Override @Override
protected void doExecute() { protected void doExecute() {
@ -48,13 +48,11 @@ public class K8sNodeListCommand extends AbstractShellCommand {
if (outputJson()) { if (outputJson()) {
print("%s", json(nodes)); print("%s", json(nodes));
} else { } else {
print(FORMAT, "Hostname", "Type", "Integration Bridge", print(FORMAT, "Hostname", "Type", "Management IP", "Data IP", "State");
"Management IP", "Data IP", "State");
for (K8sNode node : nodes) { for (K8sNode node : nodes) {
print(FORMAT, print(FORMAT,
node.hostname(), node.hostname(),
node.type(), node.type(),
node.intgBridge(),
node.managementIp(), node.managementIp(),
node.dataIp() != null ? node.dataIp() : "", node.dataIp() != null ? node.dataIp() : "",
node.state()); node.state());

View File

@ -145,7 +145,7 @@ public class DefaultK8sApiConfigHandler {
.filter(l -> l.contains(K8S_ROLE)) .filter(l -> l.contains(K8S_ROLE))
.findFirst().orElse(null); .findFirst().orElse(null);
K8sNode.Type nodeType = MASTER; K8sNode.Type nodeType = MINION;
if (roleStr != null) { if (roleStr != null) {
String role = roleStr.split("/")[1]; String role = roleStr.split("/")[1];