notifications

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

Notification Data Sources

Type: k8s-notification-source
Type: endpoint-notification-source

This package provides two event-driven DataSource plugins for the EPP data layer:

  • k8s-notification-source — watches a single Kubernetes GVK (e.g. Pod, Service) and dispatches NotificationEvents to registered NotificationExtractors when objects are created, updated, or deleted. Multiple extractors can be notified of GVK changes by a single source. Multiple sources are required for different GVKs.
  • endpoint-notification-source — delivers endpoint lifecycle events (add/update, delete) to registered EndpointExtractors whenever an endpoint is added to or removed from the datastore.

Both sources pass events through to their extractors unchanged. Extractors carry out the actual work: enriching endpoint attributes, updating caches, triggering side effects, etc. Multiple extractors can be attached to the notification sources.

Configuration

Plugins are declared in the top-level plugins list and wired into the data layer via the data.sources section. When no name is specified the plugin name defaults to its type string, which is the value used in pluginRef entries.

Watching a Kubernetes GVK
plugins:
  - type: k8s-notification-source
    parameters:
      group: ""        # empty for core API group
      version: v1
      kind: Pod
  - type: my-pod-extractor   # user-provided extractor plugin

data:
  sources:
    - pluginRef: k8s-notification-source
      extractors:
        - pluginRef: my-pod-extractor
Reacting to endpoint lifecycle events
plugins:
  - type: endpoint-notification-source
  - type: my-endpoint-extractor   # user-provided extractor plugin

data:
  sources:
    - pluginRef: endpoint-notification-source
      extractors:
        - pluginRef: my-endpoint-extractor

Writing extractors

GVK extractor (NotificationExtractor)

Implement NotificationExtractor to process events from a k8s-notification-source. The framework calls ExtractNotification for every add, update, and delete event on the watched GVK.

package myplugin

import (
	"context"
	"fmt"
	"reflect"

	"k8s.io/apimachinery/pkg/runtime/schema"

	fwkdl "github.com/llm-d/llm-d-router/pkg/epp/framework/interface/datalayer"
	fwkplugin "github.com/llm-d/llm-d-router/pkg/epp/framework/interface/plugin"
)

// PodEventLogger logs Pod add/remove events.
type PodEventLogger struct{}

func (e *PodEventLogger) TypedName() fwkplugin.TypedName {
	return fwkplugin.TypedName{Type: "my-pod-extractor", Name: "my-pod-extractor"}
}

func (e *PodEventLogger) ExpectedInputType() reflect.Type {
	return fwkdl.NotificationEventType
}

// Extract is the base Extractor method — not called for notification extractors.
func (e *PodEventLogger) Extract(_ context.Context, _ any, _ fwkdl.Endpoint) error { return nil }

func (e *PodEventLogger) GVK() schema.GroupVersionKind {
	return schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}
}

func (e *PodEventLogger) ExtractNotification(_ context.Context, event fwkdl.NotificationEvent) error {
	action := "added/updated"
	if event.Type == fwkdl.EventDelete {
		action = "removed"
	}
	fmt.Printf("pod %s: %s\n", event.Object.GetName(), action) // note: objects are delivered as Unstructured.
	return nil
}
Endpoint extractor (EndpointExtractor)

Implement EndpointExtractor to process events from an endpoint-notification-source. The framework calls ExtractEndpoint for every add/update and delete event on an endpoint.

package myplugin

import (
	"context"
	"fmt"
	"reflect"

	fwkdl "github.com/llm-d/llm-d-router/pkg/epp/framework/interface/datalayer"
	fwkplugin "github.com/llm-d/llm-d-router/pkg/epp/framework/interface/plugin"
)

// EndpointEventLogger logs endpoint add/remove events.
type EndpointEventLogger struct{}

func (e *EndpointEventLogger) TypedName() fwkplugin.TypedName {
	return fwkplugin.TypedName{Type: "my-endpoint-extractor", Name: "my-endpoint-extractor"}
}

func (e *EndpointEventLogger) ExpectedInputType() reflect.Type {
	return fwkdl.EndpointEventReflectType
}

// Extract is the base Extractor method — not called for endpoint extractors.
func (e *EndpointEventLogger) Extract(_ context.Context, _ any, _ fwkdl.Endpoint) error { return nil }

func (e *EndpointEventLogger) ExtractEndpoint(_ context.Context, event fwkdl.EndpointEvent) error {
	action := "added/updated"
	if event.Type == fwkdl.EventDelete {
		action = "removed"
	}
	fmt.Printf("endpoint %s: %s\n", event.Endpoint.GetMetadata().GetNamespacedName(), action)
	return nil
}

Documentation

Index

Constants

View Source
const EndpointNotificationSourceType = "endpoint-notification-source"

EndpointNotificationSourceType is the plugin type identifier for endpoint notification sources.

View Source
const NotificationSourceType = "k8s-notification-source"

NotificationSourceType is the plugin type identifier for k8s notification sources.

Variables

This section is empty.

Functions

func EndpointSourceFactory

func EndpointSourceFactory(name string, _ *json.Decoder, _ fwkplugin.Handle) (fwkplugin.Plugin, error)

EndpointSourceFactory is the factory function for endpoint notification source plugins.

func NotificationSourceFactory

func NotificationSourceFactory(name string, parameters *json.Decoder, _ fwkplugin.Handle) (fwkplugin.Plugin, error)

NotificationSourceFactory is the factory function for k8s notification source plugins.

Types

type EndpointDataSource

type EndpointDataSource struct {
	// contains filtered or unexported fields
}

EndpointDataSource is an EndpointSource that passes endpoint lifecycle events through to registered EndpointExtractors without modification.

func NewEndpointDataSource

func NewEndpointDataSource(pluginType, pluginName string) *EndpointDataSource

NewEndpointDataSource returns a new EndpointDataSource with the given plugin type and name.

func (*EndpointDataSource) NotifyEndpoint

NotifyEndpoint passes the event through unchanged for the Runtime to dispatch to extractors.

func (*EndpointDataSource) TypedName

func (s *EndpointDataSource) TypedName() fwkplugin.TypedName

TypedName returns the plugin type and name.

type K8sNotificationSource

type K8sNotificationSource struct {
	// contains filtered or unexported fields
}

K8sNotificationSource watches a single GVK and dispatches events to registered NotificationExtractors.

func NewK8sNotificationSource

func NewK8sNotificationSource(pluginType, pluginName string,
	gvk schema.GroupVersionKind) *K8sNotificationSource

NewK8sNotificationSource returns a new notification source for the given GVK.

func (*K8sNotificationSource) GVK

GVK returns the GroupVersionKind this source watches.

func (*K8sNotificationSource) Notify

Notify passes the event through for Runtime to dispatch to extractors. Returns nil to skip extractor dispatch.

func (*K8sNotificationSource) TypedName

func (s *K8sNotificationSource) TypedName() fwkplugin.TypedName

TypedName returns the plugin type and name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL