use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method cleanPhysicalInterfaces.
private void cleanPhysicalInterfaces(KubevirtNode node) {
Device device = deviceService.getDevice(node.ovsdb());
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
Set<String> bridgeNames = bridgeConfig.getBridges().stream().map(BridgeDescription::name).collect(Collectors.toSet());
Set<String> phyNetworkNames = node.phyIntfs().stream().map(pi -> BRIDGE_PREFIX + pi.network()).collect(Collectors.toSet());
// bridges are not defined in kubevirt node
for (String brName : bridgeNames) {
// physical bridges
if (brName.equals(INTEGRATION_BRIDGE) || brName.equals(TUNNEL_BRIDGE) || brName.startsWith(TENANT_BRIDGE_PREFIX)) {
continue;
}
if (!phyNetworkNames.contains(brName)) {
removePhysicalPatchPorts(node, brName.substring(NETWORK_BEGIN));
removePhysicalBridge(node, brName.substring(NETWORK_BEGIN));
log.info("Removing physical bridge {}...", brName);
}
}
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method setState.
/**
* Configures the kubernetes node with new state.
*
* @param node kubevirt node
* @param newState a new state
*/
private void setState(KubevirtNode node, KubevirtNodeState newState) {
if (node.state() == newState) {
return;
}
KubevirtNode updated = node.updateState(newState);
nodeAdminService.updateNode(updated);
log.info("Changed {} state: {}", node.hostname(), newState);
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtNodeUtil method buildKubevirtNode.
/**
* Returns the kubevirt node from the node.
*
* @param node a raw node object returned from a k8s client
* @return kubevirt node
*/
public static KubevirtNode buildKubevirtNode(Node node) {
String hostname = node.getMetadata().getName();
IpAddress managementIp = null;
IpAddress dataIp = null;
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
managementIp = IpAddress.valueOf(nodeAddress.getAddress());
dataIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
Set<String> rolesFull = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).collect(Collectors.toSet());
KubevirtNode.Type nodeType = WORKER;
for (String roleStr : rolesFull) {
String role = roleStr.split("/")[1];
if (MASTER.name().equalsIgnoreCase(role)) {
nodeType = MASTER;
break;
}
}
// start to parse kubernetes annotation
Map<String, String> annots = node.getMetadata().getAnnotations();
String physnetConfig = annots.get(PHYSNET_CONFIG_KEY);
String gatewayConfig = annots.get(GATEWAY_CONFIG_KEY);
String dataIpStr = annots.get(DATA_IP_KEY);
Set<KubevirtPhyInterface> phys = new HashSet<>();
String gatewayBridgeName = null;
try {
if (physnetConfig != null) {
JSONArray configJson = new JSONArray(physnetConfig);
for (int i = 0; i < configJson.length(); i++) {
JSONObject object = configJson.getJSONObject(i);
String network = object.getString(NETWORK_KEY);
String intf = object.getString(INTERFACE_KEY);
if (network != null && intf != null) {
String physBridgeId;
if (object.has(PHYS_BRIDGE_ID)) {
physBridgeId = object.getString(PHYS_BRIDGE_ID);
} else {
physBridgeId = genDpidFromName(network + intf + hostname);
log.trace("host {} physnet dpid for network {} intf {} is null so generate dpid {}", hostname, network, intf, physBridgeId);
}
phys.add(DefaultKubevirtPhyInterface.builder().network(network).intf(intf).physBridge(DeviceId.deviceId(physBridgeId)).build());
}
}
}
if (dataIpStr != null) {
dataIp = IpAddress.valueOf(dataIpStr);
}
if (gatewayConfig != null) {
JsonNode jsonNode = new ObjectMapper().readTree(gatewayConfig);
nodeType = GATEWAY;
gatewayBridgeName = jsonNode.get(GATEWAY_BRIDGE_NAME).asText();
}
} catch (JSONException | JsonProcessingException e) {
log.error("Failed to parse physnet config or gateway config object", e);
}
// if the node is taint with kubevirt.io key configured,
// we mark this node as OTHER type, and do not add it into the cluster
NodeSpec spec = node.getSpec();
if (spec.getTaints() != null) {
for (Taint taint : spec.getTaints()) {
String effect = taint.getEffect();
String key = taint.getKey();
String value = taint.getValue();
if (StringUtils.equals(effect, NO_SCHEDULE_EFFECT) && StringUtils.equals(key, KUBEVIRT_IO_KEY) && StringUtils.equals(value, DRAINING_VALUE)) {
nodeType = OTHER;
}
}
}
return DefaultKubevirtNode.builder().hostname(hostname).managementIp(managementIp).dataIp(dataIp).type(nodeType).state(KubevirtNodeState.ON_BOARDED).phyIntfs(phys).gatewayBridgeName(gatewayBridgeName).build();
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtNodeWebResource method healthz.
/**
* Returns the health check result.
*
* @return 200 OK with health check result, 404 not found
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("healthz")
public Response healthz() {
KubevirtApiConfigService configService = get(KubevirtApiConfigService.class);
KubevirtNodeService nodeService = get(KubevirtNodeService.class);
// TODO: we need to add more health check items
boolean allInit = true;
KubevirtApiConfig config = configService.apiConfig();
if (nodeService.nodes().size() == 0) {
allInit = false;
} else {
for (KubevirtNode node : nodeService.nodes()) {
if (node.state() != INIT) {
allInit = false;
}
}
}
String result = ERROR;
if (config != null && !allInit) {
result = OK;
}
ObjectNode jsonResult = mapper().createObjectNode();
jsonResult.put(API_CONFIG, result);
return ok(jsonResult).build();
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtNodeWebResource method initIncompleteNodes.
/**
* Initializes KubeVirt nodes which are in the stats other than COMPLETE.
*
* @return 200 OK with init result, 500 server error
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/incomplete")
public Response initIncompleteNodes() {
log.trace(String.format(MESSAGE_NODE, QUERY));
KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
service.nodes().stream().filter(n -> n.state() != KubevirtNodeState.COMPLETE).forEach(n -> {
KubevirtNode updated = n.updateState(INIT);
service.updateNode(updated);
});
return ok(mapper().createObjectNode()).build();
}
Aggregations