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
- type AuthError
- type Clock
- type Connector
- type FetchOptions
- type KubeConnector
- type Manager
- func (m *Manager) ClientFor(name string) (kubernetes.Interface, bool)
- func (m *Manager) Close()
- func (m *Manager) Connect(ctx context.Context, name string) error
- func (m *Manager) ConnectOrder() []string
- func (m *Manager) ReapIdle() []string
- func (m *Manager) SetTier(name string, tier Tier)
- func (m *Manager) Status(name string) (Status, bool)
- func (m *Manager) Statuses() []Status
- func (m *Manager) Tier(name string) Tier
- func (m *Manager) Touch(name string)
- func (m *Manager) Untouched(d time.Duration) []string
- type Options
- type Scope
- type Session
- type Snapshot
- type State
- type Status
- type Tier
Constants ¶
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.
type Connector ¶
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 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) Connect ¶
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 ¶
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 ¶
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 ¶
SetTier moves a context between tiers. Attention is what promotes one: the environment a tab is watching is active, and everything else is background.
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.
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 ¶
func Fetch(ctx context.Context, c kubernetes.Interface, kctx kubeconfig.Context, opts FetchOptions) (Snapshot, error)
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 // unreachable because the fix is different and the UI prompts inline. StateUnauthorized )
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 )