Search in sources :

Example 1 with Taint

use of io.fabric8.kubernetes.api.model.Taint in project titus-control-plane by Netflix.

the class TitusNodePredicatesTest method checkBadTaint.

@Test
public void checkBadTaint() {
    Node node = new Node();
    NodeSpec nodeSpec = new NodeSpec();
    Taint taint1 = new Taint();
    taint1.setEffect("NoSchedule");
    taint1.setKey("node.titus.netflix.com/tier");
    taint1.setValue("Critical");
    taint1.setTimeAdded(Fabric8IOUtil.formatTimestamp(OffsetDateTime.now().minusMinutes(20)));
    Taint taint2 = new Taint();
    taint2.setEffect("NoSchedule");
    taint2.setKey("node.kubernetes.io/unreachable");
    taint2.setTimeAdded(Fabric8IOUtil.formatTimestamp(OffsetDateTime.now().minusMinutes(10)));
    nodeSpec.setTaints(Arrays.asList(taint1, taint2));
    node.setSpec(nodeSpec);
    Pattern pattern = Pattern.compile(".*unreachable");
    boolean isBadTaint = NodePredicates.hasBadTaint(node, pattern::matcher, 300);
    assertThat(isBadTaint).isTrue();
    nodeSpec.setTaints(Collections.singletonList(taint1));
    isBadTaint = NodePredicates.hasBadTaint(node, pattern::matcher, 300);
    assertThat(isBadTaint).isFalse();
}
Also used : Pattern(java.util.regex.Pattern) Node(io.fabric8.kubernetes.api.model.Node) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) Taint(io.fabric8.kubernetes.api.model.Taint) Test(org.junit.Test)

Example 2 with Taint

use of io.fabric8.kubernetes.api.model.Taint in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaProvisioner method applyProfile.

void applyProfile(KafkaInstanceConfiguration profile, int replicas) throws IOException {
    if (!this.clusters.isEmpty()) {
        // until install applies the profile, we can only do one deployment at a time
        throw new IllegalStateException("the provisioner cannot currently manage multiple clusters");
    }
    // remove any previous taints.
    removeTaintsOnNodes();
    List<Node> workers = cluster.getWorkerNodes();
    // divide the nodes by their zones, then sort them by their cpu availability then mark however brokers needed for the taint
    validateClusterForBrokers(replicas, profile.getKafka().isColocateWithZookeeper(), workers.stream());
    // convert the profile into simple configmap values
    ConfigMap override = toConfigMap(profile);
    var configMapClient = cluster.kubeClient().client().configMaps().inNamespace(FleetShardOperatorManager.OPERATOR_NS);
    configMapClient.createOrReplace(override);
    // restart the operator deployment
    RollableScalableResource<Deployment> fleetshardOperatorDeployment = cluster.kubeClient().client().apps().deployments().inNamespace(FleetShardOperatorManager.OPERATOR_NS).withName(FleetShardOperatorManager.OPERATOR_NAME);
    LOGGER.info("Restarting fleetshard operatior with configuration {}", Serialization.asYaml(override));
    fleetshardOperatorDeployment.scale(0, true);
    fleetshardOperatorDeployment.scale(1, true);
// fleetshardOperatorDeployment.waitUntilReady(30, TimeUnit.SECONDS);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Node(io.fabric8.kubernetes.api.model.Node) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 3 with Taint

use of io.fabric8.kubernetes.api.model.Taint 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();
}
Also used : Address(org.xbill.DNS.Address) StringUtils(org.apache.commons.lang.StringUtils) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) JSONException(org.json.JSONException) WORKER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER) JSONObject(org.json.JSONObject) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OTHER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.OTHER) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Node(io.fabric8.kubernetes.api.model.Node) IpAddress(org.onlab.packet.IpAddress) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Tools.get(org.onlab.util.Tools.get) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Taint(io.fabric8.kubernetes.api.model.Taint) BridgeName(org.onosproject.net.behaviour.BridgeName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) MASTER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.MASTER) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) List(java.util.List) SONA_PROJECT_DOMAIN(org.onosproject.kubevirtnode.api.Constants.SONA_PROJECT_DOMAIN) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) KubevirtNodeState(org.onosproject.kubevirtnode.api.KubevirtNodeState) DeviceId(org.onosproject.net.DeviceId) JSONArray(org.json.JSONArray) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Taint(io.fabric8.kubernetes.api.model.Taint) Taint(io.fabric8.kubernetes.api.model.Taint) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) JSONObject(org.json.JSONObject) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) IpAddress(org.onlab.packet.IpAddress) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Example 4 with Taint

use of io.fabric8.kubernetes.api.model.Taint in project titus-control-plane by Netflix.

the class TestDataFactory method addNodeTaint.

public static void addNodeTaint(Node node, String key, String value, String effect) {
    List<Taint> taints = Evaluators.getOrDefault(node.getSpec().getTaints(), Collections.emptyList());
    Taint taint = new TaintBuilder().withKey(key).withValue(value).withEffect(effect).build();
    taints.add(taint);
    node.getSpec().setTaints(taints);
}
Also used : TaintBuilder(io.fabric8.kubernetes.api.model.TaintBuilder) Taint(io.fabric8.kubernetes.api.model.Taint)

Aggregations

Node (io.fabric8.kubernetes.api.model.Node)3 Taint (io.fabric8.kubernetes.api.model.Taint)3 NodeSpec (io.fabric8.kubernetes.api.model.NodeSpec)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 NodeAddress (io.fabric8.kubernetes.api.model.NodeAddress)1 TaintBuilder (io.fabric8.kubernetes.api.model.TaintBuilder)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Dictionary (java.util.Dictionary)1 HashSet (java.util.HashSet)1 List (java.util.List)1