reconcile

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImageKeyLabel     = "hatchctl.reconcile.image-key"
	ContainerKeyLabel = "hatchctl.reconcile.container-key"
)

Variables

View Source
var (
	ErrObservedTargetNotFound = errors.New("observed runtime target not found")
	ErrObservedStateStale     = errors.New("observed runtime target changed before action")
)
View Source
var ErrContainerObservationMissing = errors.New("container observation is required for reconcile")
View Source
var ErrInvalidLifecyclePhase = errors.New("invalid lifecycle phase")

Functions

func ContainerKey

func ContainerKey(resolved devcontainer.ResolvedConfig, imageIdentity string, bridgeEnabled bool, sshAgent bool) (string, error)

func DotfilesNeedsInstall

func DotfilesNeedsInstall(state storefs.WorkspaceState, cfg capdot.Config) bool

func EnsureContainerHasSSHAgent

func EnsureContainerHasSSHAgent(inspect *backend.ContainerInspect) error

func LifecycleKey

func LifecycleKey(resolved devcontainer.ResolvedConfig, containerKey string, dotfiles DotfilesConfig) (string, error)

func LifecycleStateApplied

func LifecycleStateApplied(state storefs.WorkspaceState, desiredKey string) bool

func ManagedImageKey

func ManagedImageKey(resolved devcontainer.ResolvedConfig, targetImage string) (string, error)

func NormalizeLifecyclePhase

func NormalizeLifecyclePhase(requested string) (string, error)

func RedactSensitiveMap

func RedactSensitiveMap(values map[string]string) map[string]string

func ShouldAllocateTTY

func ShouldAllocateTTY(stdin io.Reader, stdout io.Writer) bool

Types

type BridgeDoctorOptions

type BridgeDoctorOptions struct {
	Debug bool
	IO    CommandStreams
}

type BuildOptions

type BuildOptions struct {
	Debug bool
	IO    CommandStreams
}

type BuildResult

type BuildResult struct {
	Image string `json:"image"`
}

type CapabilityState

type CapabilityState struct {
	SSHAgentAttached bool
	BridgeEnabled    bool
	DotfilesApplied  bool
	UIDRemapDesired  bool
}

type CommandStreams

type CommandStreams struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	Events ui.Sink
}

type ContainerAction

type ContainerAction string
const (
	ContainerActionReuse   ContainerAction = "reuse"
	ContainerActionStart   ContainerAction = "start"
	ContainerActionCreate  ContainerAction = "create"
	ContainerActionReplace ContainerAction = "replace"
)

type ContainerPlan

type ContainerPlan struct {
	Action       ContainerAction
	ContainerID  string
	Observed     *backend.ContainerInspect
	DesiredKey   string
	Reused       bool
	NeedsCleanup bool
}

func PlanContainer

func PlanContainer(observed ObservedState, desired DesiredContainer) (ContainerPlan, error)

type ControlState

type ControlState struct {
	WorkspaceState  storefs.WorkspaceState
	Coordination    storefs.CoordinationRecord
	PlanCachePath   string
	PlanCacheExists bool
}

type DesiredContainer

type DesiredContainer struct {
	ReuseKey string
	ForceNew bool
}

type DesiredImage

type DesiredImage struct {
	TargetImage string
	BuildMode   ImageBuildMode
	ReuseKey    string
	Verify      bool
}

type DesiredLifecycle

type DesiredLifecycle struct {
	Key       string
	Requested string
	Dotfiles  DotfilesConfig
	Created   bool
}

type DotfilesConfig

type DotfilesConfig = capability.Dotfiles

type DotfilesStatus

type DotfilesStatus struct {
	Configured     bool   `json:"configured"`
	Applied        bool   `json:"applied"`
	NeedsInstall   bool   `json:"needsInstall"`
	Repository     string `json:"repository,omitempty"`
	InstallCommand string `json:"installCommand,omitempty"`
	TargetPath     string `json:"targetPath,omitempty"`
}

func DotfilesStatusFromState

func DotfilesStatusFromState(state storefs.WorkspaceState, cfg capdot.Config) *DotfilesStatus

type ExecOptions

type ExecOptions struct {
	Args      []string
	RemoteEnv map[string]string
	Debug     bool
	IO        CommandStreams
}

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor(client backend.Client) *Executor

func NewExecutorWithIO

func NewExecutorWithIO(client backend.Client, stdin io.Reader, stdout io.Writer, stderr io.Writer) *Executor

func (*Executor) BridgeDoctor

func (e *Executor) BridgeDoctor(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts BridgeDoctorOptions) (bridge.Report, error)

func (*Executor) Build

func (e *Executor) Build(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts BuildOptions) (BuildResult, error)

func (*Executor) EnrichMergedConfig

func (e *Executor) EnrichMergedConfig(ctx context.Context, resolved *devcontainer.ResolvedConfig, image string) error

func (*Executor) EnsureUpdatedUIDContainer

func (e *Executor) EnsureUpdatedUIDContainer(ctx context.Context, resolved devcontainer.ResolvedConfig, image string, containerID string, events ui.Sink) error

func (*Executor) Exec

func (e *Executor) Exec(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts ExecOptions) (int, error)

func (*Executor) ExecRequest added in v0.7.0

func (e *Executor) ExecRequest(ctx context.Context, observed ObservedState, stdin bool, tty bool, extraEnv map[string]string, command []string, streams backend.Streams) (backend.ExecRequest, error)

func (*Executor) InspectImageArchitecture

func (e *Executor) InspectImageArchitecture(ctx context.Context, image string) (string, error)

func (*Executor) InspectImageUser

func (e *Executor) InspectImageUser(ctx context.Context, image string) (string, error)

func (*Executor) Materialize

func (e *Executor) Materialize(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, debug bool, events ui.Sink, phase string, label string) (devcontainer.ResolvedConfig, error)

func (*Executor) PrepareObservedSession

func (e *Executor) PrepareObservedSession(ctx context.Context, opts ObservedSessionOptions) (*Session, error)

func (*Executor) ReadConfig

func (e *Executor) ReadConfig(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts ReadConfigOptions) (ReadConfigResult, error)

func (*Executor) ReconcileContainer

func (e *Executor) ReconcileContainer(ctx context.Context, observed ObservedState, resolved devcontainer.ResolvedConfig, image string, imagePlan ImagePlan, bridgeEnabled bool, sshAgent bool, forceNew bool, events ui.Sink) (string, string, bool, error)

func (*Executor) ReconcileImage

func (e *Executor) ReconcileImage(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, resolved devcontainer.ResolvedConfig, events ui.Sink) (string, ImagePlan, error)

func (*Executor) RunLifecycle

func (e *Executor) RunLifecycle(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts RunLifecycleOptions) (RunLifecycleResult, error)

func (*Executor) RunLifecyclePlan

func (e *Executor) RunLifecyclePlan(ctx context.Context, observed ObservedState, state storefs.WorkspaceState, dotfiles capdot.Config, allowHostLifecycle bool, events ui.Sink, plan LifecyclePlan) error

func (*Executor) SetTrustedSigners added in v0.6.13

func (e *Executor) SetTrustedSigners(signers []security.TrustedSigner)

func (*Executor) Up

func (e *Executor) Up(ctx context.Context, workspacePlan workspaceplan.WorkspacePlan, opts UpOptions) (UpResult, error)

func (*Executor) VerificationCheck

func (e *Executor) VerificationCheck() func(context.Context, string) security.VerificationResult

func (*Executor) VerifyResolvedFeatures

func (e *Executor) VerifyResolvedFeatures(resolved devcontainer.ResolvedConfig, events ui.Sink) error

func (*Executor) WithTrustedSigners added in v0.6.16

func (e *Executor) WithTrustedSigners(signers []security.TrustedSigner) *Executor

type ExitError

type ExitError struct {
	Code int
}

func (ExitError) Error

func (e ExitError) Error() string

type ImageAction

type ImageAction string
const (
	ImageActionUseTarget   ImageAction = "use-target"
	ImageActionReuseTarget ImageAction = "reuse-target"
	ImageActionBuildTarget ImageAction = "build-target"
)

type ImageBuildMode

type ImageBuildMode string
const (
	ImageBuildModeNone     ImageBuildMode = "none"
	ImageBuildModeBuild    ImageBuildMode = "build"
	ImageBuildModeFeatures ImageBuildMode = "features"
	ImageBuildModeProject  ImageBuildMode = "project"
)

type ImagePlan

type ImagePlan struct {
	Action      ImageAction
	TargetImage string
	BuildMode   ImageBuildMode
	ReuseKey    string
	Verify      bool
}

func PlanImage

func PlanImage(desired DesiredImage, observed *backend.ImageInspect) ImagePlan

type LifecyclePhase

type LifecyclePhase string
const (
	LifecyclePhaseNone   LifecyclePhase = ""
	LifecyclePhaseCreate LifecyclePhase = "create"
	LifecyclePhaseAll    LifecyclePhase = "all"
)

type LifecyclePlan

type LifecyclePlan struct {
	RunCreate      bool
	RunStart       bool
	RunAttach      bool
	Key            string
	TransitionKind LifecyclePhase
	NeedsRecovery  bool
}

func PlanLifecycleCommand

func PlanLifecycleCommand(observed ObservedState, desired DesiredLifecycle) (LifecyclePlan, error)

func PlanUpLifecycle

func PlanUpLifecycle(observed ObservedState, desired DesiredLifecycle) LifecyclePlan

type ManagedContainer

type ManagedContainer struct {
	ID            string            `json:"id"`
	Name          string            `json:"name,omitempty"`
	Image         string            `json:"image,omitempty"`
	Status        string            `json:"status,omitempty"`
	Running       bool              `json:"running"`
	RemoteUser    string            `json:"remoteUser,omitempty"`
	ContainerEnv  map[string]string `json:"containerEnv,omitempty"`
	Labels        map[string]string `json:"labels,omitempty"`
	ForwardPorts  []string          `json:"forwardPorts,omitempty"`
	MetadataCount int               `json:"metadataCount"`
	BridgeEnabled bool              `json:"bridgeEnabled,omitempty"`
}

type ObserveRequest

type ObserveRequest struct {
	Plan               workspaceplan.WorkspacePlan
	Resolved           devcontainer.ResolvedConfig
	ImageRef           string
	LoadControlState   bool
	ObserveTarget      bool
	InspectTarget      bool
	ObserveImage       bool
	AllowMissingTarget bool
}

type ObservedSessionOptions

type ObservedSessionOptions struct {
	Plan                  workspaceplan.WorkspacePlan
	Resolved              devcontainer.ResolvedConfig
	Debug                 bool
	Events                ui.Sink
	Enrich                bool
	LoadState             bool
	FindContainer         bool
	AllowMissingContainer bool
	InspectContainer      bool
}

type ObservedState

type ObservedState struct {
	Plan       workspaceplan.WorkspacePlan
	Resolved   devcontainer.ResolvedConfig
	Target     RuntimeTarget
	Control    ControlState
	Capability CapabilityState
	Container  *backend.ContainerInspect
	Image      *backend.ImageInspect
	ImageRef   string
	ReadTarget ReadToken
}

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

func NewObserver

func NewObserver(runtime observerBackend) *Observer

func (*Observer) Observe

func (o *Observer) Observe(ctx context.Context, req ObserveRequest) (ObservedState, error)

func (*Observer) RevalidateReadToken

func (o *Observer) RevalidateReadToken(ctx context.Context, observed ObservedState) error

type ReadConfigOptions

type ReadConfigOptions struct {
	Debug bool
	IO    CommandStreams
}

type ReadConfigResult

type ReadConfigResult struct {
	WorkspaceFolder      string            `json:"workspaceFolder"`
	ConfigPath           string            `json:"configPath"`
	WorkspaceMount       string            `json:"workspaceMount"`
	SourceKind           string            `json:"sourceKind"`
	HasInitializeCommand bool              `json:"hasInitializeCommand"`
	HasCreateCommand     bool              `json:"hasCreateCommand"`
	HasStartCommand      bool              `json:"hasStartCommand"`
	HasAttachCommand     bool              `json:"hasAttachCommand"`
	Image                string            `json:"image"`
	ImageUser            string            `json:"imageUser,omitempty"`
	ContainerName        string            `json:"containerName"`
	StateDir             string            `json:"stateDir"`
	CacheDir             string            `json:"cacheDir"`
	RemoteUser           string            `json:"remoteUser,omitempty"`
	ContainerUser        string            `json:"containerUser,omitempty"`
	RemoteEnv            map[string]string `json:"remoteEnv,omitempty"`
	ContainerEnv         map[string]string `json:"containerEnv,omitempty"`
	Mounts               []string          `json:"mounts,omitempty"`
	ForwardPorts         []string          `json:"forwardPorts,omitempty"`
	Bridge               *bridge.Report    `json:"bridge,omitempty"`
	Dotfiles             *DotfilesStatus   `json:"dotfiles,omitempty"`
	MetadataCount        int               `json:"metadataCount"`
	ManagedContainer     *ManagedContainer `json:"managedContainer,omitempty"`
}

type ReadToken

type ReadToken struct {
	TargetKind             TargetKind
	ContainerName          string
	ComposeProject         string
	ComposeService         string
	PrimaryContainer       string
	CoordinationGeneration int64
}

type RunLifecycleOptions

type RunLifecycleOptions struct {
	Phase string
	Debug bool
	IO    CommandStreams
}

type RunLifecycleResult

type RunLifecycleResult struct {
	ContainerID string `json:"containerId"`
	Phase       string `json:"phase"`
}

type RuntimeTarget

type RuntimeTarget struct {
	Kind             TargetKind
	Image            string
	ContainerName    string
	ComposeProject   string
	ComposeService   string
	PrimaryContainer string
	Containers       []backend.ContainerInspect
}

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) ContainerID

func (s *Session) ContainerID() string

func (*Session) ContainerInspect

func (s *Session) ContainerInspect() *backend.ContainerInspect

func (*Session) EffectiveRemoteUser

func (s *Session) EffectiveRemoteUser(ctx context.Context) (string, error)

func (*Session) Image

func (s *Session) Image() string

func (*Session) ManagedContainer

func (s *Session) ManagedContainer(ctx context.Context) (*ManagedContainer, error)

func (*Session) Observed

func (s *Session) Observed() ObservedState

func (*Session) Resolved

func (s *Session) Resolved() devcontainer.ResolvedConfig

func (*Session) RevalidateReadTarget

func (s *Session) RevalidateReadTarget(ctx context.Context) error

func (*Session) SetContainerID

func (s *Session) SetContainerID(containerID string)

func (*Session) SetContainerInspect

func (s *Session) SetContainerInspect(inspect *backend.ContainerInspect)

func (*Session) SetResolved

func (s *Session) SetResolved(resolved devcontainer.ResolvedConfig)

func (*Session) SetState

func (s *Session) SetState(state storefs.WorkspaceState)

func (*Session) State

func (s *Session) State() storefs.WorkspaceState

type StateTracker

type StateTracker struct {
	// contains filtered or unexported fields
}

func LoadStateTracker added in v0.8.1

func LoadStateTracker(stateDir string) (*StateTracker, error)

func NewStateTracker

func NewStateTracker(stateDir string, state storefs.WorkspaceState) *StateTracker

func (*StateTracker) ApplyContainer

func (t *StateTracker) ApplyContainer(containerID string, containerKey string, created bool)

func (*StateTracker) BeginBridge

func (t *StateTracker) BeginBridge(kind string, key string)

func (*StateTracker) BeginContainer

func (t *StateTracker) BeginContainer(containerID string, containerKey string)

func (*StateTracker) BeginDotfiles

func (t *StateTracker) BeginDotfiles(kind string, key string)

func (*StateTracker) BeginLifecycle

func (t *StateTracker) BeginLifecycle(kind LifecyclePhase, key string)

func (*StateTracker) BeginPlannedLifecycle

func (t *StateTracker) BeginPlannedLifecycle(plan LifecyclePlan, installDotfiles bool)

func (*StateTracker) CompleteDotfiles

func (t *StateTracker) CompleteDotfiles(dotfiles DotfilesConfig)

func (*StateTracker) CompleteLifecycle

func (t *StateTracker) CompleteLifecycle(key string, dotfiles DotfilesConfig)

func (*StateTracker) CompletePlannedLifecycle

func (t *StateTracker) CompletePlannedLifecycle(plan LifecyclePlan, dotfiles DotfilesConfig, installDotfiles bool)

func (*StateTracker) DisableBridge

func (t *StateTracker) DisableBridge()

func (*StateTracker) EnableBridge

func (t *StateTracker) EnableBridge(sessionID string)

func (*StateTracker) Persist

func (t *StateTracker) Persist() error

func (*StateTracker) SetBridge

func (t *StateTracker) SetBridge(enabled bool, sessionID string)

func (*StateTracker) SetContainer

func (t *StateTracker) SetContainer(containerID string, containerKey string)

func (*StateTracker) SetTrustedRefs added in v0.6.8

func (t *StateTracker) SetTrustedRefs(refs []string)

func (*StateTracker) State

func (t *StateTracker) State() storefs.WorkspaceState

type TargetKind

type TargetKind string
const (
	TargetKindManagedContainer TargetKind = "managed-container"
	TargetKindComposeService   TargetKind = "compose-service"
)

type UpOptions

type UpOptions struct {
	Recreate bool
	Debug    bool
	IO       CommandStreams
}

type UpResult

type UpResult struct {
	ContainerID           string         `json:"containerId"`
	Image                 string         `json:"image"`
	RemoteWorkspaceFolder string         `json:"remoteWorkspaceFolder"`
	StateDir              string         `json:"stateDir"`
	Bridge                *bridge.Report `json:"bridge,omitempty"`
}

Jump to

Keyboard shortcuts

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