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;
}
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));
}
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));
}
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));
}
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));
}
Aggregations