Skip to content

Commit

Permalink
Configure watcher with namespaces and align tests (cherry-pick from 2…
Browse files Browse the repository at this point in the history
…3507c4 in main branch)

Related to smallrye#373
  • Loading branch information
aureamunoz committed Jul 13, 2023
1 parent 48f3838 commit 51a7f76
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import io.fabric8.kubernetes.api.model.EndpointPort;
import io.fabric8.kubernetes.api.model.EndpointSubset;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsList;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.AnyNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
import io.smallrye.mutiny.Uni;
import io.smallrye.stork.api.Metadata;
Expand Down Expand Up @@ -84,7 +87,13 @@ public KubernetesServiceDiscovery(String serviceName, KubernetesConfiguration co
this.client = new KubernetesClientBuilder().withConfig(k8sConfig).build();
this.vertx = vertx;
this.secure = isSecure(config);
client.endpoints().inform(new ResourceEventHandler<Endpoints>() {
AnyNamespaceOperation<Endpoints, EndpointsList, Resource<Endpoints>> endpointsOperation;
if (allNamespaces) {
endpointsOperation = client.endpoints().inAnyNamespace();
} else {
endpointsOperation = client.endpoints().inNamespace(namespace);
}
endpointsOperation.inform(new ResourceEventHandler<Endpoints>() {
@Override
public void onAdd(Endpoints obj) {
LOGGER.info("Endpoint added: {}", obj.getMetadata().getName());
Expand Down
Loading

0 comments on commit 51a7f76

Please sign in to comment.