Example #1
0
        /// <summary>
        /// Watch for events that apply to the specified Kubernetes resource.
        /// </summary>
        /// <param name="eventClient">The Kubernetes API client.</param>
        /// <param name="resource">The <see cref="KubeResourceV1"/>.</param>
        /// <returns>An <see cref="EventListV1"/> containing the relevant events.</returns>
        public static IObservable <IResourceEventV1 <EventV1> > WatchAll(this IEventClientV1 eventClient, KubeResourceV1 resource)
        {
            if (eventClient == null)
            {
                throw new ArgumentNullException(nameof(eventClient));
            }

            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            string fieldSelector = BuildInvolvedObjectFieldSelector(resource);

            return(eventClient.WatchAll(
                       fieldSelector: fieldSelector,
                       resourceVersion: resource.Metadata.ResourceVersion
                       ));
        }
Example #2
0
        /// <summary>
        /// List events that apply to the specified Kubernetes resource.
        /// </summary>
        /// <param name="eventClient">The Kubernetes API client.</param>
        /// <param name="resource">The <see cref="KubeResourceV1"/>.</param>
        /// <param name="onlyNewEvents">Only return events newer than the <paramref name="resource"/>'s ResourceVersion?</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> that can be used to cancel the request.</param>
        /// <returns>An <see cref="EventListV1"/> containing the relevant events.</returns>
        public static Task <EventListV1> List(this IEventClientV1 eventClient, KubeResourceV1 resource, bool onlyNewEvents = false, CancellationToken cancellationToken = default)
        {
            if (eventClient == null)
            {
                throw new ArgumentNullException(nameof(eventClient));
            }

            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            string fieldSelector = BuildInvolvedObjectFieldSelector(resource);

            return(eventClient.List(
                       fieldSelector: fieldSelector,
                       resourceVersion: onlyNewEvents ? resource.Metadata.ResourceVersion : null,
                       cancellationToken: cancellationToken
                       ));
        }