コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: CrdWatcher.cs プロジェクト: vivekpt/iotedge
        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");
                }
            }
        }
コード例 #5
0
        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");
            }
        }
コード例 #6
0
        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;
            }));
        }
コード例 #7
0
        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;
            }));
        }