Skip to content

Commit 433ed1a

Browse files
authored
Watch a Kubernetes service from the latest resource version. (line#6305)
Motivation: I found out that the Fabric8 Kubernetes client uses a list API to establish a watch connection, such as "/api/v1/namespaces/<namespace>/services?fieldSelector=metadata.name=<service-name>&watch=true". Therefore, the resource version of a service cannot be used to indicate the last known version. Modifications: - Do not specify a resource version to watch a service. - The latest version is fetched instead. - `watcher.eventReceived()` compares the cached version with the latest version to decide whether an update is needed. Result: You no longer see `WatcherException: too old resource version` when using `KubernetesEndpointGroup`.
1 parent a041a7b commit 433ed1a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

kubernetes/src/main/java/com/linecorp/armeria/client/kubernetes/endpoints/KubernetesEndpointGroup.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,16 @@ public void onClose() {
422422

423423
final Service service = this.service;
424424
assert service != null;
425+
426+
// Fabric8 Kubernetes client uses a list API to establish a watch connection, such as
427+
// "/api/v1/namespaces/<namespace>/services?fieldSelector=metadata.name=<service-name>&watch=true".
428+
// Therefore, the resource version of a service cannot be used. Instead, it fetches the latest version
429+
// and compares it with the cached version in `watcher.eventReceived()` to decide whether an update is
430+
// needed.
425431
if (namespace == null) {
426-
return client.services().withName(serviceName).withResourceVersion(resourceVersion).watch(watcher);
432+
return client.services().withName(serviceName).watch(watcher);
427433
} else {
428-
return client.services().inNamespace(namespace).withName(serviceName)
429-
.withResourceVersion(resourceVersion).watch(watcher);
434+
return client.services().inNamespace(namespace).withName(serviceName).watch(watcher);
430435
}
431436
}
432437

0 commit comments

Comments
 (0)