Search in sources :

Example 1 with LabelSelectorRequirement

use of io.fabric8.kubernetes.api.model.LabelSelectorRequirement in project fabric8-maven-plugin by fabric8io.

the class KubernetesClientUtil method withSelector.

public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, Logger log) {
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
    Map<String, String> matchLabels = selector.getMatchLabels();
    if (matchLabels != null && !matchLabels.isEmpty()) {
        answer = answer.withLabels(matchLabels);
    }
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    if (matchExpressions != null) {
        for (LabelSelectorRequirement expression : matchExpressions) {
            String key = expression.getKey();
            List<String> values = expression.getValues();
            if (Strings.isNullOrBlank(key)) {
                log.warn("Ignoring empty key in selector expression %s", expression);
                continue;
            }
            if (values == null || values.isEmpty()) {
                log.warn("Ignoring empty values in selector expression %s", expression);
                continue;
            }
            String[] valuesArray = values.toArray(new String[values.size()]);
            String operator = expression.getOperator();
            switch(operator) {
                case "In":
                    answer = answer.withLabelIn(key, valuesArray);
                    break;
                case "NotIn":
                    answer = answer.withLabelNotIn(key, valuesArray);
                    break;
                default:
                    log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression);
            }
        }
    }
    return answer;
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) Watch(io.fabric8.kubernetes.client.Watch) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) Watcher(io.fabric8.kubernetes.client.Watcher) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement)

Example 2 with LabelSelectorRequirement

use of io.fabric8.kubernetes.api.model.LabelSelectorRequirement in project fabric8 by fabric8io.

the class DeploymentConfigPodsAssert method pods.

public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    DeploymentConfigSpec spec = this.actual.getSpec();
    Integer replicas = spec.getReplicas();
    Map<String, String> matchLabels = spec.getSelector();
    List<LabelSelectorRequirement> matchExpressions = new ArrayList<>();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "DeploymentConfig " + KubernetesHelper.getName(actual));
}
Also used : ArrayList(java.util.ArrayList) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec)

Example 3 with LabelSelectorRequirement

use of io.fabric8.kubernetes.api.model.LabelSelectorRequirement in project fabric8 by fabric8io.

the class ReplicationControllerPodsAssert method pods.

public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    ReplicationControllerSpec spec = this.actual.getSpec();
    Integer replicas = spec.getReplicas();
    Map<String, String> matchLabels = spec.getSelector();
    List<LabelSelectorRequirement> matchExpressions = new ArrayList<>();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "ReplicationController " + KubernetesHelper.getName(actual));
}
Also used : ArrayList(java.util.ArrayList) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 4 with LabelSelectorRequirement

use of io.fabric8.kubernetes.api.model.LabelSelectorRequirement in project fabric8 by fabric8io.

the class ServicePodsAssert method pods.

@Override
public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    ServiceSpec spec = this.actual.getSpec();
    int replicas = 1;
    LabelSelector selector = null;
    Map<String, String> matchLabels = spec.getSelector();
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "Service " + KubernetesHelper.getName(actual));
}
Also used : ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement)

Example 5 with LabelSelectorRequirement

use of io.fabric8.kubernetes.api.model.LabelSelectorRequirement in project fabric8 by fabric8io.

the class ReplicaSetPodsAssert method pods.

@Override
public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    ReplicaSetSpec spec = this.actual.getSpec();
    Integer replicas = spec.getReplicas();
    LabelSelector selector = spec.getSelector();
    Map<String, String> matchLabels = selector.getMatchLabels();
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "ReplicaSet " + KubernetesHelper.getName(actual));
}
Also used : ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement)

Aggregations

LabelSelectorRequirement (io.fabric8.kubernetes.api.model.LabelSelectorRequirement)6 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)3 ArrayList (java.util.ArrayList)2 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)1 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)1 DeploymentSpec (io.fabric8.kubernetes.api.model.extensions.DeploymentSpec)1 ReplicaSetSpec (io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec)1 Watch (io.fabric8.kubernetes.client.Watch)1 Watcher (io.fabric8.kubernetes.client.Watcher)1 LogWatch (io.fabric8.kubernetes.client.dsl.LogWatch)1 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)1