config

package
v0.7.3 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: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSyncthingVersion       = "v1.29.7"
	DefaultSyncthingRescanSeconds = 300
	DefaultSidecarImageRepository = "ghcr.io/acmore/okdev"
	DefaultSidecarImageFallback   = "edge"
	DefaultWorkspacePVCSize       = "50Gi"
)
View Source
const (
	DefaultWorkspacePath = "/workspace"
	DefaultWorkspaceName = "workspace"
)
View Source
const (
	PortDirectionForward = "forward"
	PortDirectionReverse = "reverse"
)
View Source
const (
	DefaultFile = ".okdev.yaml"
	FolderFile  = ".okdev/okdev.yaml"
	LegacyFile  = "okdev.yaml"
)
View Source
const (
	SnapshotVersion           = "v1"
	AnnotationLastAppliedSpec = "okdev.io/last-applied-spec"
	AnnotationLastAppliedHash = "okdev.io/last-applied-spec-sha256"
)

Variables

View Source
var DefaultMigrations = []Migration{
	workspaceToVolumesMigration(),
	pytorchjobWorkerInjectMigration(),
}

DefaultMigrations is the ordered list of all config migrations.

Functions

func BuiltinTemplateLocalIgnores added in v0.2.20

func BuiltinTemplateLocalIgnores(ref string) []string

func BuiltinTemplateNames added in v0.2.11

func BuiltinTemplateNames() []string

BuiltinTemplateNames returns the list of available built-in template names.

func CoerceVariableValue added in v0.7.0

func CoerceVariableValue(v TemplateVariable, raw string) (any, error)

CoerceVariableValue converts a string value to the declared variable type.

func ComputeManifestSHA256 added in v0.4.2

func ComputeManifestSHA256(path string) (string, error)

func DefaultSidecarImageForBinaryVersion added in v0.2.0

func DefaultSidecarImageForBinaryVersion(binaryVersion string) string

func ManifestDir added in v0.3.5

func ManifestDir(configPath string) string

func ProjectTemplateNames added in v0.7.0

func ProjectTemplateNames(dir string) ([]string, error)

ProjectTemplateNames returns template names found in <dir>/.okdev/templates.

func RenderEmbeddedTemplate added in v0.3.1

func RenderEmbeddedTemplate(path string, vars *TemplateVars) (string, error)

func RenderTemplate added in v0.2.11

func RenderTemplate(ref string, vars *TemplateVars) (string, error)

RenderTemplate resolves a template by ref and renders it with the given vars.

func RenderTemplateContent added in v0.7.0

func RenderTemplateContent(name, raw string, vars *TemplateVars, customVars map[string]any) (string, error)

RenderTemplateContent renders raw template content with built-in fields plus custom variables exposed as .Vars.

func RenderTemplateContext added in v0.3.0

func RenderTemplateContext(ctx context.Context, ref string, vars *TemplateVars) (string, error)

RenderTemplateContext resolves a template by ref and renders it with the given vars.

func RenderTemplateWithVars added in v0.7.0

func RenderTemplateWithVars(ctx context.Context, ref string, vars *TemplateVars, customVars map[string]any, projDir string) (string, error)

RenderTemplateWithVars resolves and renders a template with built-in fields plus custom variables exposed as .Vars.

func ResolveLocalAgentPath added in v0.3.0

func ResolveLocalAgentPath(path string) (string, error)

func ResolvePath

func ResolvePath(configPath string) (string, error)

func ResolveTemplate added in v0.2.11

func ResolveTemplate(ref string) (string, error)

ResolveTemplate loads raw template content from a built-in name, file path, or URL.

func ResolveTemplateAssetFromDir added in v0.7.0

func ResolveTemplateAssetFromDir(ctx context.Context, templateRef, assetRef, projDir string) (string, error)

ResolveTemplateAssetFromDir resolves a companion template asset declared by frontmatter. Relative asset paths are resolved next to the selected template.

func ResolveTemplateContext added in v0.3.0

func ResolveTemplateContext(ctx context.Context, ref string) (string, error)

ResolveTemplateContext loads raw template content from a built-in name, file path, or URL.

func ResolveTemplateFromDir added in v0.7.0

func ResolveTemplateFromDir(ctx context.Context, ref, projDir string) (string, error)

ResolveTemplateFromDir resolves a template with project-local directory awareness.

func ResolveVariables added in v0.7.0

func ResolveVariables(meta *TemplateMeta, sets map[string]string, stored map[string]any) (map[string]any, error)

ResolveVariables resolves template variables from flags, stored values, and defaults.

func ResolveWorkloadManifestPath added in v0.3.5

func ResolveWorkloadManifestPath(configPath, manifestPath string) string

func RootDir added in v0.3.4

func RootDir(configPath string) string

func STIgnorePreset added in v0.3.0

func STIgnorePreset(name string) []string

func UserTemplateNames added in v0.3.1

func UserTemplateNames() ([]string, error)

Types

type AgentAuth added in v0.3.0

type AgentAuth struct {
	Env       string `yaml:"env,omitempty"`
	LocalPath string `yaml:"localPath,omitempty"`
}

type AgentSpec added in v0.3.0

type AgentSpec struct {
	Name string     `yaml:"name"`
	Auth *AgentAuth `yaml:"auth,omitempty"`
}

type DevEnvSpec

type DevEnvSpec struct {
	Namespace   string           `yaml:"namespace"`
	KubeContext string           `yaml:"kubeContext"`
	Template    *TemplateRef     `yaml:"template,omitempty"`
	Session     SessionSpec      `yaml:"session"`
	Agents      []AgentSpec      `yaml:"agents,omitempty"`
	Workload    WorkloadSpec     `yaml:"workload"`
	Volumes     []corev1.Volume  `yaml:"volumes"`
	Workspace   *LegacyWorkspace `yaml:"workspace,omitempty"`
	Sync        SyncSpec         `yaml:"sync"`
	Ports       []PortMapping    `yaml:"ports"`
	SSH         SSHSpec          `yaml:"ssh"`
	Lifecycle   LifecycleSpec    `yaml:"lifecycle"`
	Sidecar     SidecarSpec      `yaml:"sidecar"`
	PodTemplate PodTemplateRef   `yaml:"podTemplate"`
}

type DevEnvironment

type DevEnvironment struct {
	APIVersion string     `yaml:"apiVersion"`
	Kind       string     `yaml:"kind"`
	Metadata   Metadata   `yaml:"metadata"`
	Spec       DevEnvSpec `yaml:"spec"`
}

DevEnvironment is the top-level config structure for .okdev.yaml.

func Load

func Load(configPath string) (*DevEnvironment, string, error)

func (*DevEnvironment) EffectiveVolumes added in v0.2.4

func (d *DevEnvironment) EffectiveVolumes() []corev1.Volume

func (*DevEnvironment) EffectiveWorkloadInject added in v0.7.3

func (d *DevEnvironment) EffectiveWorkloadInject() []WorkloadInjectSpec

func (*DevEnvironment) EffectiveWorkspaceMountPath added in v0.3.4

func (d *DevEnvironment) EffectiveWorkspaceMountPath(configPath string) string

func (*DevEnvironment) SetDefaults

func (d *DevEnvironment) SetDefaults()

func (*DevEnvironment) Validate

func (d *DevEnvironment) Validate() error

func (*DevEnvironment) WorkspaceMountPath added in v0.2.4

func (d *DevEnvironment) WorkspaceMountPath() string

type LastAppliedWorkloadSpec added in v0.4.2

type LastAppliedWorkloadSpec struct {
	Version            string                      `json:"version"`
	WorkloadKind       string                      `json:"workloadKind"`
	Workload           WorkloadSpec                `json:"workload"`
	PodTemplate        PodTemplateRef              `json:"podTemplate"`
	Volumes            []corev1.Volume             `json:"volumes"`
	SidecarImage       string                      `json:"sidecarImage"`
	SidecarResources   corev1.ResourceRequirements `json:"sidecarResources,omitempty"`
	WorkspaceMountPath string                      `json:"workspaceMountPath"`
	TargetContainer    string                      `json:"targetContainer"`
	Tmux               bool                        `json:"tmux"`
	PreStop            string                      `json:"preStop"`
	ManifestPath       string                      `json:"manifestPath,omitempty"`
	ManifestSHA256     string                      `json:"manifestSHA256,omitempty"`
}

func BuildWorkloadSnapshot added in v0.4.2

func BuildWorkloadSnapshot(cfg *DevEnvironment, workspaceMountPath, targetContainer string, tmux bool, preStop, manifestPath, manifestResolvedPath string) LastAppliedWorkloadSpec

func ParseLastAppliedWorkloadSpec added in v0.4.2

func ParseLastAppliedWorkloadSpec(raw string) (LastAppliedWorkloadSpec, error)

func (*LastAppliedWorkloadSpec) JSON added in v0.4.2

func (s *LastAppliedWorkloadSpec) JSON() (string, error)

func (*LastAppliedWorkloadSpec) SHA256 added in v0.4.2

func (s *LastAppliedWorkloadSpec) SHA256() (string, error)

type LegacyWorkspace added in v0.2.4

type LegacyWorkspace struct {
	MountPath string            `yaml:"mountPath"`
	PVC       map[string]string `yaml:"pvc"`
}

LegacyWorkspace exists only to produce a clear migration error for removed config.

type LifecycleSpec added in v0.2.0

type LifecycleSpec struct {
	PostCreate string `yaml:"postCreate"`
	PostSync   string `yaml:"postSync"`
	PreStop    string `yaml:"preStop"`
}

type Metadata

type Metadata struct {
	Name string `yaml:"name"`
}

type MetadataMap

type MetadataMap struct {
	Labels map[string]string `yaml:"labels"`
}

type Migration added in v0.2.11

type Migration struct {
	Name        string
	Description string
	Applies     func(doc *yaml.Node) bool
	Transform   func(doc *yaml.Node) (warnings []string, err error)
}

Migration defines a single config transformation.

type MigrationEligibleError added in v0.2.11

type MigrationEligibleError struct {
	Err error
}

MigrationEligibleError wraps validation errors that can be fixed by okdev migrate.

func (*MigrationEligibleError) Error added in v0.2.11

func (e *MigrationEligibleError) Error() string

func (*MigrationEligibleError) Unwrap added in v0.2.11

func (e *MigrationEligibleError) Unwrap() error

type MigrationResult added in v0.2.11

type MigrationResult struct {
	Applied  []string // names of applied migrations
	Warnings []string // warnings from ambiguous transforms
}

MigrationResult holds the outcome of running migrations.

func RunMigrations added in v0.2.11

func RunMigrations(doc *yaml.Node, migrations []Migration) (*MigrationResult, error)

RunMigrations runs all applicable migrations sequentially. Each migration checks Applies() before running Transform().

type PodTemplateRef

type PodTemplateRef struct {
	Metadata MetadataMap    `yaml:"metadata"`
	Spec     corev1.PodSpec `yaml:"spec"`
}

type PortMapping

type PortMapping struct {
	Name      string `yaml:"name"`
	Local     int    `yaml:"local"`
	Remote    int    `yaml:"remote"`
	Direction string `yaml:"direction,omitempty"`
}

func (PortMapping) EffectiveDirection added in v0.3.0

func (p PortMapping) EffectiveDirection() string

type PortVar added in v0.2.11

type PortVar struct {
	Name   string
	Local  int
	Remote int
}

type SSHSpec

type SSHSpec struct {
	User              string `yaml:"user"`
	PrivateKeyPath    string `yaml:"privateKeyPath"`
	AutoDetectPorts   *bool  `yaml:"autoDetectPorts"`
	ForwardAgent      *bool  `yaml:"forwardAgent"`
	InterPod          *bool  `yaml:"interPod"`
	PersistentSession *bool  `yaml:"persistentSession"`
	KeepAliveInterval int    `yaml:"keepAliveIntervalSeconds"`
	KeepAliveTimeout  int    `yaml:"keepAliveTimeoutSeconds"`
	KeepAliveCountMax int    `yaml:"keepAliveCountMax"`
}

func (SSHSpec) ForwardAgentEnabled added in v0.6.1

func (s SSHSpec) ForwardAgentEnabled() bool

func (SSHSpec) InterPodEnabled added in v0.7.3

func (s SSHSpec) InterPodEnabled() bool

func (SSHSpec) PersistentSessionEnabled added in v0.2.0

func (s SSHSpec) PersistentSessionEnabled() bool

type SessionSpec

type SessionSpec struct {
	DefaultNameTemplate string `yaml:"defaultNameTemplate"`
	TTLHours            int    `yaml:"ttlHours"`
	IdleTimeoutMinutes  int    `yaml:"idleTimeoutMinutes"`
}

type SidecarSpec added in v0.2.0

type SidecarSpec struct {
	Image     string                      `yaml:"image"`
	Resources corev1.ResourceRequirements `yaml:"resources,omitempty"`
}

type SyncSpec

type SyncSpec struct {
	Paths         []string      `yaml:"paths"`
	PreservePaths []string      `yaml:"preservePaths"`
	Engine        string        `yaml:"engine"`
	Syncthing     SyncthingSpec `yaml:"syncthing"`
}

type SyncthingSpec

type SyncthingSpec struct {
	Version               string `yaml:"version"`
	AutoInstall           *bool  `yaml:"autoInstall"`
	Image                 string `yaml:"image"`
	RescanIntervalSeconds int    `yaml:"rescanIntervalSeconds"`
	WatcherDelaySeconds   int    `yaml:"watcherDelaySeconds"`
	RelaysEnabled         bool   `yaml:"relaysEnabled"`
	Compression           bool   `yaml:"compression"`
}

func (SyncthingSpec) AutoInstallEnabled

func (s SyncthingSpec) AutoInstallEnabled() bool

type TemplateFile added in v0.7.0

type TemplateFile struct {
	Path     string `yaml:"path"`
	Template string `yaml:"template"`
}

TemplateFile declares an additional file rendered by okdev init.

type TemplateMeta added in v0.7.0

type TemplateMeta struct {
	Name        string             `yaml:"name"`
	Description string             `yaml:"description"`
	Variables   []TemplateVariable `yaml:"variables"`
	Files       []TemplateFile     `yaml:"files"`
}

TemplateMeta holds optional frontmatter metadata from a template file.

func ParseFrontmatter added in v0.7.0

func ParseFrontmatter(raw string) (*TemplateMeta, string, error)

ParseFrontmatter extracts YAML frontmatter from a template string.

type TemplateRef added in v0.7.0

type TemplateRef struct {
	Name string         `yaml:"name"`
	Vars map[string]any `yaml:"vars,omitempty"`
}

TemplateRef records which template and variable values produced this config.

type TemplateVariable added in v0.7.0

type TemplateVariable struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Type        string `yaml:"type"`
	Default     any    `yaml:"default,omitempty"`
}

TemplateVariable declares a custom variable that a template accepts.

func (TemplateVariable) HasDefault added in v0.7.0

func (v TemplateVariable) HasDefault() bool

HasDefault returns true when a default value was declared.

type TemplateVars added in v0.2.11

type TemplateVars struct {
	Name             string
	Namespace        string
	KubeContext      string
	User             string
	Repo             string
	DevImage         string
	DevCPURequest    string
	DevMemoryRequest string
	DevCPULimit      string
	DevMemoryLimit   string
	SidecarImage     string
	SidecarCPU       string
	SidecarMemory    string
	SyncthingVersion string
	SyncLocal        string
	SyncRemote       string
	SSHUser          string
	Ports            []PortVar
	WorkloadType     string
	ManifestPath     string
	InjectPaths      []string
	AttachContainer  string
	GenericPreset    string
	TTLHours         int
}

TemplateVars holds all variables available to templates.

func NewTemplateVars added in v0.2.11

func NewTemplateVars() *TemplateVars

NewTemplateVars returns TemplateVars with sensible defaults.

type WorkloadAttachSpec added in v0.3.0

type WorkloadAttachSpec struct {
	Container string `yaml:"container,omitempty"`
}

type WorkloadInjectSpec added in v0.3.0

type WorkloadInjectSpec struct {
	Path       string `yaml:"path,omitempty"`
	Sidecar    *bool  `yaml:"sidecar,omitempty"`
	Attachable *bool  `yaml:"attachable,omitempty"`
}

type WorkloadSpec added in v0.3.0

type WorkloadSpec struct {
	Type         string               `yaml:"type"`
	ManifestPath string               `yaml:"manifestPath,omitempty"`
	Inject       []WorkloadInjectSpec `yaml:"inject,omitempty"`
	Attach       WorkloadAttachSpec   `yaml:"attach,omitempty"`
}

Jump to

Keyboard shortcuts

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