Java Code Examples for io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable#withLabelIn()

The following examples show how to use io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable#withLabelIn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeploymentRollingUpdater.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
protected PodList listSelectedPods(Deployment obj) {
  FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = pods().inNamespace(namespace);
  if (obj.getSpec().getSelector().getMatchLabels() != null) {
    podLister.withLabels(obj.getSpec().getSelector().getMatchLabels());
  }
  if (obj.getSpec().getSelector().getMatchExpressions() != null) {
    for (LabelSelectorRequirement req : obj.getSpec().getSelector().getMatchExpressions()) {
      switch (req.getOperator()) {
        case "In":
          podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "NotIn":
          podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "DoesNotExist":
          podLister.withoutLabel(req.getKey());
          break;
        case "Exists":
          podLister.withLabel(req.getKey());
          break;
      }
    }
  }
  return podLister.list();
}
 
Example 2
Source File: StatefulSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
protected PodList listSelectedPods(StatefulSet obj) {
  FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = pods().inNamespace(namespace);
  if (obj.getSpec().getSelector().getMatchLabels() != null) {
    podLister.withLabels(obj.getSpec().getSelector().getMatchLabels());
  }
  if (obj.getSpec().getSelector().getMatchExpressions() != null) {
    for (LabelSelectorRequirement req : obj.getSpec().getSelector().getMatchExpressions()) {
      switch (req.getOperator()) {
        case "In":
          podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "NotIn":
          podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "DoesNotExist":
          podLister.withoutLabel(req.getKey());
          break;
        case "Exists":
          podLister.withLabel(req.getKey());
          break;
      }
    }
  }
  return podLister.list();
}
 
Example 3
Source File: ReplicaSetRollingUpdater.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
protected PodList listSelectedPods(ReplicaSet obj) {
  FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = pods().inNamespace(namespace);
  if (obj.getSpec().getSelector().getMatchLabels() != null) {
    podLister.withLabels(obj.getSpec().getSelector().getMatchLabels());
  }
  if (obj.getSpec().getSelector().getMatchExpressions() != null) {
    for (LabelSelectorRequirement req : obj.getSpec().getSelector().getMatchExpressions()) {
      switch (req.getOperator()) {
        case "In":
          podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "NotIn":
          podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
          break;
        case "DoesNotExist":
          podLister.withoutLabel(req.getKey());
          break;
        case "Exists":
          podLister.withLabel(req.getKey());
          break;
      }
    }
  }
  return podLister.list();
}
 
Example 4
Source File: KubernetesClientUtil.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger 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 (StringUtils.isBlank(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;
}
 
Example 5
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, KitLogger 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 (StringUtils.isBlank(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;
}
 
Example 6
Source File: Pods.java    From dekorate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link PodList} that match the specified {@link Deployment}.
 * @param deployment The {@link Deployment}
 */
protected PodList map(Deployment deployment) {
  FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = client.pods()
      .inNamespace(deployment.getMetadata().getNamespace());
  if (deployment.getSpec().getSelector().getMatchLabels() != null) {
    podLister.withLabels(deployment.getSpec().getSelector().getMatchLabels());
  }
  if (deployment.getSpec().getSelector().getMatchExpressions() != null) {
    for (LabelSelectorRequirement req : deployment.getSpec().getSelector().getMatchExpressions()) {
      switch (req.getOperator()) {
      case "In":
        podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[] {}));
        break;
      case "NotIn":
        podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[] {}));
        break;
      case "DoesNotExist":
        podLister.withoutLabel(req.getKey());
        break;
      case "Exists":
        podLister.withLabel(req.getKey());
        break;
      }
    }
  }
  return podLister.list();
}
 
Example 7
Source File: Pods.java    From dekorate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link PodList} that match the specified {@link ReplicaSet}.
 *
 * @param replicaSet The {@link ReplicaSet}
 */
protected PodList map(ReplicaSet replicaSet) {
  FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister = client.pods()
      .inNamespace(replicaSet.getMetadata().getNamespace());
  if (replicaSet.getSpec().getSelector().getMatchLabels() != null) {
    podLister.withLabels(replicaSet.getSpec().getSelector().getMatchLabels());
  }
  if (replicaSet.getSpec().getSelector().getMatchExpressions() != null) {
    for (LabelSelectorRequirement req : replicaSet.getSpec().getSelector().getMatchExpressions()) {
      switch (req.getOperator()) {
      case "In":
        podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[] {}));
        break;
      case "NotIn":
        podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[] {}));
        break;
      case "DoesNotExist":
        podLister.withoutLabel(req.getKey());
        break;
      case "Exists":
        podLister.withLabel(req.getKey());
        break;
      }
    }
  }
  return podLister.list();
}