cliutil

package
v0.0.59 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package cliutil holds the CR-agnostic plumbing shared by seictl's `network` and `node` command trees: the -o printer, the metav1.Status error discipline, kubeconfig/namespace resolution, and the --set/--override/--genesis-override expression parsers. Everything here is independent of which GVK a tree binds (that lives in internal/seiapi plus each tree's gvk.go); the per-tree render() functions differ only in their discrete flags and apply-time auto-wiring.

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is stamped onto the seictl.sei.io/version provenance annotation by both command trees' render(). Linker override:

-ldflags "-X 'github.com/sei-protocol/seictl/internal/cliutil.Version=$VERSION'"

`make build` wires version.json; bare `go build`/`go test` see "dev".

Functions

func ApplyGenesisOverride

func ApplyGenesisOverride(root map[string]interface{}, expr string, fieldPath ...string) error

ApplyGenesisOverride writes a single key=value pair into the string-keyed JSON-valued map at fieldPath (for SeiNetwork this is spec.genesis.overrides). The key is a dotted cosmos-module path (module.field[.field...]) — the first segment must be a key in app_state of the genesis JSON. Value parses as JSON if it parses (number, bool, object, array, or JSON-quoted string); otherwise it's stored as a raw string.

Distinct from ApplyOverride because the genesis-overrides map's value type is map[string]<JSON> rather than map[string]string, and the key shape is validated upstream by the sidecar's applyGenesisOverrides. Single-segment keys are rejected here so the user sees the issue at apply time rather than after the network has stalled retrying the assemble-genesis task.

func ApplyOverride

func ApplyOverride(root map[string]interface{}, expr string, fieldPath ...string) error

ApplyOverride writes a single key=value pair into the string-keyed map at fieldPath (for SeiNode this is spec.overrides). Keys may contain dots because the overrides map's keys are themselves dotted TOML paths.

func ApplySet

func ApplySet(root map[string]interface{}, expr string) error

ApplySet writes a single dotted-path --set expression. Each segment is a map key, optionally suffixed with `[N]` to step into a list at index N after the key. Empty intermediate maps and lists are created on demand.

List-index rules:

  • idx == len(list) appends a new element (extends the list by one).
  • idx < len(list) sets in place on the existing element.
  • idx > len(list) errors; sparse indices are not supported.

func EmitStatus

func EmitStatus(w io.Writer, err error)

EmitStatus writes err as a metav1.Status so callers can `jq -r .reason` to discriminate failure classes. Wraps non-Status errors as InternalError.

func MakePrinter

func MakePrinter(format string) (printers.ResourcePrinter, error)

MakePrinter returns a printer for -o values: yaml (default), json, name (kind/name), jsonpath=<template>. Anything else is a usage error the caller surfaces via EmitStatus.

func MatchPhase

func MatchPhase(obj *unstructured.Unstructured, until string) (bool, error)

MatchPhase decides whether a single CR event satisfies the --until condition. Returns (true, nil) on match, (false, error) on terminal Failed phase, (false, nil) otherwise so the watch keeps streaming. The CR-agnostic mechanism each tree shares; the legal --until set differs per tree and is validated at parse time (see ValidatePhase).

func NewClient

func NewClient(cfg *rest.Config) (client.Client, error)

NewClient builds a controller-runtime client for unstructured SSA; no scheme registration needed since GVK is read off the object.

func ParseGenesisAccount

func ParseGenesisAccount(entry string) (string, string, error)

ParseGenesisAccount parses a `<address>:<balance>` --genesis-account entry. The balance side accepts the standard cosmos coin format (one or more `<int><denom>` separated by commas — e.g. `1000usei,500uatom`).

func RunWatch

func RunWatch(ctx context.Context, cfg *rest.Config, gvr schema.GroupVersionResource, ns, name, until string, timeout time.Duration, out io.Writer) error

RunWatch streams every event for the named resource as one NDJSON line on out, returning nil when MatchPhase(obj, until) is satisfied and a metav1.Status-shaped error on timeout / terminal Failed / API error.

func ToStatus

func ToStatus(err error) *metav1.Status

ToStatus extracts an apiserver metav1.Status from err (walking %w wraps), or synthesizes an InternalError for a plain Go error.

func UsageError

func UsageError(format string, args ...interface{}) error

UsageError reports CLI validation failures as Status{Reason:Invalid} (BadRequest) so the stderr discriminator above still works.

func ValidatePhase

func ValidatePhase(until string, legal []string) error

ValidatePhase rejects an --until value not in the resource's phase enum at parse time, so an illegal phase is a crisp Invalid usage error rather than a full-timeout wait. legal lists the allowed phases for the message.

func WatchExitError

func WatchExitError(err error, name, ns, until string, timeout time.Duration) error

WatchExitError shapes the err that came out of UntilWithSync into a metav1.Status so stderr discrimination (`jq -r .reason`) covers timeout / NotFound / terminal-Failed-phase / transient API failure uniformly.

Types

type Kubeconfig

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

Kubeconfig honors --kubeconfig, $KUBECONFIG colon-merge, in-cluster fallback, and kubectl namespace precedence (override > context > "default") through a single deferred loader.

func LoadKubeconfig

func LoadKubeconfig(explicitPath, namespaceOverride string) *Kubeconfig

LoadKubeconfig builds a deferred loader from an explicit path (or the standard resolution chain when empty) and an optional -n override.

func (*Kubeconfig) Namespace

func (k *Kubeconfig) Namespace() (string, error)

Namespace resolves the effective namespace (override > context > "default").

func (*Kubeconfig) RESTConfig

func (k *Kubeconfig) RESTConfig() (*rest.Config, error)

RESTConfig resolves the loader to a *rest.Config.

Jump to

Keyboard shortcuts

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