io.radanalytics.operator.common.ConfigMapWatcher Maven / Gradle / Ivy
package io.radanalytics.operator.common;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.radanalytics.operator.resource.HasDataHelper;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import static io.radanalytics.operator.common.OperatorConfig.ALL_NAMESPACES;
public class ConfigMapWatcher extends AbstractWatcher {
// use via builder
private ConfigMapWatcher(String namespace,
String entityName,
KubernetesClient client,
Map selector,
BiConsumer onAdd,
BiConsumer onDelete,
BiConsumer onModify,
Predicate predicate,
Function convert) {
super(true, namespace, entityName, client, null, selector, onAdd, onDelete, onModify, predicate, convert, null);
}
public static class Builder {
private boolean registered = false;
private String namespace = ALL_NAMESPACES;
private String entityName;
private KubernetesClient client;
private Map selector;
private BiConsumer onAdd;
private BiConsumer onDelete;
private BiConsumer onModify;
private Predicate predicate;
private Function convert;
public Builder withNamespace(String namespace) {
this.namespace = namespace;
return this;
}
public Builder withEntityName(String entityName) {
this.entityName = entityName;
return this;
}
public Builder withClient(KubernetesClient client) {
this.client = client;
return this;
}
public Builder withSelector(Map selector) {
this.selector = selector;
return this;
}
public Builder withOnAdd(BiConsumer onAdd) {
this.onAdd = onAdd;
return this;
}
public Builder withOnDelete(BiConsumer onDelete) {
this.onDelete = onDelete;
return this;
}
public Builder withOnModify(BiConsumer onModify) {
this.onModify = onModify;
return this;
}
public Builder withPredicate(Predicate predicate) {
this.predicate = predicate;
return this;
}
public Builder withConvert(Function convert) {
this.convert = convert;
return this;
}
public ConfigMapWatcher build() {
if (!registered) {
io.fabric8.kubernetes.internal.KubernetesDeserializer.registerCustomKind("v1#ConfigMap", ConfigMap.class);
registered = true;
}
return new ConfigMapWatcher(namespace, entityName, client, selector, onAdd, onDelete, onModify, predicate, convert);
}
}
public static T defaultConvert(Class clazz, ConfigMap cm) {
return HasDataHelper.parseCM(clazz, cm);
}
@Override
public CompletableFuture> watch() {
return createConfigMapWatch().thenApply(watch -> this);
}
}