Documentation
¶
Overview ¶
Package events provides core infrastructure for generating Kubernetes Events for muster CRD lifecycle operations.
This package extends the existing unified MusterClient architecture to support Kubernetes Events generation, enabling visibility into CRD operations through standard Kubernetes tooling (kubectl get events).
Architecture:
The events package follows the existing service locator pattern and integrates with the unified MusterClient interface. It provides:
- EventGenerator: Core event generation utilities using MusterClient
- MessageTemplateEngine: Dynamic message templating system
- Event type definitions and constants
- API integration following service locator pattern
Backend Support:
- Kubernetes: Creates actual Kubernetes Events API objects
- Filesystem: Logs events to console and events.log file
The package automatically adapts to the current client mode (Kubernetes vs filesystem) through the unified MusterClient interface, ensuring consistent behavior across different deployment environments.
Usage:
Components should access event generation functionality through the API layer:
eventManager := api.GetEventManager()
if eventManager != nil {
err := eventManager.CreateEvent(ctx, objectRef, "Created", "MCPServer successfully created", "Normal")
}
Direct usage of EventGenerator is also supported for advanced scenarios:
generator := events.NewEventGenerator(musterClient)
err := generator.MCPServerEvent(server, events.ReasonCreated, events.EventData{})
Index ¶
- type Adapter
- func (a *Adapter) CreateEvent(ctx context.Context, objectRef api.ObjectReference, ...) error
- func (a *Adapter) CreateEventForCRD(ctx context.Context, ...) error
- func (a *Adapter) ExecuteTool(ctx context.Context, toolName string, args map[string]interface{}) (*api.CallToolResult, error)
- func (a *Adapter) GetGenerator() *EventGenerator
- func (a *Adapter) GetTools() []api.ToolMetadata
- func (a *Adapter) IsKubernetesMode() bool
- func (a *Adapter) QueryEvents(ctx context.Context, options api.EventQueryOptions) (*api.EventQueryResult, error)
- func (a *Adapter) Register()
- type EventData
- type EventGenerator
- func (g *EventGenerator) CRDEvent(crdType, name, namespace string, reason EventReason, data EventData) error
- func (g *EventGenerator) GetTemplate(reason EventReason) (string, bool)
- func (g *EventGenerator) IsKubernetesMode() bool
- func (g *EventGenerator) MCPServerEvent(server *musterv1alpha1.MCPServer, reason EventReason, data EventData) error
- func (g *EventGenerator) SetTemplate(reason EventReason, template string)
- func (g *EventGenerator) WorkflowEvent(workflow *musterv1alpha1.Workflow, reason EventReason, data EventData) error
- type EventReason
- type EventType
- type MessageTemplateEngine
- type ObjectReference
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements the EventManagerHandler interface using the unified MusterClient. It bridges the events package functionality with the API service locator pattern. It also implements the ToolProvider interface to expose event querying capabilities through the aggregator.
func NewAdapter ¶
func NewAdapter(musterClient client.MusterClient) *Adapter
NewAdapter creates a new events adapter using the provided MusterClient.
func (*Adapter) CreateEvent ¶
func (a *Adapter) CreateEvent(ctx context.Context, objectRef api.ObjectReference, reason, message, eventType string) error
CreateEvent creates an event for a specific object reference. Implements EventManagerHandler.CreateEvent.
func (*Adapter) CreateEventForCRD ¶
func (a *Adapter) CreateEventForCRD(ctx context.Context, crdType, name, namespace, reason, message, eventType string) error
CreateEventForCRD creates an event for a CRD by type, name, and namespace. Implements EventManagerHandler.CreateEventForCRD.
func (*Adapter) ExecuteTool ¶
func (a *Adapter) ExecuteTool(ctx context.Context, toolName string, args map[string]interface{}) (*api.CallToolResult, error)
ExecuteTool executes a tool by name. Implements api.ToolProvider.ExecuteTool.
func (*Adapter) GetGenerator ¶
func (a *Adapter) GetGenerator() *EventGenerator
GetGenerator returns the underlying EventGenerator for advanced usage scenarios. This method is not part of the EventManagerHandler interface but provides access to advanced event generation features when needed.
func (*Adapter) GetTools ¶
func (a *Adapter) GetTools() []api.ToolMetadata
GetTools returns metadata for all tools this provider offers. Implements api.ToolProvider.GetTools.
func (*Adapter) IsKubernetesMode ¶
IsKubernetesMode returns true if the event manager is using Kubernetes mode. Implements EventManagerHandler.IsKubernetesMode.
func (*Adapter) QueryEvents ¶
func (a *Adapter) QueryEvents(ctx context.Context, options api.EventQueryOptions) (*api.EventQueryResult, error)
QueryEvents retrieves events based on filtering options. Implements EventManagerHandler.QueryEvents.
type EventData ¶
type EventData struct {
// Name is the name of the object involved in the event.
Name string
// Namespace is the namespace of the object involved in the event.
Namespace string
// Operation is the operation that triggered the event (e.g., "create", "update", "delete").
Operation string
// Arguments contains additional key-value data for the event.
Arguments map[string]interface{}
// Error contains error information for failure events.
Error string
// Duration is the duration of an operation (for execution events).
Duration time.Duration
// StepCount is the number of steps in a workflow execution.
StepCount int
// Workflow-specific fields
// StepID is the ID of the workflow step involved in the event.
StepID string
// StepTool is the tool used in the workflow step.
StepTool string
// ConditionResult is the result of step condition evaluation.
ConditionResult string
// ExecutionID is the unique identifier for a workflow execution.
ExecutionID string
// ToolNames contains the list of tools (for availability events).
ToolNames []string
// AllowFailure indicates whether a failed step allows failure.
AllowFailure bool
}
EventData holds contextual information for event message templating.
type EventGenerator ¶
type EventGenerator struct {
// contains filtered or unexported fields
}
EventGenerator provides event generation utilities using the unified MusterClient. It automatically adapts to the current client mode (Kubernetes vs filesystem) through the MusterClient interface.
func NewEventGenerator ¶
func NewEventGenerator(musterClient client.MusterClient) *EventGenerator
NewEventGenerator creates a new EventGenerator using the provided MusterClient.
func (*EventGenerator) CRDEvent ¶
func (g *EventGenerator) CRDEvent(crdType, name, namespace string, reason EventReason, data EventData) error
CRDEvent generates an event for a CRD by type, name, and namespace. This is useful when you don't have the actual CRD object but know its details.
func (*EventGenerator) GetTemplate ¶
func (g *EventGenerator) GetTemplate(reason EventReason) (string, bool)
GetTemplate returns the template for a specific event reason.
func (*EventGenerator) IsKubernetesMode ¶
func (g *EventGenerator) IsKubernetesMode() bool
IsKubernetesMode returns true if the generator is using Kubernetes mode.
func (*EventGenerator) MCPServerEvent ¶
func (g *EventGenerator) MCPServerEvent(server *musterv1alpha1.MCPServer, reason EventReason, data EventData) error
MCPServerEvent generates an event for an MCPServer CRD.
func (*EventGenerator) SetTemplate ¶
func (g *EventGenerator) SetTemplate(reason EventReason, template string)
SetTemplate allows customizing the message template for a specific event reason.
func (*EventGenerator) WorkflowEvent ¶
func (g *EventGenerator) WorkflowEvent(workflow *musterv1alpha1.Workflow, reason EventReason, data EventData) error
WorkflowEvent generates an event for a Workflow CRD.
type EventReason ¶
type EventReason string
EventReason represents the reason code for an event.
const ( // CRD Management Events // ReasonMCPServerCreated indicates an MCPServer CRD was successfully created. ReasonMCPServerCreated EventReason = "MCPServerCreated" // ReasonMCPServerUpdated indicates an MCPServer CRD was successfully updated. ReasonMCPServerUpdated EventReason = "MCPServerUpdated" // ReasonMCPServerDeleted indicates an MCPServer CRD was successfully deleted. ReasonMCPServerDeleted EventReason = "MCPServerDeleted" // Service Lifecycle Events // ReasonMCPServerStarting indicates an MCPServer service is beginning to start. ReasonMCPServerStarting EventReason = "MCPServerStarting" // ReasonMCPServerStarted indicates an MCPServer service was started successfully. ReasonMCPServerStarted EventReason = "MCPServerStarted" // ReasonMCPServerStopped indicates an MCPServer service was stopped. ReasonMCPServerStopped EventReason = "MCPServerStopped" // ReasonMCPServerRestarting indicates an MCPServer service is being restarted. ReasonMCPServerRestarting EventReason = "MCPServerRestarting" // ReasonMCPServerFailed indicates an MCPServer operation failed. ReasonMCPServerFailed EventReason = "MCPServerFailed" // Tool Discovery Events // ReasonMCPServerToolsDiscovered indicates tools were successfully discovered from an MCPServer. ReasonMCPServerToolsDiscovered EventReason = "MCPServerToolsDiscovered" ReasonMCPServerToolsUnavailable EventReason = "MCPServerToolsUnavailable" // ReasonMCPServerReconnected indicates connection to an MCPServer was restored. ReasonMCPServerReconnected EventReason = "MCPServerReconnected" // Health and Recovery Events // ReasonMCPServerHealthCheckFailed indicates health checks failed for an MCPServer. ReasonMCPServerHealthCheckFailed EventReason = "MCPServerHealthCheckFailed" // ReasonMCPServerRecoveryStarted indicates automatic recovery began for an MCPServer. ReasonMCPServerRecoveryStarted EventReason = "MCPServerRecoveryStarted" // ReasonMCPServerRecoverySucceeded indicates automatic recovery succeeded for an MCPServer. ReasonMCPServerRecoverySucceeded EventReason = "MCPServerRecoverySucceeded" // ReasonMCPServerRecoveryFailed indicates automatic recovery failed for an MCPServer. ReasonMCPServerRecoveryFailed EventReason = "MCPServerRecoveryFailed" // ReasonMCPServerAuthRequired indicates an MCPServer requires OAuth authentication. ReasonMCPServerAuthRequired EventReason = "MCPServerAuthRequired" // ReasonMCPServerTokenForwarded indicates an ID token was forwarded to a downstream server. // This event is generated when muster forwards a user's ID token instead of triggering // a separate OAuth flow, enabling SSO across the MCP ecosystem. ReasonMCPServerTokenForwarded EventReason = "MCPServerTokenForwarded" // ReasonMCPServerTokenForwardingFailed indicates ID token forwarding failed. // This may trigger fallback to server-specific OAuth if configured. ReasonMCPServerTokenForwardingFailed EventReason = "MCPServerTokenForwardingFailed" // ReasonMCPServerTokenExchanged indicates a token was successfully exchanged via RFC 8693. // This event is generated when muster exchanges a local token for one valid on a remote // cluster's Identity Provider, enabling cross-cluster SSO. ReasonMCPServerTokenExchanged EventReason = "MCPServerTokenExchanged" // ReasonMCPServerTokenExchangeFailed indicates RFC 8693 token exchange failed. // This may trigger fallback to server-specific OAuth if configured. ReasonMCPServerTokenExchangeFailed EventReason = "MCPServerTokenExchangeFailed" )
MCPServer event reasons
const ( // Configuration Management Events // ReasonWorkflowCreated indicates a Workflow was successfully created. ReasonWorkflowCreated EventReason = "WorkflowCreated" // ReasonWorkflowUpdated indicates a Workflow was successfully updated. ReasonWorkflowUpdated EventReason = "WorkflowUpdated" // ReasonWorkflowDeleted indicates a Workflow was successfully deleted. ReasonWorkflowDeleted EventReason = "WorkflowDeleted" // ReasonWorkflowValidationFailed indicates workflow definition validation failed. ReasonWorkflowValidationFailed EventReason = "WorkflowValidationFailed" // ReasonWorkflowValidationSucceeded indicates workflow definition validation passed. ReasonWorkflowValidationSucceeded EventReason = "WorkflowValidationSucceeded" // Execution Lifecycle Events // ReasonWorkflowExecutionStarted indicates workflow execution has begun. ReasonWorkflowExecutionStarted EventReason = "WorkflowExecutionStarted" // ReasonWorkflowExecutionCompleted indicates workflow execution completed successfully. ReasonWorkflowExecutionCompleted EventReason = "WorkflowExecutionCompleted" // ReasonWorkflowExecutionFailed indicates workflow execution failed. ReasonWorkflowExecutionFailed EventReason = "WorkflowExecutionFailed" // ReasonWorkflowExecutionTracked indicates execution state was persisted. ReasonWorkflowExecutionTracked EventReason = "WorkflowExecutionTracked" // Step-Level Execution Events // ReasonWorkflowStepStarted indicates individual step began execution. ReasonWorkflowStepStarted EventReason = "WorkflowStepStarted" // ReasonWorkflowStepCompleted indicates individual step completed successfully. ReasonWorkflowStepCompleted EventReason = "WorkflowStepCompleted" // ReasonWorkflowStepFailed indicates individual step failed (with allowFailure context). ReasonWorkflowStepFailed EventReason = "WorkflowStepFailed" // ReasonWorkflowStepSkipped indicates step was skipped due to condition evaluation. ReasonWorkflowStepSkipped EventReason = "WorkflowStepSkipped" // ReasonWorkflowStepConditionEvaluated indicates step condition was evaluated. ReasonWorkflowStepConditionEvaluated EventReason = "WorkflowStepConditionEvaluated" // Tool Availability Events // ReasonWorkflowAvailable indicates all required tools became available. ReasonWorkflowAvailable EventReason = "WorkflowAvailable" ReasonWorkflowUnavailable EventReason = "WorkflowUnavailable" // ReasonWorkflowToolsDiscovered indicates new required tools are discovered and available. ReasonWorkflowToolsDiscovered EventReason = "WorkflowToolsDiscovered" // ReasonWorkflowToolsMissing indicates specific tools became unavailable. ReasonWorkflowToolsMissing EventReason = "WorkflowToolsMissing" // Tool Registration Events // ReasonWorkflowToolRegistered indicates workflow was registered as action_<workflow-name> tool. ReasonWorkflowToolRegistered EventReason = "WorkflowToolRegistered" // ReasonWorkflowToolUnregistered indicates workflow tool was removed from aggregator. ReasonWorkflowToolUnregistered EventReason = "WorkflowToolUnregistered" // ReasonWorkflowCapabilitiesRefreshed indicates aggregator capabilities were updated after workflow changes. ReasonWorkflowCapabilitiesRefreshed EventReason = "WorkflowCapabilitiesRefreshed" // Legacy event reasons (kept for compatibility) // ReasonWorkflowExecuted indicates a Workflow was successfully executed. ReasonWorkflowExecuted EventReason = "WorkflowExecuted" )
Workflow event reasons
type EventType ¶
type EventType string
EventType represents the type/severity of a Kubernetes Event.
type MessageTemplateEngine ¶
type MessageTemplateEngine struct {
// contains filtered or unexported fields
}
MessageTemplateEngine provides dynamic message generation for events.
func NewMessageTemplateEngine ¶
func NewMessageTemplateEngine() *MessageTemplateEngine
NewMessageTemplateEngine creates a new message template engine with default templates.
func (*MessageTemplateEngine) GetTemplate ¶
func (e *MessageTemplateEngine) GetTemplate(reason EventReason) (string, bool)
GetTemplate returns the template for a specific event reason.
func (*MessageTemplateEngine) Render ¶
func (e *MessageTemplateEngine) Render(reason EventReason, data EventData) string
Render generates a message for the given event reason and data.
func (*MessageTemplateEngine) SetTemplate ¶
func (e *MessageTemplateEngine) SetTemplate(reason EventReason, template string)
SetTemplate allows customizing the message template for a specific event reason.
type ObjectReference ¶
type ObjectReference struct {
// APIVersion is the API version of the object.
APIVersion string
// Kind is the kind of the object.
Kind string
// Name is the name of the object.
Name string
// Namespace is the namespace of the object.
Namespace string
// UID is the unique identifier of the object (optional).
UID string
}
ObjectReference represents a reference to a Kubernetes object for event creation.