Search in sources :

Example 1 with V1TopologySpreadConstraint

use of io.kubernetes.client.openapi.models.V1TopologySpreadConstraint in project titus-control-plane by Netflix.

the class DefaultTopologyFactory method buildZoneTopologySpreadConstraints.

private Optional<V1TopologySpreadConstraint> buildZoneTopologySpreadConstraints(Job<?> job) {
    boolean zoneHard = Boolean.parseBoolean(JobFunctions.findHardConstraint(job, JobConstraints.ZONE_BALANCE).orElse("false"));
    boolean zoneSoft = Boolean.parseBoolean(JobFunctions.findSoftConstraint(job, JobConstraints.ZONE_BALANCE).orElse("false"));
    if (!zoneHard && !zoneSoft) {
        return Optional.empty();
    }
    V1TopologySpreadConstraint zoneConstraint = new V1TopologySpreadConstraint().topologyKey(KubeConstants.NODE_LABEL_ZONE).labelSelector(new V1LabelSelector().matchLabels(Collections.singletonMap(KubeConstants.POD_LABEL_JOB_ID, job.getId()))).maxSkew(1);
    if (zoneHard) {
        zoneConstraint.whenUnsatisfiable("DoNotSchedule");
    } else {
        zoneConstraint.whenUnsatisfiable("ScheduleAnyway");
    }
    return Optional.of(zoneConstraint);
}
Also used : V1TopologySpreadConstraint(io.kubernetes.client.openapi.models.V1TopologySpreadConstraint) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Example 2 with V1TopologySpreadConstraint

use of io.kubernetes.client.openapi.models.V1TopologySpreadConstraint in project titus-control-plane by Netflix.

the class DefaultTopologyFactory method buildJobTopologySpreadConstraints.

private Optional<V1TopologySpreadConstraint> buildJobTopologySpreadConstraints(Job<?> job) {
    if (!isJobSpreadingEnabled(job)) {
        return Optional.empty();
    }
    int maxSkew = getJobMaxSkew(job);
    if (maxSkew <= 0) {
        return Optional.empty();
    }
    V1TopologySpreadConstraint nodeConstraint = new V1TopologySpreadConstraint().topologyKey(KubeConstants.NODE_LABEL_MACHINE_ID).labelSelector(new V1LabelSelector().matchLabels(Collections.singletonMap(KubeConstants.POD_LABEL_JOB_ID, job.getId()))).maxSkew(maxSkew).whenUnsatisfiable("ScheduleAnyway");
    return Optional.of(nodeConstraint);
}
Also used : V1TopologySpreadConstraint(io.kubernetes.client.openapi.models.V1TopologySpreadConstraint) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector) V1TopologySpreadConstraint(io.kubernetes.client.openapi.models.V1TopologySpreadConstraint)

Aggregations

V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)2 V1TopologySpreadConstraint (io.kubernetes.client.openapi.models.V1TopologySpreadConstraint)2