notification

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const PermanentFailureMarker = "permanent failure"

PermanentFailureMarker is the string stored in delivery attempt errors to indicate a permanent (non-retryable) failure. Used by circuit breaker logic to skip retry for channels with permanent errors (4xx, auth failures).

Variables

This section is empty.

Functions

This section is empty.

Types

type NotificationRequestReconciler

type NotificationRequestReconciler struct {
	client.Client
	APIReader client.Reader // DD-STATUS-001: Cache-bypassed reader for critical status checks
	Scheme    *runtime.Scheme

	// Delivery services
	ConsoleService *delivery.ConsoleDeliveryService
	FileService    *delivery.FileDeliveryService // E2E testing only (DD-NOT-002)

	// BR-NOT-104: Per-receiver credential resolution for Slack delivery
	CredentialResolver *credentials.Resolver

	SlackTimeout time.Duration // NT-1: HTTP timeout for Slack webhook (wired from config)

	// ========================================
	// DELIVERY ORCHESTRATOR (Pattern 3 - P0)
	// See: docs/architecture/patterns/CONTROLLER_REFACTORING_PATTERN_LIBRARY.md §3
	// ========================================
	//
	// DeliveryOrchestrator manages notification delivery across channels
	// Extracted from controller to improve testability and maintainability
	//
	// BENEFITS:
	// - ~217 lines extracted from controller
	// - Delivery logic isolated and testable
	// - Single responsibility principle
	//
	// WIRED IN: cmd/notification/main.go
	// USAGE: r.DeliveryOrchestrator.DeliverToChannels(...)
	//
	// ========================================
	// INTERFACE-BASED SERVICES PATTERN (P2)
	// ========================================
	// The orchestrator implements the Interface-Based Services pattern:
	//   - Interface: delivery.DeliveryService (pkg/notification/delivery/interface.go)
	//   - Registry: map[string]DeliveryService (orchestrator.channels)
	//   - Registration: orchestrator.RegisterChannel(name, service)
	//
	// All delivery channels (Slack, Console, File, Log, etc.) implement DeliveryService
	// and register dynamically via RegisterChannel() for pluggable architecture.
	//
	// See: docs/architecture/decisions/DD-NOT-007-DELIVERY-ORCHESTRATOR-REGISTRATION-PATTERN.md
	// ========================================
	DeliveryOrchestrator *delivery.Orchestrator

	// Data sanitization
	Sanitizer *sanitization.Sanitizer

	// v3.1: Circuit breaker for graceful degradation (Category B)
	// Migrated to github.com/sony/gobreaker via shared Manager wrapper
	// Provides per-channel isolation (Slack, console, webhooks)
	CircuitBreaker *circuitbreaker.Manager

	// v1.1: Audit integration for unified audit table (ADR-034)
	// BR-NOT-062: Unified Audit Table Integration
	// BR-NOT-063: Graceful Audit Degradation
	// See: DD-NOT-001-ADR034-AUDIT-INTEGRATION-v2.0-FULL.md
	AuditStore   audit.AuditStore           // Buffered store for async audit writes (fire-and-forget)
	AuditManager *notificationaudit.Manager // Audit event manager (DD-AUDIT-002)

	// BR-NOT-065: Channel Routing Based on Spec Fields
	// BR-NOT-067: Routing Configuration Hot-Reload
	// Thread-safe router with hot-reload support from ConfigMap
	// See: DD-WE-004 (skip-reason routing)
	Router *routing.Router

	// ========================================
	// METRICS RECORDER (DD-METRICS-001)
	// 📋 Design Decision: DD-METRICS-001 | ✅ Dependency Injection Pattern
	// See: docs/architecture/decisions/DD-METRICS-001-controller-metrics-wiring-pattern.md
	// ========================================
	//
	// Metrics recorder for observability (DD-005 compliant)
	// Dependency-injected to enable testing and isolation
	//
	// MANDATORY: DD-METRICS-001 requires metrics to be dependency-injected
	// RATIONALE: Enables test isolation, prevents global state pollution
	//
	// WIRED IN: cmd/notification/main.go
	// USED IN: All reconciliation methods that emit metrics
	Metrics *notificationmetrics.Metrics

	// ========================================
	// EVENT RECORDER (K8s Events for Debugging)
	// See: SERVICE_MATURITY_REQUIREMENTS.md v1.1.0 (P1 - Should Have)
	// See: docs/development/business-requirements/TESTING_GUIDELINES.md §1312-1357
	// ========================================
	//
	// EventRecorder for emitting Kubernetes Events
	// Used for operational debugging and troubleshooting
	//
	// WIRED IN: cmd/notification/main.go
	// EVENTS EMITTED: ReconcileStarted, PhaseTransition, ReconcileComplete, ReconcileFailed
	Recorder record.EventRecorder

	// ========================================
	// STATUS MANAGER (Pattern 2 - P1 Quick Win)
	// See: docs/architecture/patterns/CONTROLLER_REFACTORING_PATTERN_LIBRARY.md §4
	// ========================================
	//
	// StatusManager handles all status updates with retry logic
	// Replaces controller's custom updateStatusWithRetry() method
	//
	// BENEFITS:
	// - Centralized status update logic (~100 lines saved)
	// - Consistent retry patterns across all status updates
	// - Better testability and separation of concerns
	//
	// WIRED IN: cmd/notification/main.go
	// USAGE: r.StatusManager.UpdatePhase(), r.StatusManager.RecordDeliveryAttempt()
	StatusManager *notificationstatus.Manager
	// contains filtered or unexported fields
}

NotificationRequestReconciler reconciles a NotificationRequest object

func (*NotificationRequestReconciler) ExportedAuditMessageAcknowledged

func (r *NotificationRequestReconciler) ExportedAuditMessageAcknowledged(ctx context.Context, notification *notificationv1alpha1.NotificationRequest) error

ExportedAuditMessageAcknowledged exposes auditMessageAcknowledged for ADR-032 compliance testing

func (*NotificationRequestReconciler) ExportedAuditMessageEscalated

func (r *NotificationRequestReconciler) ExportedAuditMessageEscalated(ctx context.Context, notification *notificationv1alpha1.NotificationRequest) error

ExportedAuditMessageEscalated exposes auditMessageEscalated for ADR-032 compliance testing

func (*NotificationRequestReconciler) ExportedAuditMessageFailed

func (r *NotificationRequestReconciler) ExportedAuditMessageFailed(ctx context.Context, notification *notificationv1alpha1.NotificationRequest, channel string, deliveryErr error) error

ExportedAuditMessageFailed exposes auditMessageFailed for ADR-032 compliance testing

func (*NotificationRequestReconciler) ExportedAuditMessageSent

func (r *NotificationRequestReconciler) ExportedAuditMessageSent(ctx context.Context, notification *notificationv1alpha1.NotificationRequest, channel string) error

ExportedAuditMessageSent exposes auditMessageSent for ADR-032 compliance testing

func (*NotificationRequestReconciler) Reconcile

Reconcile is part of the main kubernetes reconciliation loop which aims to move the current state of the cluster closer to the desired state.

For more details, check Reconcile and its Result here: - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile

BR-NOT-050: Data Loss Prevention (CRD persistence) BR-NOT-051: Complete Audit Trail (delivery attempts) BR-NOT-052: Automatic Retry (exponential backoff) BR-NOT-053: At-Least-Once Delivery (reconciliation loop) BR-NOT-056: CRD Lifecycle Management (phase state machine)

func (*NotificationRequestReconciler) SetupWithManager

func (r *NotificationRequestReconciler) SetupWithManager(mgr ctrl.Manager, opts ...controller.Options) error

SetupWithManager sets up the controller with the Manager. BR-NOT-067: Watches ConfigMap for routing configuration hot-reload

Optional opts parameter allows configuring controller behavior:

  • MaxConcurrentReconciles: Number of concurrent workers (default: 1)

Example (integration tests with high concurrency):

reconciler.SetupWithManager(mgr, controller.Options{
    MaxConcurrentReconciles: 5,  // 5 workers for 100 concurrent notifications
})

Jump to

Keyboard shortcuts

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