config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config loads ynf's own config.yaml (ADR-009): found in the home factory folder by the same lookup as lanes, validated against the published schema, with defaults applied.

Index

Constants

View Source
const File = "config.yaml"

File is the config file name in a factory folder.

Variables

This section is empty.

Functions

func Find

func Find(home string) (path string, shadowed []string, err error)

Find returns the config file in the first home factory folder that has one.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads a size such as 64MiB: a whole number and KiB, MiB or GiB.

Types

type Config

type Config struct {
	Version int      `yaml:"version"`
	Repos   []string `yaml:"repos"`
	// Factory names the configuration repository, which enrols repositories instead of Repos.
	Factory *struct {
		Repo string `yaml:"repo"`
	} `yaml:"factory"`
	Store   string `yaml:"store"`
	WorkDir string `yaml:"work_dir"`
	Owner   string `yaml:"owner"`
	GitHub  struct {
		TokenEnv string `yaml:"token_env"`
		Author   *struct {
			Name  string `yaml:"name"`
			Email string `yaml:"email"`
		} `yaml:"author"`
	} `yaml:"github"`
	Lease struct {
		TTL       string `yaml:"ttl"`
		Heartbeat string `yaml:"heartbeat"`
	} `yaml:"lease"`
	Poll struct {
		CI     string `yaml:"ci"`
		Review string `yaml:"review"`
	} `yaml:"poll"`
	// Executor inline declares this instance runs inside containment the operator provides, such
	// as the factory image as a job (ADR-007): every run is inline, as InlineUser.
	Executor   string `yaml:"executor"`
	InlineUser string `yaml:"inline_user"`
	Images     struct {
		Build *bool `yaml:"build"`
	} `yaml:"images"`
	Memory *struct {
		Provider  string `yaml:"provider"`
		Namespace string `yaml:"namespace"`
		Cwd       string `yaml:"cwd"`
		// Transport is cli (the ynm CLI, a store chosen by cwd) or http (a hosted ynm at
		// Endpoint, with the bearer token in TokenEnv): the shared store for a pool or CI.
		Transport string `yaml:"transport"`
		Endpoint  string `yaml:"endpoint"`
		TokenEnv  string `yaml:"token_env"`
		// Level is personal or distributed; over http it defaults to distributed, since a hosted
		// store keeps nothing at the personal level.
		Level string `yaml:"level"`
	} `yaml:"memory"`

	// Telemetry is where ynf and its runs write OpenTelemetry, and whether ynf starts ynr serve for
	// a factory job (ADR-009, ADR-011). Without it, ynf writes where the environment says.
	Telemetry *struct {
		// Spool is the spool root: factory/ for ynf, runs/<run id>/ for each run, and
		// manifests/<run id>.json.
		Spool string `yaml:"spool"`
		// RunQuota is how large a run's folder may grow, such as 64MiB.
		RunQuota  string `yaml:"run_quota"`
		Collector *struct {
			Enabled  bool   `yaml:"enabled"`
			ID       string `yaml:"id"`
			Instance string `yaml:"instance"`
			Upstream string `yaml:"upstream"`
			// Archive is how long ynr serve has at a job's end to ship what is left.
			Archive string `yaml:"archive"`
		} `yaml:"collector"`
	} `yaml:"telemetry"`

	Path     string   `yaml:"-"` // the file it was loaded from
	Shadowed []string `yaml:"-"` // other candidates found at the same level
}

Config is a loaded config.

func Load

func Load(path string) (*Config, error)

Load reads and validates a config file and applies defaults.

func (*Config) Author

func (c *Config) Author() (name, email string)

Author returns the git identity for ynf's commits.

func (*Config) Dir

func (c *Config) Dir() string

Dir is the folder the config was loaded from; relative paths in it resolve against this.

func (*Config) Durations

func (c *Config) Durations() (ttl, heartbeat, ci, review time.Duration, err error)

Durations returns the lease TTL, heartbeat and poll intervals.

func (*Config) MemorySettings

func (c *Config) MemorySettings() (enabled *bool, namespace, cwd string)

MemorySettings returns whether memory is wanted (nil means detect), the namespace template ({repo} is host/owner/name), and the folder ynm runs from, which picks its store.

func (*Config) MemoryTransport

func (c *Config) MemoryTransport() (transport, endpoint, tokenEnv, level string)

MemoryTransport returns how ynf reaches ynm (cli or http), the endpoint and token variable for http, and the level it writes at.

func (*Config) SQLitePath

func (c *Config) SQLitePath() (string, error)

SQLitePath returns the database path for a sqlite:// store.

func (*Config) StoreKind

func (c *Config) StoreKind() string

StoreKind is the store's scheme: sqlite, s3 or dynamodb.

func (*Config) TelemetrySettings

func (c *Config) TelemetrySettings(getenv func(string) string) (TelemetrySettings, error)

TelemetrySettings is the telemetry block, resolved: the spool root as an absolute path, the run quota, and the collector with its upstream filled from the operator's OpenTelemetry environment when the block names none. getenv reads that environment. It is an error for the collector to be enabled with no upstream: ynr serve has nowhere to ship until it has an object store of its own.

func (*Config) Token

func (c *Config) Token() (string, error)

Token returns the GitHub token from the configured variable, falling back to `gh auth token`.

func (*Config) WorkPath

func (c *Config) WorkPath() string

WorkPath is the absolute work folder.

type TelemetrySettings

type TelemetrySettings struct {
	Root      string // the spool root, absolute; empty when none is configured
	Quota     int64  // bytes a run's folder may hold; 0 is the default
	Collector spool.Collector
}

TelemetrySettings is the telemetry block, resolved.

Jump to

Keyboard shortcuts

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