Closed zhiweiv closed 2 years ago
cc @tg123
Any update on this? The new Watcher code doesn't seem to fire the onEvent
task.
@phspies Did not get a chance to create one Old API should work as the same. otherwise, it is a bug. Could you please show me the code?
Task<HttpOperationResponse<V1ReplicaSetList>> replicasetlistResp = k8Client.ListReplicaSetForAllNamespacesWithHttpMessagesAsync(watch: true);
replicationsetWatcher = replicasetlistResp.Watch<V1ReplicaSet, V1ReplicaSetList>(
onEvent: (eventType, replicationset) =>
{
Application.MainLoop.Invoke(() =>
{
Log.Info($"Processing ReplicationSet Event: {eventType} : {JsonConvert.SerializeObject(replicationset)}");
processEventDetails(eventType, replicationset);
switch (eventType)
{
case WatchEventType.Added:
replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Add);
break;
case WatchEventType.Modified:
replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Change);
break;
case WatchEventType.Deleted:
replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Delete);
break;
case WatchEventType.Error:
Log.Error("Error Event: error in watch thread");
break;
case WatchEventType.Bookmark:
Log.Error("Bookmark Event: error in watch thread");
break;
default:
Log.Error("default event: error in watch thread");
break;
}
replicasetsTableView.SetNeedsDisplay();
UpdateTabHeaders();
});
}, onError: (ex) =>
{
Log.Error(ex);
},
onClosed: () =>
{
Log.Error("ReplicaSets Watcher closed connection");
});
Task<HttpOperationResponse<V1ReplicaSetList>> replicasetlistResp = k8Client.ListReplicaSetForAllNamespacesWithHttpMessagesAsync(watch: true); replicationsetWatcher = replicasetlistResp.Watch<V1ReplicaSet, V1ReplicaSetList>( onEvent: (eventType, replicationset) => { Application.MainLoop.Invoke(() => { Log.Info($"Processing ReplicationSet Event: {eventType} : {JsonConvert.SerializeObject(replicationset)}"); processEventDetails(eventType, replicationset); switch (eventType) { case WatchEventType.Added: replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Add); break; case WatchEventType.Modified: replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Change); break; case WatchEventType.Deleted: replicasetsList.AddUpdateDelete(new ReplicaSetType(replicationset), CRUDOperation.Delete); break; case WatchEventType.Error: Log.Error("Error Event: error in watch thread"); break; case WatchEventType.Bookmark: Log.Error("Bookmark Event: error in watch thread"); break; default: Log.Error("default event: error in watch thread"); break; } replicasetsTableView.SetNeedsDisplay(); UpdateTabHeaders(); }); }, onError: (ex) => { Log.Error(ex); }, onClosed: () => { Log.Error("ReplicaSets Watcher closed connection"); });
I tested your code by keeping Log.Info
only.
it works on my test env. could you please take a deeper look at your code again?
So update on the example? I'd like to use the new api but not figured out how to do it.
@tg123 One more question, in old api, there is an onClose event, we can use it to monitor the watch close and open a new watch.
In new pattern, if the watch closed, I guess the loop will end, then we can dispose the podlistResp and open a new watch, is it right? For example:
while (true)
{
using var podlistResp = client.ListNamespacedPodWithHttpMessagesAsync("default", watch: true);
await foreach (var (type, item) in podlistResp.WatchAsync<V1Pod, V1PodList>())
{
//
}
}
Seems there is a new watch api https://github.com/kubernetes-client/csharp/pull/586, can you add an example about how to use it? There is no update in https://github.com/kubernetes-client/csharp/blob/master/examples/watch/Program.cs.