作者:LoisWangol_326 | 来源:互联网 | 2022-12-02 17:53
我是Kubernetes的新手,我不确定如何正确实施手表; 特别是我不确定如何处理resourceVersion参数.
目标是观察具有特定标签的新pod,如果出现错误或从群集断开,则可以从上次发生的事件重启手表.
我正在做这样的事情:
// after setting up the connection and some parameters
String lastResourceVersion = null; // at beginning version is unknown
while (true) {
try {
Watch watcher = Watch.createWatch(
client,
api.listNamespacedPodCall(namespace, pretty, fieldSelector, labelSelector, lastResourceVersion, forEver, true, null, null),
new TypeToken>() {}.getType()
);
for (Watch.Response 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);
}
}
使用Pod的resourceVersion重新初始化观看调用是否正确?此数字是群集中所有事件的时间戳,还是不同的api将使用不同的序列?
我是否需要注意特定的例外情况?例如.如果资源版本是旧的?
谢谢