kubernetes

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package kubernetes runs services on a Kubernetes cluster through kubectl, so it uses whatever auth the user's kubeconfig has. It never falls back to the current context: the environment names it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(env core.Env, c *spec.Component) (any, error)

func TextTable

func TextTable(s string) core.Table

TextTable splits kubectl's column output into a table; anything else becomes one column.

Types

type HelmSection

type HelmSection struct {
	Chart   string   `yaml:"chart"` // a path, repo/name or oci:// reference
	Version string   `yaml:"version"`
	Release string   `yaml:"release"` // default: the service name
	Values  []string `yaml:"values"`  // values files, relative to the project
	// Set are --set values; $TAG, $NAMESPACE and the environment's manifest vars are filled in.
	Set map[string]string `yaml:"set"`
	// Where rig puts what it builds and scales, e.g. image.repository, image.tag, replicaCount.
	ImageKey    string `yaml:"image_key"`
	TagKey      string `yaml:"tag_key"`
	ReplicasKey string `yaml:"replicas_key"`
}

HelmSection deploys a service with a Helm chart instead of manifests (`helm:` on the service). Status, logs, scale and the rest still work through k8s.workload, which names what the chart creates (charts often call it <release>-<chart>).

type Options

type Options struct {
	Context string `yaml:"context"`
	// Server finds the context by its cluster's API address when machines name it differently
	Server    string `yaml:"server"`
	Namespace string `yaml:"namespace"`
	Registry  string `yaml:"registry"`
	// PullRegistry is the registry as the cluster's nodes name it, when that differs from where
	// builds push (registry.local vs registry.local:80, say).
	PullRegistry    string            `yaml:"pull_registry"`
	Manifests       []string          `yaml:"manifests"`
	Vars            map[string]string `yaml:"vars"`
	Env             map[string]string `yaml:"env"`
	CreateNamespace bool              `yaml:"create_namespace"`
	StateConfigMap  string            `yaml:"state_configmap"`
	// Debug gives service containers SYS_PTRACE, so dlv in the image (the go builder's debug) can attach.
	Debug          bool   `yaml:"debug"`
	NodeShellImage string `yaml:"node_shell_image"`
}

type Runtime

type Runtime struct {
	Opt Options

	// HostIP is the address pods use to reach this machine; set by runtimes that know it (kind).
	HostIP func(ctx context.Context) (string, error)
	// contains filtered or unexported fields
}

func (*Runtime) Actions

func (r *Runtime) Actions() []core.Action

func (*Runtime) ApplyManifests

func (r *Runtime) ApplyManifests(ctx context.Context, objs []*manifest.Object) error

ApplyManifests applies objects as they are written, with the environment's manifest variables filled in: what rig would deploy, for objects no service owns (or before one does).

func (*Runtime) Bridge

func (r *Runtime) Bridge(ctx context.Context, s *spec.Service, ports map[int]string) error

Bridge creates a selector-less Service named after s whose Endpoints are the given addresses, so pods reach a service running on the host (or in docker) by its usual name.

func (*Runtime) Close

func (r *Runtime) Close() error

func (*Runtime) Deploy

func (r *Runtime) Deploy(ctx context.Context, s *spec.Service, rel core.Release) error

func (*Runtime) Discover

func (r *Runtime) Discover(ctx context.Context) ([]core.Workload, error)

func (*Runtime) Exec

func (r *Runtime) Exec(ctx context.Context, s *spec.Service, o core.ExecOptions) error

func (*Runtime) Forward

func (r *Runtime) Forward(ctx context.Context, t core.Target) (string, error)

func (*Runtime) Hosts

func (r *Runtime) Hosts(ctx context.Context) ([]core.Host, error)

func (*Runtime) Init

func (r *Runtime) Init() error

Init checks options; adapters embedding Runtime call it after filling Opt.

func (*Runtime) InjectedEnv

func (r *Runtime) InjectedEnv(s *spec.Service) map[string]bool

InjectedEnv names the env vars a deploy of s adds from rig.yaml, which a manifest synced back from the cluster should not take in.

func (*Runtime) KubectlArgs

func (r *Runtime) KubectlArgs() []string

KubectlArgs point kubectl at this environment's cluster and namespace.

func (*Runtime) LiveEnv

func (r *Runtime) LiveEnv(ctx context.Context, s *spec.Service) (map[string]string, error)

LiveEnv is the first container's env on the cluster; values from secrets and config maps show where they come from.

func (*Runtime) LiveObject

func (r *Runtime) LiveObject(ctx context.Context, kind, name string) ([]byte, error)

LiveObject is one object of the namespace as JSON (`kubectl get -o json`).

func (*Runtime) LiveObjects

func (r *Runtime) LiveObjects(ctx context.Context) ([]byte, error)

LiveObjects are the namespace's objects as YAML documents, stripped of what the cluster adds (status, managed fields, defaults no one set); objects another object owns are left out.

func (*Runtime) LoadState

func (r *Runtime) LoadState(ctx context.Context) (map[string]string, error)

func (*Runtime) Logs

func (r *Runtime) Logs(ctx context.Context, s *spec.Service, o core.LogOptions) (<-chan core.LogLine, error)

func (*Runtime) Objects

func (r *Runtime) Objects(s *spec.Service) ([]*manifest.Object, *manifest.Object, error)

Objects returns what a deploy of s applies: its own manifest files, or the workload found in the environment's manifest folders with everything bundled with it, or nil when it has neither.

func (*Runtime) QueryLanguage

func (r *Runtime) QueryLanguage() string

func (*Runtime) Registry

func (r *Runtime) Registry() string

func (*Runtime) Render

func (r *Runtime) Render(ctx context.Context, s *spec.Service, rel core.Release) ([]byte, error)

Render produces the YAML Deploy would apply.

func (*Runtime) Resources

func (r *Runtime) Resources(ctx context.Context, s *spec.Service) ([]core.Resources, error)

func (*Runtime) Restart

func (r *Runtime) Restart(ctx context.Context, s *spec.Service) error

func (*Runtime) RunQuery

func (r *Runtime) RunQuery(ctx context.Context, q string) (core.Table, error)

func (*Runtime) SaveState

func (r *Runtime) SaveState(ctx context.Context, m map[string]string) error

func (*Runtime) Scale

func (r *Runtime) Scale(ctx context.Context, s *spec.Service, n int) error

func (*Runtime) SetAutoscale

func (r *Runtime) SetAutoscale(ctx context.Context, s *spec.Service, b core.Bounds) error

SetAutoscale moves the bounds of the HPA that scales s, or creates one (named after the workload) scaling on b's CPU and memory targets when there is none.

func (*Runtime) SetEnv

func (r *Runtime) SetEnv(env core.Env)

func (*Runtime) SetResources

func (r *Runtime) SetResources(ctx context.Context, s *spec.Service, res core.Resources) error

SetResources runs `kubectl set resources` on one container; empty values stay as they are.

func (*Runtime) Shell

func (r *Runtime) Shell(ctx context.Context, host string, command []string) (*exec.Cmd, error)

Shell opens a root shell on a node through a privileged debug pod.

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context, s *spec.Service) error

func (*Runtime) Status

func (r *Runtime) Status(ctx context.Context, s *spec.Service) (core.Status, error)

func (*Runtime) StatusAll

func (r *Runtime) StatusAll(ctx context.Context, svcs []*spec.Service) ([]core.Status, error)

StatusAll reads every workload and pod of the namespace in one kubectl call; usage comes from a cached `kubectl top`, so a TUI refreshing every few seconds costs one process per refresh.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context, s *spec.Service) error

type Section

type Section struct {
	Workload  string   `yaml:"workload"`
	Container string   `yaml:"container"`
	Service   string   `yaml:"service"`
	Manifests []string `yaml:"manifests"`
	Command   []string `yaml:"command"`
	Args      []string `yaml:"args"`
}

Section is a service's k8s: block.

Jump to

Keyboard shortcuts

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