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.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.GRE_TUNNEL;
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.net.AnnotationKeys.PORT_NAME;
@ -61,14 +64,16 @@ public class K8sNodeCheckCommand extends AbstractShellCommand {
}
print("[Integration Bridge Status]");
Device device = deviceService.getDevice(node.intgBridge());
if (device != null) {
Device intgBridge = deviceService.getDevice(node.intgBridge());
if (intgBridge != null) {
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,
device.id(),
deviceService.isAvailable(device.id()),
device.annotations());
intgBridge.id(),
deviceService.isAvailable(intgBridge.id()),
intgBridge.annotations());
printPortState(deviceService, node.intgBridge(), INTEGRATION_BRIDGE);
printPortState(deviceService, node.intgBridge(), INTEGRATION_TO_EXTERNAL_BRIDGE);
if (node.dataIp() != null) {
printPortState(deviceService, node.intgBridge(), VXLAN_TUNNEL);
printPortState(deviceService, node.intgBridge(), GRE_TUNNEL);
@ -80,6 +85,24 @@ public class K8sNodeCheckCommand extends AbstractShellCommand {
INTEGRATION_BRIDGE,
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,

View File

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

View File

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