我是Kubernetes的新手,我不确定如何正确实施手表; 特别是我不确定如何处理resourceVersion参数.
目标是观察具有特定标签的新pod,如果出现错误或从群集断开,则可以从上次发生的事件重启手表.
我正在做这样的事情:
// after setting up the connection and some parameters
String lastResourceVersion = null; // at beginning version is unknown
while (true) {
try {
Watch<V1Pod> watcher = Watch.createWatch(
client,
api.listNamespacedPodCall(namespace, pretty, fieldSelector, labelSelector, lastResourceVersion, forEver, true, null, null),
new TypeToken<Watch.Response<V1Pod>>() {}.getType()
);
for (Watch.Response<V1Pod> item : watcher) {
//increment the version
lastResourceVersion = item.object.getMetadata().getResourceVersion();
// do some stuff with the pod
}
} catch (ApiException apiException) {
log.error("restarting the watch from "+lastResourceVersion, apiException);
}
}
Run Code Online (Sandbox Code Playgroud)
使用Pod的resourceVersion重新初始化观看调用是否正确?此数字是群集中所有事件的时间戳,还是不同的api将使用不同的序列? …