class 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 public  KubeConstraint(SchedulerConfiguration schedulerConfiguration,
                          MesosConfiguration mesosConfiguration,
                          AgentManagementService agentManagementService,
                          KubeApiFacade kubeApiFacade);

}