use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class DefaultK8sNodeHandler method createBridge.
/**
* Creates a bridge with a given name on a given kubernetes node.
*
* @param k8sNode kubernetes node
* @param bridgeName bridge name
* @param devId device identifier
*/
private void createBridge(K8sNode k8sNode, String bridgeName, DeviceId devId) {
Device device = deviceService.getDevice(k8sNode.ovsdb());
List<ControllerInfo> controllers = k8sApiConfigService.apiConfigs().stream().map(c -> new ControllerInfo(c.ipAddress(), DEFAULT_OFPORT, DEFAULT_OF_PROTO)).collect(Collectors.toList());
String dpid = devId.toString().substring(DPID_BEGIN);
BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
bridgeConfig.addBridge(builder.build());
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeManager method createNode.
@Override
public void createNode(K8sNode node) {
checkNotNull(node, ERR_NULL_NODE);
K8sNode intNode;
K8sNode extNode;
K8sNode localNode;
K8sNode tunNode;
if (node.intgBridge() == null) {
String deviceIdStr = genDpid(deviceIdCounter.incrementAndGet());
checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
intNode = node.updateIntgBridge(DeviceId.deviceId(deviceIdStr));
checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
} else {
intNode = node;
checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
}
if (intNode.extBridge() == null) {
String deviceIdStr = genDpid(deviceIdCounter.incrementAndGet());
checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
extNode = intNode.updateExtBridge(DeviceId.deviceId(deviceIdStr));
checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
} else {
extNode = intNode;
checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
}
if (node.localBridge() == null) {
String deviceIdStr = genDpid(deviceIdCounter.incrementAndGet());
checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
localNode = extNode.updateLocalBridge(DeviceId.deviceId(deviceIdStr));
checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
} else {
localNode = extNode;
checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
}
if (node.mode() == NORMAL) {
if (node.tunBridge() == null) {
String deviceIdStr = genDpid(deviceIdCounter.incrementAndGet());
checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID);
tunNode = localNode.updateTunBridge(DeviceId.deviceId(deviceIdStr));
checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
} else {
tunNode = localNode;
checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
}
nodeStore.createNode(tunNode);
} else {
nodeStore.createNode(localNode);
}
log.info(String.format(MSG_NODE, extNode.hostname(), MSG_CREATED));
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class DefaultK8sApiConfigHandler method buildK8sNode.
private K8sNode buildK8sNode(Node node, K8sApiConfig config) {
String hostname = node.getMetadata().getName();
IpAddress managementIp = null;
IpAddress dataIp = null;
IpAddress nodeIp = null;
// normal mode: we use K8S node's internal IP as the management and data IP
if (config.mode() == PASSTHROUGH) {
HostNodesInfo info = config.infos().stream().filter(h -> h.nodes().contains(hostname)).findAny().orElse(null);
if (info == null) {
log.error("None of the nodes were found in the host nodes info mapping list");
} else {
managementIp = info.hostIp();
dataIp = info.hostIp();
}
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
nodeIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
} else {
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
managementIp = IpAddress.valueOf(nodeAddress.getAddress());
dataIp = IpAddress.valueOf(nodeAddress.getAddress());
nodeIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
}
String roleStr = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).findFirst().orElse(null);
K8sNode.Type nodeType = MINION;
if (roleStr != null) {
String role = roleStr.split("/")[1];
if (MASTER.name().equalsIgnoreCase(role)) {
nodeType = MASTER;
} else {
nodeType = MINION;
}
}
Map<String, String> annots = node.getMetadata().getAnnotations();
String extIntf = "";
String extGatewayIpStr = DEFAULT_GATEWAY_IP;
String extBridgeIpStr = DEFAULT_BRIDGE_IP;
if (config.mode() == PASSTHROUGH) {
extNetworkService.registerNetwork(config.extNetworkCidr());
extIntf = EXTERNAL_TO_ROUTER + "-" + config.clusterShortName();
IpAddress gatewayIp = extNetworkService.getGatewayIp(config.extNetworkCidr());
IpAddress bridgeIp = extNetworkService.allocateIp(config.extNetworkCidr());
if (gatewayIp != null) {
extGatewayIpStr = gatewayIp.toString();
}
if (bridgeIp != null) {
extBridgeIpStr = bridgeIp.toString();
}
} else {
extIntf = annots.get(EXT_INTF_NAME);
extGatewayIpStr = annots.get(EXT_GATEWAY_IP);
extBridgeIpStr = annots.get(EXT_BRIDGE_IP);
}
K8sNode.Builder builder = DefaultK8sNode.builder().clusterName(DEFAULT_CLUSTER_NAME).hostname(hostname).managementIp(managementIp).dataIp(dataIp).nodeInfo(new K8sNodeInfo(nodeIp, null)).extIntf(extIntf).type(nodeType).segmentId(config.segmentId()).state(PRE_ON_BOARD).mode(config.mode()).extBridgeIp(IpAddress.valueOf(extBridgeIpStr)).extGatewayIp(IpAddress.valueOf(extGatewayIpStr)).podCidr(node.getSpec().getPodCIDR());
if (config.dvr()) {
builder.extGatewayMac(MacAddress.valueOf(DEFAULT_EXTERNAL_GATEWAY_MAC));
}
return builder.build();
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class DefaultK8sApiConfigHandler method bootstrapK8sNodes.
private void bootstrapK8sNodes(K8sApiConfig config) {
KubernetesClient k8sClient = k8sClient(config);
if (k8sClient == null) {
log.warn("Failed to connect to kubernetes API server");
return;
}
for (Node node : k8sClient.nodes().list().getItems()) {
K8sNode k8sNode = buildK8sNode(node, config);
k8sNodeAdminService.createNode(k8sNode);
while (k8sNodeAdminService.node(k8sNode.hostname()).state() != ON_BOARDED) {
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during on-boarding state checking...");
}
if (k8sNodeAdminService.node(k8sNode.hostname()).state() == ON_BOARDED) {
break;
}
}
}
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeCodecTest method testK8sMinionNodeDecode.
/**
* Tests the kubernetes minion node decoding.
*
* @throws IOException IO exception
*/
@Test
public void testK8sMinionNodeDecode() throws IOException {
K8sNode node = getK8sNode("K8sMinionNode.json");
assertEquals("kubernetes", node.clusterName());
assertEquals("minion", node.hostname());
assertEquals("MINION", node.type().name());
assertEquals(100, node.segmentId());
assertEquals("172.16.130.4", node.managementIp().toString());
assertEquals("172.16.130.4", node.dataIp().toString());
assertEquals("172.16.130.5", node.nodeIp().toString());
assertEquals("of:00000000000000a1", node.intgBridge().toString());
assertEquals("eth1", node.extIntf());
assertEquals("172.16.130.5", node.extBridgeIp().toString());
assertEquals("172.16.130.1", node.extGatewayIp().toString());
assertEquals("FF:FF:FF:FF:FF:FF", node.extGatewayMac().toString());
}
Aggregations