devsession

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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

View Source
var (
	ErrConflict        = errors.New("dev session conflict detected")
	ErrSessionNotFound = errors.New("dev session not found")
)

Functions

func ConfigMapNameForService

func ConfigMapNameForService(service string) string

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.

func (DevSession) IsStale

func (s DevSession) IsStale(now time.Time) bool

IsStale returns true if the session heartbeat has not been updated within StaleSessionDuration.

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.

func (*K8sSessionManager) Release

func (m *K8sSessionManager) Release(ctx context.Context, namespace, service, sessionID string) error

Release cleanly deletes the ConfigMap if held by sessionID.

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.

Jump to

Keyboard shortcuts

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