Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigMapNameForService(service string) string
- func DetectHostname() string
- type ConflictError
- type ConflictPolicy
- type DevSession
- type K8sSessionManager
- func (m *K8sSessionManager) Acquire(ctx context.Context, session DevSession, policy ConflictPolicy, force bool) (*DevSession, bool, error)
- func (m *K8sSessionManager) Heartbeat(ctx context.Context, namespace, service, sessionID string) error
- func (m *K8sSessionManager) List(ctx context.Context, namespace string) ([]DevSession, error)
- func (m *K8sSessionManager) Release(ctx context.Context, namespace, service, sessionID string) error
- type Manager
Constants ¶
const ( ConfigMapPrefix = "diverge-dev-session-" ConfigMapDataKey = "session" LabelManagedBy = "divergedev.com/managed-by" LabelManagedByVal = "diverge" LabelService = "divergedev.com/service" LabelDeveloper = "divergedev.com/developer" LabelSessionID = "divergedev.com/session-id" )
Labels and keys for ConfigMap tracking.
const StaleSessionDuration = 90 * time.Second
StaleSessionDuration defines the duration after which an un-renewed session is considered abandoned. Aligns with Diverge's 90-second lease expiration.
Variables ¶
var ( ErrConflict = errors.New("dev session conflict detected") ErrSessionNotFound = errors.New("dev session not found") )
Functions ¶
func ConfigMapNameForService ¶
ConfigMapNameForService returns the standard ConfigMap name for tracking a service's dev session.
func DetectHostname ¶
func DetectHostname() string
DetectHostname returns the local machine hostname.
Types ¶
type ConflictError ¶
type ConflictError struct {
Service string
ExistingSession DevSession
CurrentDeveloper string
}
ConflictError represents a collision with another active developer session.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
func (*ConflictError) FormatWarning ¶
func (e *ConflictError) FormatWarning(policy ConflictPolicy) string
FormatWarning returns a prominent, human-readable terminal warning banner.
type ConflictPolicy ¶
type ConflictPolicy string
ConflictPolicy defines how to handle active developer collisions.
const ( // ConflictPolicyWarn logs a prominent warning but proceeds with the session. ConflictPolicyWarn ConflictPolicy = "warn" // ConflictPolicyBlock prevents the session from starting unless forced. ConflictPolicyBlock ConflictPolicy = "block" // ConflictPolicyAllow overwrites the existing session (last-writer-wins). ConflictPolicyAllow ConflictPolicy = "allow" )
type DevSession ¶
type DevSession struct {
ID string `json:"id"`
Service string `json:"service"`
Namespace string `json:"namespace"`
Developer string `json:"developer"`
Hostname string `json:"hostname"`
Branch string `json:"branch"`
PreviewID string `json:"previewId"`
GroupName string `json:"groupName"`
StartedAt time.Time `json:"startedAt"`
Heartbeat time.Time `json:"heartbeat"`
PID int `json:"pid,omitempty"`
}
DevSession contains metadata for an active local development session.
type K8sSessionManager ¶
type K8sSessionManager struct {
// contains filtered or unexported fields
}
K8sSessionManager implements Manager using Kubernetes ConfigMaps.
func NewSessionManager ¶
func NewSessionManager(c client.Client) *K8sSessionManager
NewSessionManager creates a new K8sSessionManager.
func (*K8sSessionManager) Acquire ¶
func (m *K8sSessionManager) Acquire(ctx context.Context, session DevSession, policy ConflictPolicy, force bool) (*DevSession, bool, error)
Acquire registers the developer's session, checking for collisions with other developers.
func (*K8sSessionManager) Heartbeat ¶
func (m *K8sSessionManager) Heartbeat(ctx context.Context, namespace, service, sessionID string) error
Heartbeat refreshes the session's heartbeat timestamp.
func (*K8sSessionManager) List ¶
func (m *K8sSessionManager) List(ctx context.Context, namespace string) ([]DevSession, error)
List returns all active dev sessions in the given namespace.
type Manager ¶
type Manager interface {
// Acquire attempts to start a session. Returns (existingSession, wasConflict, error).
Acquire(ctx context.Context, session DevSession, policy ConflictPolicy, force bool) (*DevSession, bool, error)
// Heartbeat extends the active session's lease.
Heartbeat(ctx context.Context, namespace, service, sessionID string) error
// Release cleanly tears down the session.
Release(ctx context.Context, namespace, service, sessionID string) error
// List returns all active dev sessions in the namespace.
List(ctx context.Context, namespace string) ([]DevSession, error)
}
Manager defines the interface for distributed developer session coordination.