session

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package session contains client-side primitives for treating a labeled Workspace as a paddock-tui session: list/create/end/watch and template-default annotations.

A "session" is just a Workspace with the SessionLabel set to "true". All cluster-side state introduced by paddock-tui lives in three keys: one label and two annotations.

Index

Constants

View Source
const (
	// SessionLabel marks a Workspace as a paddock-tui session.
	SessionLabel = "paddock.dev/session"

	// SessionLabelTrue is the value set on the SessionLabel for sessions.
	SessionLabelTrue = "true"

	// DefaultTemplateAnnotation records the HarnessTemplate the session
	// was created against. Used as a fallback when LastTemplate is unset.
	DefaultTemplateAnnotation = "paddock.dev/session-default-template"

	// LastTemplateAnnotation records the last HarnessTemplate actually
	// used by a HarnessRun in this session. The TUI updates this on
	// every prompt submission and on the `template` palette command.
	// Falls back to DefaultTemplate when missing.
	LastTemplateAnnotation = "paddock.dev/session-last-template"
)
View Source
const DescriptionAnnotation = "paddock.dev/description"

DescriptionAnnotation lets template authors surface a one-line blurb in paddock-tui's picker. Optional; image is the fallback.

Variables

This section is empty.

Functions

func DefaultTemplate

func DefaultTemplate(ws *paddockv1alpha1.Workspace) string

DefaultTemplate returns the session's default template annotation (empty string when unset).

func End

func End(ctx context.Context, c client.Client, ns, name string) error

End deletes a session-labeled Workspace. Refuses to delete a Workspace that isn't a session — paddock-tui only manages its own labeled workspaces.

func IsSession

func IsSession(ws *paddockv1alpha1.Workspace) bool

IsSession reports whether a Workspace carries the session label.

func LastTemplate

func LastTemplate(ws *paddockv1alpha1.Workspace) string

LastTemplate returns the session's last-used template annotation, falling back to DefaultTemplate when LastTemplate is unset.

func Watch

func Watch(ctx context.Context, c client.Client, ns string, interval time.Duration) (<-chan Event, error)

Watch polls List(ns) at the given interval and emits Add/Update/ Delete events on the returned channel. The channel closes when ctx is done. We poll rather than use a controller-runtime informer so the client side stays small and dependency-light. interval=0 falls back to one second.

Types

type CreateOptions

type CreateOptions struct {
	Namespace   string
	Name        string
	Template    string            // HarnessTemplate name; recorded as default + last template.
	StorageSize resource.Quantity // PVC size; required.
	SeedRepoURL string            // optional; if set, becomes spec.seed.repos[0].URL.
	SeedBranch  string            // optional.
}

CreateOptions parameterises Create. Name is required; Namespace is resolved from the kubeconfig at command time and threaded through.

type Event

type Event struct {
	Type    EventType
	Session Session
}

Event is a single session-watch update.

type EventType

type EventType string

EventType labels a watch event.

const (
	EventAdd    EventType = "Add"
	EventUpdate EventType = "Update"
	EventDelete EventType = "Delete"
)

type Session

type Session struct {
	Name            string
	Namespace       string
	DefaultTemplate string
	LastTemplate    string
	Phase           paddockv1alpha1.WorkspacePhase
	ActiveRunRef    string
	TotalRuns       int32
	LastActivity    time.Time
	CreationTime    time.Time
	ResourceVersion string
}

Session is a TUI-shaped projection of a labeled Workspace. It carries only what the TUI needs and is safe to copy across goroutines.

func Create

func Create(ctx context.Context, c client.Client, opts CreateOptions) (Session, error)

Create creates a new session-labeled Workspace and returns its Session projection. Does not wait for the Workspace controller to finish seeding — callers that need that should watch separately.

func FromWorkspace

func FromWorkspace(ws *paddockv1alpha1.Workspace) Session

FromWorkspace converts a Workspace to its Session projection.

func List

func List(ctx context.Context, c client.Client, ns string) ([]Session, error)

List returns sessions in ns, filtered by SessionLabel and sorted by LastActivity desc (CreationTime as tiebreaker).

type TemplateInfo

type TemplateInfo struct {
	Name        string
	Kind        string // "HarnessTemplate" or "ClusterHarnessTemplate"
	Description string
}

TemplateInfo is a flattened view of a HarnessTemplate suited for the new-session modal.

func ListTemplates

func ListTemplates(ctx context.Context, c client.Client, ns string) ([]TemplateInfo, error)

ListTemplates returns namespaced HarnessTemplates plus all ClusterHarnessTemplates. Sorted by Name. ClusterHarnessTemplate errors are tolerated (RBAC may forbid list at cluster scope).

Jump to

Keyboard shortcuts

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