private async Task RecordToSink(KubeEvent item, CancellationToken cancellation)
        {
            // recorder.makeEvent(refRegarding, refRelated, timestamp, eventtype, reason, message, recorder.reportingController, recorder.reportingInstance, action)
            // See https://github.com/kubernetes/client-go/blob/758467711e075d6fd3d31abcaf6e2e1eb51ef3d4/tools/events/event_recorder.go#L66
            var evt = new Eventsv1Event
            {
                ApiVersion = Eventsv1Event.KubeGroup + "/" + Eventsv1Event.KubeApiVersion,
                Kind       = Eventsv1Event.KubeKind,
                Regarding  = item.Regarding,
                Reason     = item.Reason,
                Type       = item.EvtType.ToString(),
                Metadata   = new V1ObjectMeta
                {
                    Name = $"{item.Regarding.Name}.{item.Timestamp.Ticks:D}",
                    NamespaceProperty = item.Regarding.NamespaceProperty,
                },
                Note                = item.Message,
                EventTime           = item.Timestamp,
                ReportingController = "dotnet-ingress-controller",
                ReportingInstance   = _configuration.PodName,
                Action              = "Added",
            };

            try
            {
                var createdEvent = await _client.CreateNamespacedEvent1Async(evt, namespaceParameter : item.Regarding.NamespaceProperty, cancellationToken : cancellation);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to report event for {namespace}/{name}", item.Regarding.NamespaceProperty, item.Regarding.Name);
            }
        }
Beispiel #2
0
        public async ValueTask CreateEvent(V1ObjectReference runtimeObject, KubeEvent.EventType eventType, string reason, string message, CancellationToken cancellation)
        {
            var kubeEvent = new KubeEvent
            {
                Regarding = runtimeObject,
                Timestamp = DateTime.UtcNow,
                EvtType   = eventType,
                Reason    = reason,
                Message   = message,
            };

            _logger.LogInformation($"Event(Kind={runtimeObject.Kind}, Resource={runtimeObject.NamespaceProperty}/{runtimeObject.Name}, UID={runtimeObject.Uid}, APIVersion={runtimeObject.ApiVersion}, ResourceVersion={runtimeObject.ResourceVersion}, type={eventType}, reason='{reason}', '{message}')");

            await _channel.Writer.WriteAsync(kubeEvent, cancellation);
        }