state

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state keeps the Installations a user has made: the catalog of saved selections, stored in one file.

Index

Constants

View Source
const (
	KindDemo = "kind"
	Cluster  = "cluster"
)
View Source
const (
	// DefaultClusterName is the name of the first demo's kind cluster.
	DefaultClusterName = "kubrix-demo"
)

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir is $XDG_CONFIG_HOME/kubrix, else ~/.config/kubrix (also on macOS, like gh), and %AppData%\kubrix on Windows.

Types

type Catalog

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

Catalog is the user's saved Installations: demos on kind clusters and installs on existing clusters.

A Catalog that could not read its file is empty, reports why through Problem, and refuses to write, so the unreadable file is never overwritten.

func Open

func Open(dir string) *Catalog

Open reads the catalog in dir. A missing file is an empty catalog; an empty dir is an unavailable one.

func (*Catalog) ClusterNameFree

func (c *Catalog) ClusterNameFree(name, original string) error

ClusterNameFree checks that name can name a kind cluster for a demo. original is the key of the demo being rerun, which may keep its own name.

func (*Catalog) Clusters

func (c *Catalog) Clusters() []string

Clusters returns the keys of the installs on existing clusters, most recently used first.

func (*Catalog) Demos

func (c *Catalog) Demos() []string

Demos returns the keys of the demos, most recently used first.

func (*Catalog) Find

func (c *Catalog) Find(key string) (Installation, bool)

Find returns the installation with the key (kind cluster name or kube context).

func (*Catalog) Forget

func (c *Catalog) Forget(key string) error

Forget removes the installation from the catalog.

func (*Catalog) FreeClusterName

func (c *Catalog) FreeClusterName() string

FreeClusterName returns the first kind cluster name of kubrix-demo, kubrix-demo-2, ... that no installation uses.

func (*Catalog) Keys

func (c *Catalog) Keys() []string

Keys returns the keys of all installations, most recently used first.

func (*Catalog) Last

func (c *Catalog) Last() (Installation, bool)

Last is the installation used most recently, of either kind.

func (*Catalog) Len

func (c *Catalog) Len() int

Len is the number of saved installations.

func (*Catalog) NewDemo

func (c *Catalog) NewDemo() Installation

NewDemo returns the selections a new demo starts from: those of the last demo, without its repository, and with a kind cluster name that is free.

func (*Catalog) NewInstall

func (c *Catalog) NewInstall(context string) (Installation, bool)

NewInstall returns the selections an install on the kube context starts from, and whether the context was installed to before. A rerun keeps everything. A new context starts from the last install on a cluster, without what belongs to that cluster (repository, domain, excluded apps, version). Without one, only the personal choices of the last demo carry over.

func (*Catalog) Problem

func (c *Catalog) Problem() error

Problem is why the saved installations could not be read, or nil.

func (*Catalog) Record

func (c *Catalog) Record(st Installation) error

Record saves the installation and makes it the most recently used one. It does not replace an installation of the other kind that has the same key.

type Installation

type Installation struct {
	Kind           string   `json:"kind,omitempty"`
	GitHost        string   `json:"gitHost,omitempty"`
	Org            string   `json:"org,omitempty"`
	Repo           string   `json:"repo,omitempty"`
	GitUserName    string   `json:"gitUserName,omitempty"`
	TargetType     string   `json:"targetType,omitempty"`
	UpstreamRepo   string   `json:"upstreamRepo,omitempty"`
	UpstreamBranch string   `json:"upstreamBranch,omitempty"`
	ClusterName    string   `json:"clusterName,omitempty"`
	Context        string   `json:"context,omitempty"`
	Domain         string   `json:"domain,omitempty"`
	DNSProvider    string   `json:"dnsProvider,omitempty"`
	CloudProvider  string   `json:"cloudProvider,omitempty"`
	ExcludedApps   []string `json:"excludedApps,omitempty"`
}

Installation holds one installation's selections. It deliberately has no token or DNS credential field.

func (Installation) IsCluster

func (st Installation) IsCluster() bool

func (Installation) Key

func (st Installation) Key() string

Key identifies an installation: the kind cluster name for demos, the kube context otherwise.

func (Installation) Where

func (st Installation) Where() string

Where says where the platform runs, e.g. "kind cluster kubrix-demo" or "context prod".

Jump to

Keyboard shortcuts

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