async Task OnListPodsCompleted(Task <HttpOperationResponse <V1PodList> > task) { HttpOperationResponse <V1PodList> podListResp = await task; this.podWatch = Option.Some( podListResp.Watch <V1Pod, V1PodList>( onEvent: (type, item) => { try { this.HandlePodChangedAsync(type, item); } catch (Exception ex) when(!ex.IsFatal()) { Events.PodWatchFailed(ex); } }, onClosed: () => { Events.PodWatchClosed(); // get rid of the current pod watch object since we got closed this.podWatch.ForEach(watch => watch.Dispose()); this.podWatch = Option.None <Watcher <V1Pod> >(); // kick off a new watch this.StartListPods(); }, onError: Events.PodWatchFailed)); }
async Task OnListEdgeDeploymentsCompleted(Task <HttpOperationResponse <object> > task) { HttpOperationResponse <object> response = await task; this.operatorWatch = Option.Some( response.Watch <EdgeDeploymentDefinition>( onEvent: async(type, item) => { try { await this.HandleEdgeDeploymentChangedAsync(type, item); } catch (Exception ex) when(!ex.IsFatal()) { Events.EdgeDeploymentWatchFailed(ex); } }, onClosed: () => { Events.EdgeDeploymentWatchClosed(); // get rid of the current edge deployment watch object since we got closed this.operatorWatch.ForEach(watch => watch.Dispose()); this.operatorWatch = Option.None <Watcher <EdgeDeploymentDefinition> >(); // kick off a new watch this.StartListEdgeDeployments(); }, onError: Events.EdgeDeploymentWatchFailed)); }
public async Task Start(CancellationToken cancellationToken) { var kubernetesClient = new k8s.Kubernetes(_kubernetesConfiguration); var kubernetesNamespace = _configuration.GetValue <string>(key: "NAMESPACE"); HttpOperationResponse <V1EventList> eventsPerNamespace = await kubernetesClient.ListNamespacedEventWithHttpMessagesAsync(kubernetesNamespace, watch : true, cancellationToken : cancellationToken); _watch = eventsPerNamespace.Watch <V1Event>(async(type, kubernetesEvent) => await HandleKubernetesEvent(type, kubernetesEvent)); }
public async Task ListCrdComplete(Task <HttpOperationResponse <object> > customObjectWatchTask) { if (customObjectWatchTask == null) { Events.NullListResponse("ListClusterCustomObjectWithHttpMessagesAsync", "task"); throw new NullReferenceException("Null Task from ListClusterCustomObjectWithHttpMessagesAsync"); } else { HttpOperationResponse <object> customObjectWatch = await customObjectWatchTask; if (customObjectWatch != null) { // We can add events to a watch once created, like if connection is closed, etc. this.operatorWatch = Option.Some( customObjectWatch.Watch <object>( onEvent: async(type, item) => { try { await this.WatchDeploymentEventsAsync(type, item); } catch (Exception ex) when(!ex.IsFatal()) { Events.ExceptionInCustomResourceWatch(ex); } }, onClosed: () => { Events.CrdWatchClosed(); // get rid of the current crd watch object since we got closed this.operatorWatch.ForEach(watch => watch.Dispose()); this.operatorWatch = Option.None <Watcher <object> >(); // kick off a new watch this.client.ListClusterCustomObjectWithHttpMessagesAsync( Constants.K8sCrdGroup, Constants.K8sApiVersion, Constants.K8sCrdPlural, watch: true).ContinueWith(this.ListCrdComplete); }, onError: Events.ExceptionInCustomResourceWatch)); } else { Events.NullListResponse("ListClusterCustomObjectWithHttpMessagesAsync", "http response"); throw new NullReferenceException("Null response from ListClusterCustomObjectWithHttpMessagesAsync"); } } }
private async Task ListPodComplete(Task <HttpOperationResponse <V1PodList> > podListRespTask) { if (podListRespTask != null) { HttpOperationResponse <V1PodList> podListResp = await podListRespTask; if (podListResp != null) { this.podWatch = Option.Some( podListResp.Watch <V1Pod>( onEvent: async(type, item) => { try { await this.WatchPodEventsAsync(type, item); } catch (Exception ex) when(!ex.IsFatal()) { Events.ExceptionInPodWatch(ex); } }, onClosed: () => { Events.PodWatchClosed(); // get rid of the current pod watch object since we got closed this.podWatch.ForEach(watch => watch.Dispose()); this.podWatch = Option.None <Watcher <V1Pod> >(); // kick off a new watch this.client.ListNamespacedPodWithHttpMessagesAsync(this.deviceNamespace, watch: true).ContinueWith(this.ListPodComplete); }, onError: Events.ExceptionInPodWatch)); } else { Events.NullListResponse("ListNamespacedPodWithHttpMessagesAsync", "http response"); throw new KuberenetesResponseException("Null response from ListNamespacedPodWithHttpMessagesAsync"); } } else { Events.NullListResponse("ListNamespacedPodWithHttpMessagesAsync", "task"); throw new KuberenetesResponseException("Null Task from ListNamespacedPodWithHttpMessagesAsync"); } }
async Task OnSecretsListCompleted(Task <HttpOperationResponse <V1SecretList> > task) { HttpOperationResponse <V1SecretList> response = await task; this.operatorWatch = Option.Some( response.Watch <V1Secret, V1SecretList>( onEvent: async(type, item) => await this.SecretOnEventHandlerAsync(type, item), onClosed: () => { // get rid of the current edge deployment watch object since we got closed this.operatorWatch.ForEach(watch => watch.Dispose()); this.operatorWatch = Option.None <Watcher <V1Secret> >(); // kick off a new watch this.StartListSecrets(); }, onError: (e) => { Console.WriteLine("Error in Secret watch:"); throw e; })); }
async Task OnListEdgeDeploymentsCompleted(Task <HttpOperationResponse <object> > task) { HttpOperationResponse <object> response = await task; this.operatorWatch = Option.Some( response.Watch <EdgeDeploymentDefinition, object>( onEvent: async(type, item) => await this.EdgeDeploymentOnEventHandlerAsync(type, item), onClosed: () => { Events.EdgeDeploymentWatchClosed(); // get rid of the current edge deployment watch object since we got closed this.operatorWatch.ForEach(watch => watch.Dispose()); this.operatorWatch = Option.None <Watcher <EdgeDeploymentDefinition> >(); // kick off a new watch this.StartListEdgeDeployments(); }, onError: (ex) => { Events.EdgeDeploymentWatchFailed(ex); throw ex; })); }