Search in sources :

Example 36 with K8sNode

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());
}
Also used : DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) K8sApiConfigService(org.onosproject.k8snode.api.K8sApiConfigService) CoreService(org.onosproject.core.CoreService) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) VXLAN(org.onosproject.k8snode.api.Constants.VXLAN) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) K8sNodeState(org.onosproject.k8snode.api.K8sNodeState) NodeId(org.onosproject.cluster.NodeId) INCOMPLETE(org.onosproject.k8snode.api.K8sNodeState.INCOMPLETE) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) AUTO_RECOVERY(org.onosproject.k8snode.impl.OsgiPropertyConstants.AUTO_RECOVERY) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) K8sNodeUtil.getBooleanProperty(org.onosproject.k8snode.util.K8sNodeUtil.getBooleanProperty) K8sNodeUtil.isOvsdbConnected(org.onosproject.k8snode.util.K8sNodeUtil.isOvsdbConnected) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) DeviceEvent(org.onosproject.net.device.DeviceEvent) AUTO_RECOVERY_DEFAULT(org.onosproject.k8snode.impl.OsgiPropertyConstants.AUTO_RECOVERY_DEFAULT) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) GENEVE(org.onosproject.k8snode.api.Constants.GENEVE) GRE(org.onosproject.k8snode.api.Constants.GRE) Tools(org.onlab.util.Tools) K8sNodeUtil.getOvsdbClient(org.onosproject.k8snode.util.K8sNodeUtil.getOvsdbClient) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ComponentContext(org.osgi.service.component.ComponentContext) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) TunnelKey(org.onosproject.net.behaviour.TunnelKey) Component(org.osgi.service.component.annotations.Component) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) DEVICE_CREATED(org.onosproject.k8snode.api.K8sNodeState.DEVICE_CREATED) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) COMPLETE(org.onosproject.k8snode.api.K8sNodeState.COMPLETE) K8sNode(org.onosproject.k8snode.api.K8sNode) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) K8sNodeHandler(org.onosproject.k8snode.api.K8sNodeHandler) PatchDescription(org.onosproject.net.behaviour.PatchDescription) APP_ID(org.onosproject.k8snode.api.K8sNodeService.APP_ID) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) OVSDB_PORT(org.onosproject.k8snode.impl.OsgiPropertyConstants.OVSDB_PORT) Modified(org.osgi.service.component.annotations.Modified) OVSDB_PORT_NUM_DEFAULT(org.onosproject.k8snode.impl.OsgiPropertyConstants.OVSDB_PORT_NUM_DEFAULT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) NORMAL(org.onosproject.k8snode.api.K8sApiConfig.Mode.NORMAL) Device(org.onosproject.net.Device) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 37 with K8sNode

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));
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode)

Example 38 with K8sNode

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();
}
Also used : K8sNodeInfo(org.onosproject.k8snode.api.K8sNodeInfo) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultK8sNode(org.onosproject.k8snode.api.DefaultK8sNode) HostNodesInfo(org.onosproject.k8snode.api.HostNodesInfo) IpAddress(org.onlab.packet.IpAddress) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress)

Example 39 with K8sNode

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;
            }
        }
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultK8sNode(org.onosproject.k8snode.api.DefaultK8sNode) K8sNode(org.onosproject.k8snode.api.K8sNode) Node(io.fabric8.kubernetes.api.model.Node) DefaultK8sNode(org.onosproject.k8snode.api.DefaultK8sNode)

Example 40 with K8sNode

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());
}
Also used : K8sNodeJsonMatcher.matchesK8sNode(org.onosproject.k8snode.codec.K8sNodeJsonMatcher.matchesK8sNode) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultK8sNode(org.onosproject.k8snode.api.DefaultK8sNode) Test(org.junit.Test)

Aggregations

K8sNode (org.onosproject.k8snode.api.K8sNode)40 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 DefaultK8sNode (org.onosproject.k8snode.api.DefaultK8sNode)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 DeviceId (org.onosproject.net.DeviceId)6 Objects (java.util.Objects)5 Set (java.util.Set)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)5 Consumes (javax.ws.rs.Consumes)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5 LeadershipService (org.onosproject.cluster.LeadershipService)5