Skip to content

Commit

Permalink
read selector from member field
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Dec 9, 2024
1 parent b6b0d24 commit eeefaed
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void eventReceived(Action action, Service service0) {
service = service0;
nodePort = nodePort0;

watchPodAsync(service0.getSpec().getSelector());
watchPodAsync();
break;
case DELETED:
logger.warn("[{}/{}] service is deleted.", namespace, serviceName);
Expand Down Expand Up @@ -351,7 +351,7 @@ public void onClose() {
}
}

private CompletableFuture<Void> watchPodAsync(Map<String, String> selector) {
private CompletableFuture<Void> watchPodAsync() {
return CompletableFuture.supplyAsync(() -> {
final Watch oldPodWatch = podWatch;
if (oldPodWatch != null) {
Expand All @@ -363,7 +363,7 @@ private CompletableFuture<Void> watchPodAsync(Map<String, String> selector) {
}
final Watch newPodwatch;
try {
newPodwatch = watchPod(selector);
newPodwatch = watchPod();
} catch (Exception e) {
logger.warn("[{}/{}] Failed to start the pod watcher.", namespace, serviceName, e);
return null;
Expand All @@ -379,7 +379,7 @@ private CompletableFuture<Void> watchPodAsync(Map<String, String> selector) {
}, worker);
}

private Watch watchPod(Map<String, String> selector) {
private Watch watchPod() {
// Clear the podToNode map before starting a new pod watch.
podToNode.clear();
final Watcher<Pod> watcher = new Watcher<Pod>() {
Expand Down Expand Up @@ -425,7 +425,7 @@ public void onClose(WatcherException cause) {
logger.info("[{}/{}] Reconnecting the pod watcher...", namespace, serviceName);
// TODO(ikhoon): Add a backoff strategy to prevent rapid reconnections when the pod watcher
// keeps failing.
watchPodAsync(selector);
watchPodAsync();
}

@Override
Expand All @@ -434,6 +434,9 @@ public void onClose() {
}
};

final Service service = this.service;
assert service != null;
final Map<String, String> selector = service.getSpec().getSelector();
// watch() method will block until the watch connection is established.
if (namespace == null) {
return client.pods().withLabels(selector).watch(watcher);
Expand Down

0 comments on commit eeefaed

Please sign in to comment.