Example #1
0
 private static bool HasFailed(V1Pod value, [NotNullWhen(true)] out Exception?ex)
 {
     if (value.Status.Phase == "Failed")
     {
         ex = new KubernetesException($"The pod {value.Metadata.Name} has failed: {value.Status.Reason}");
         return(true);
     }
     else
     {
         ex = null;
         return(false);
     }
 }
Example #2
0
        public async Task Execute()
        {
            try
            {
                Watching = true;
                string line;
                _streamReader = await _streamReaderFactory().ConfigureAwait(false);

                // ReadLineAsync will return null when reached the end of the stream.
                while ((line = await _streamReader.ReadLineAsync().ConfigureAwait(false)) != null)
                {
                    if (_cts.IsCancellationRequested)
                    {
                        return;
                    }

                    try
                    {
                        var watchEvent = JsonConvert.DeserializeStringEnum <WatchEvent>(line);
                        if (watchEvent != null)
                        {
                            OnEvent?.Invoke(watchEvent.Type, watchEvent.Object, _cts);
                        }
                        else
                        {
                            var statusEvent = JsonConvert.DeserializeStringEnum <Watch <V1Status> .WatchEvent>(line);
                            var exception   = new KubernetesException(statusEvent?.Object);
                            OnError?.Invoke(exception);
                        }
                    }
#pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception ex)
                    {
                        // deserialized failed or OnEvent throws
                        OnError?.Invoke(ex);
                    }
#pragma warning restore CA1031 // Do not catch general exception types
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                OnError?.Invoke(ex);
            }
#pragma warning restore CA1031 // Do not catch general exception types
            finally
            {
                Watching = false;
                OnClosed?.Invoke();
            }
        }