clusters

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 15 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 clusters manages one connection per kubeconfig context.

Each connection owns its informer factory, REST client, permission cache and circuit breaker, so an unreachable cluster never blocks another.

Index

Constants

View Source
const (
	DefaultIdleAfter   = 15 * time.Minute
	DefaultBreakerBase = 5 * time.Second
	DefaultBreakerMax  = 2 * time.Minute
)

Defaults from docs/04-multi-cluster.md.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthError

type AuthError struct{ Err error }

AuthError lets a connector report a credential failure that is not an apierrors type, such as an exec credential plugin exiting non-zero.

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

type Clock

type Clock interface{ Now() time.Time }

Clock is injected so lifecycle behaviour is tested without real time.

type Connector

type Connector interface {
	Connect(ctx context.Context, kctx kubeconfig.Context) (Session, error)
}

Connector opens a session for one kubeconfig context. The production implementation builds a REST config and starts informers; tests substitute a fake so no apiserver is required.

type FetchOptions

type FetchOptions struct {
	Tier Tier
}

FetchOptions controls how much is read.

type KubeConnector

type KubeConnector struct {
	Opts kubeconfig.Options
	// NewClient is swappable in tests.
	NewClient func(kctx kubeconfig.Context, opts kubeconfig.Options) (kubernetes.Interface, error)
}

KubeConnector is the production Connector. It builds a REST config per context, which is where exec credential plugins run.

func (KubeConnector) Connect

func (k KubeConnector) Connect(ctx context.Context, kctx kubeconfig.Context) (Session, error)

type Manager

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

Manager owns one connection per kubeconfig context.

Connections are independent by construction: each has its own mutex, its own circuit breaker, and its own goroutine when connecting. A cluster behind a VPN that is switched off can never block a cluster that is reachable.

func New

func New(cfg *kubeconfig.Config, connector Connector, opts Options) *Manager

New builds a Manager over every context in the kubeconfig. No connection is opened: contexts connect lazily, on first use.

func (*Manager) ClientFor

func (m *Manager) ClientFor(name string) (kubernetes.Interface, bool)

ClientFor returns the clientset behind a live connection.

func (*Manager) Close

func (m *Manager) Close()

Close drops every session.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, name string) error

Connect opens a session for one context, respecting the circuit breaker. Calling it for an already-live context is a no-op.

func (*Manager) ConnectOrder

func (m *Manager) ConnectOrder() []string

ConnectOrder returns context names with the current context first.

Launch has no cache to replay, so the environment the developer actually works in must handshake first rather than waiting behind a slow prod cluster.

func (*Manager) ReapIdle

func (m *Manager) ReapIdle() []string

ReapIdle drops informers for live connections untouched beyond the idle window. The last snapshot is retained, so the connection becomes Stale rather than NeverConnected: the data is still shown, labelled with its age.

func (*Manager) SetTier

func (m *Manager) SetTier(name string, tier Tier)

SetTier moves a context between tiers. Attention is what promotes one: the environment a tab is watching is active, and everything else is background.

func (*Manager) Status

func (m *Manager) Status(name string) (Status, bool)

Status reports one connection without blocking on it.

func (*Manager) Statuses

func (m *Manager) Statuses() []Status

Statuses reports every connection, in connect order.

func (*Manager) Tier

func (m *Manager) Tier(name string) Tier

Tier reports how much of a context is worth reading right now.

func (*Manager) Touch

func (m *Manager) Touch(name string)

Touch marks a context as in use, which defers its idle disconnect.

func (*Manager) Untouched

func (m *Manager) Untouched(d time.Duration) []string

Untouched returns the live contexts nobody has read for longer than d.

It is how a context falls back from active to background: attention promotes, and the absence of attention demotes, without anything having to announce that a tab closed.

type Options

type Options struct {
	Clock       Clock
	IdleAfter   time.Duration
	BreakerBase time.Duration
	BreakerMax  time.Duration
}

Options configures a Manager. Zero values take the documented defaults.

type Scope

type Scope struct {
	ClusterWide bool
	Namespaces  []string
	// Reason explains a fallback, e.g. a forbidden cluster-scoped list.
	Reason string
}

Scope records how much of a cluster kubeside was allowed to read.

A refused cluster-scoped list is a normal answer, not an error: no Kubernetes API enumerates the namespaces a user may access, so discovery falls back and the UI names the mode it ended up in.

func (Scope) String

func (s Scope) String() string

type Session

type Session interface{ Close() error }

Session is a live connection's resources. Closing it drops informers while the manager keeps the last snapshot.

type Snapshot

type Snapshot struct {
	Context string
	Scope   Scope
	Apps    []apps.App
	// Partial lists kinds that could not be read, so the UI can say what is
	// missing instead of implying the cluster has none of them.
	Partial []string
}

Snapshot is one cluster's app list at a point in time.

func Fetch

Fetch lists workloads for one connected context and groups them.

Errors on individual kinds are recorded rather than fatal: a developer who can read Deployments but not CronJobs should still see their Deployments.

The tier decides how much is read. Pods are the most expensive collection in any real cluster and the one only the active environment needs, so a background read skips them and says so rather than implying those apps have no replicas.

type State

type State int

State is what kubeside knows about one cluster right now.

NeverConnected and Stale are deliberately separate. docs/04-multi-cluster.md is explicit that "I have not reached this cluster yet" and "here is data from 14:02" are different facts, and conflating them during an incident is the worst failure this product could have.

const (
	// StateNeverConnected: no successful connection this session. Nothing is
	// known. Never render this as an empty result set.
	StateNeverConnected State = iota
	// StateConnecting: a connection attempt is in flight.
	StateConnecting
	// StateLive: informers are running and data is current.
	StateLive
	// StateStale: connected earlier, now disconnected. The last snapshot is
	// retained and must always be labelled with its age.
	StateStale
	// StateUnreachable: the attempt failed for a network or DNS reason. Often
	// just a VPN that is off, which is normal rather than exceptional.
	StateUnreachable
	// StateUnauthorized: credentials were rejected or expired. Distinct from
	// unreachable because the fix is different and the UI prompts inline.
	StateUnauthorized
)

func (State) HasData

func (s State) HasData() bool

HasData reports whether anything is known about the cluster. It is the guard the UI uses before rendering a panel's contents.

func (State) String

func (s State) String() string

type Status

type Status struct {
	Context  string
	State    State
	LastLive time.Time
	// Age is how old the retained snapshot is. Only meaningful when State is
	// Stale; the UI prints it next to the data.
	Age time.Duration
	Err error
	// RetryAfter is when the circuit breaker will allow another attempt.
	RetryAfter time.Time
}

Status is a point-in-time snapshot of one connection, safe to hand to the UI.

type Tier

type Tier int

Tier is how much of a cluster is worth reading right now.

const (
	// TierBackground is an environment nobody is looking at. It contributes to
	// the promotion matrix, which needs versions rather than per-replica
	// health, so its pods go unread.
	TierBackground Tier = iota
	// TierActive is the environment on screen: everything health is derived
	// from, pods included.
	TierActive
)

func (Tier) String

func (t Tier) String() string

Jump to

Keyboard shortcuts

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