use of io.kubernetes.client.util.labels.LabelSelector in project java by kubernetes-client.
the class DeploymentHelper method listReplicaSets.
/**
* listReplicaSets returns a list of RSes the given deployment targets. Note that this does NOT
* attempt to reconcile ControllerRef (adopt/orphan), because only the controller itself should do
* that. However, it does filter out anything whose ControllerRef doesn't match.
*/
private static List<V1ReplicaSet> listReplicaSets(V1Deployment deployment, AppsV1Api api) throws ApiException {
String namespace = deployment.getMetadata().getNamespace();
LabelSelector selector = LabelSelector.parse(deployment.getSpec().getSelector());
List<V1ReplicaSet> all = rsListFromClient(namespace, selector.toString(), api);
List<V1ReplicaSet> owned = new ArrayList<>(all.size());
for (V1ReplicaSet rs : all) {
List<V1OwnerReference> refs = rs.getMetadata().getOwnerReferences();
Optional<V1OwnerReference> ref = refs.stream().filter(o -> o.getController() != null && o.getController()).findAny();
// Only include those whose ControllerRef matches the Deployment.
if (ref.isPresent() && ref.get().getUid().equals(deployment.getMetadata().getUid())) {
owned.add(rs);
}
}
return owned;
}
Aggregations