@Test public void successfullyScheduled() { AgentInstance agentInstance = createAgentInstance(INSTANCE_ID, INSTANCE_GROUP_ID); when(agentManagementService.findAgentInstance(INSTANCE_ID)).thenReturn(Optional.of(agentInstance)); V1Taint taint = createTaint("tolerated_taint_key", "NoSchedule", "tolerated_taint_value"); V1Node node = createNode(INSTANCE_ID, true, Collections.singletonList(taint)); when(indexer.getByKey(INSTANCE_ID)).thenReturn(node); ConstraintEvaluator.Result result = kubeConstraint.evaluate( createTaskRequest(TASK_ID), createVirtualMachineCurrentStateMock(INSTANCE_ID, Collections.emptyList(), Collections.emptyList()), taskTrackerState); assertThat(result.isSuccessful()).isTrue(); }
@Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!mesosConfiguration.isKubeApiServerIntegrationEnabled()) { return VALID; } Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } String instanceId = instanceOpt.get().getId(); V1Node node = kubeApiFacade.getNodeInformer().getIndexer().getByKey(instanceId); if (node == null) { return Failure.NODE_NOT_FOUND.toResult(); } Set<String> toleratedTaints = mesosConfiguration.getFenzoTaintTolerations(); if (toleratedTaints == null || toleratedTaints.isEmpty()) { return VALID; } if (node.getSpec() != null) { List<V1Taint> taints = node.getSpec().getTaints(); if (taints != null && !taints.isEmpty()) { for (V1Taint taint : taints) { String taintKey = taint.getKey(); if (!toleratedTaints.contains(taintKey)) { return Failure.TAINT_NOT_TOLERATED_IN_CONFIGURATION.toResult(); } } } } return VALID; }
KubeConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!mesosConfiguration.isKubeApiServerIntegrationEnabled()) { return VALID; } Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } String instanceId = instanceOpt.get().getId(); V1Node node = kubeApiFacade.getNodeInformer().getIndexer().getByKey(instanceId); if (node == null) { return Failure.NODE_NOT_FOUND.toResult(); } Set<String> toleratedTaints = mesosConfiguration.getFenzoTaintTolerations(); if (toleratedTaints == null || toleratedTaints.isEmpty()) { return VALID; } if (node.getSpec() != null) { List<V1Taint> taints = node.getSpec().getTaints(); if (taints != null && !taints.isEmpty()) { for (V1Taint taint : taints) { String taintKey = taint.getKey(); if (!toleratedTaints.contains(taintKey)) { return Failure.TAINT_NOT_TOLERATED_IN_CONFIGURATION.toResult(); } } } } return VALID; } }
KubeConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!mesosConfiguration.isKubeApiServerIntegrationEnabled()) { return VALID; } Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } String instanceId = instanceOpt.get().getId(); V1Node node = kubeApiFacade.getNodeInformer().getIndexer().getByKey(instanceId); if (node == null) { return Failure.NODE_NOT_FOUND.toResult(); } Set<String> toleratedTaints = mesosConfiguration.getFenzoTaintTolerations(); if (toleratedTaints == null || toleratedTaints.isEmpty()) { return VALID; } if (node.getSpec() != null) { List<V1Taint> taints = node.getSpec().getTaints(); if (taints != null && !taints.isEmpty()) { for (V1Taint taint : taints) { String taintKey = taint.getKey(); if (!toleratedTaints.contains(taintKey)) { return Failure.TAINT_NOT_TOLERATED_IN_CONFIGURATION.toResult(); } } } } return VALID; } @Inject  KubeConstraint(SchedulerConfiguration schedulerConfiguration,
                          MesosConfiguration mesosConfiguration,
                          AgentManagementService agentManagementService,
                          KubeApiFacade kubeApiFacade); }
KubeConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!mesosConfiguration.isKubeApiServerIntegrationEnabled()) { return VALID; } Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } String instanceId = instanceOpt.get().getId(); V1Node node = kubeApiFacade.getNodeInformer().getIndexer().getByKey(instanceId); if (node == null) { return Failure.NODE_NOT_FOUND.toResult(); } Set<String> toleratedTaints = mesosConfiguration.getFenzoTaintTolerations(); if (toleratedTaints == null || toleratedTaints.isEmpty()) { return VALID; } if (node.getSpec() != null) { List<V1Taint> taints = node.getSpec().getTaints(); if (taints != null && !taints.isEmpty()) { for (V1Taint taint : taints) { String taintKey = taint.getKey(); if (!toleratedTaints.contains(taintKey)) { return Failure.TAINT_NOT_TOLERATED_IN_CONFIGURATION.toResult(); } } } } return VALID; } @Inject  KubeConstraint(SchedulerConfiguration schedulerConfiguration,
                          MesosConfiguration mesosConfiguration,
                          AgentManagementService agentManagementService,
                          KubeApiFacade kubeApiFacade); static boolean isKubeConstraintReason(String reason); @Override String getName(); @Override void prepare(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); }
KubeConstraint implements SystemConstraint { @Override public Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) { if (!mesosConfiguration.isKubeApiServerIntegrationEnabled()) { return VALID; } Optional<AgentInstance> instanceOpt = SchedulerUtils.findInstance(agentManagementService, schedulerConfiguration.getInstanceAttributeName(), targetVM); if (!instanceOpt.isPresent()) { return Failure.INSTANCE_NOT_FOUND.toResult(); } String instanceId = instanceOpt.get().getId(); V1Node node = kubeApiFacade.getNodeInformer().getIndexer().getByKey(instanceId); if (node == null) { return Failure.NODE_NOT_FOUND.toResult(); } Set<String> toleratedTaints = mesosConfiguration.getFenzoTaintTolerations(); if (toleratedTaints == null || toleratedTaints.isEmpty()) { return VALID; } if (node.getSpec() != null) { List<V1Taint> taints = node.getSpec().getTaints(); if (taints != null && !taints.isEmpty()) { for (V1Taint taint : taints) { String taintKey = taint.getKey(); if (!toleratedTaints.contains(taintKey)) { return Failure.TAINT_NOT_TOLERATED_IN_CONFIGURATION.toResult(); } } } } return VALID; } @Inject  KubeConstraint(SchedulerConfiguration schedulerConfiguration,
                          MesosConfiguration mesosConfiguration,
                          AgentManagementService agentManagementService,
                          KubeApiFacade kubeApiFacade); static boolean isKubeConstraintReason(String reason); @Override String getName(); @Override void prepare(); @Override Result evaluate(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState); static final String NAME; static final String INSTANCE_NOT_FOUND_REASON; static final String NODE_NOT_FOUND_REASON; static final String NODE_NOT_READY_REASON; static final String TAINT_NOT_TOLERATED_IN_CONFIGURATION_REASON; }