kubernetes

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 53 Imported by: 0

Documentation

Overview

Package kubernetes implements the Kubernetes protocol plugin: a Lens-grade operations cockpit rendered entirely from the manifest projection over the generic renderer. It reaches the API server with client-go either directly (kubeconfig) or through the L7 (http_proxy) agent, which injects the cluster's own ServiceAccount credentials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyYAML

func ApplyYAML(rc *plugin.RequestContext) (any, error)

ApplyYAML server-side-applies one or more manifests (a multi-document YAML stream, like `kubectl apply -f`). Each document's GVK/namespace come from the document; the RESTMapper resolves the resource. Documents apply in order; an error stops the run, leaving earlier documents applied.

func ClusterList

func ClusterList(rc *plugin.RequestContext) (any, error)

ClusterList returns the single cluster row backing the Overview dashboard.

func ClusterMetrics

func ClusterMetrics(rc *plugin.RequestContext, client plugin.ClientStream) error

ClusterMetrics streams cluster-wide CPU/memory/pod usage vs capacity. Frames degrade gracefully (metricsAvailable=false) when metrics-server is absent.

func ClusterShellStream

func ClusterShellStream(rc *plugin.RequestContext, client plugin.ClientStream) error

ClusterShellStream attaches an interactive shell to a long-lived kubectl pod, giving the operator cluster-scoped kubectl from inside the cluster. A single fixed-name pod is reused across sessions, so reconnects are instant and never pile up duplicates.

func ColumnsForKind

func ColumnsForKind(rc *plugin.RequestContext) (any, error)

ColumnsForKind returns the column definitions for a kind's list, used by the generic table's columnsSource. CRDs report their server-side printer columns; built-in kinds report their declared columns.

func Connect

func Connect(ctx context.Context, cfg plugin.ConnectConfig) (plugin.Session, error)

Connect builds the REST config for the connection's transport and wires the typed, dynamic, discovery, RESTMapper, and metrics clients over it.

func CordonNode

func CordonNode(rc *plugin.RequestContext) (any, error)

CordonNode / UncordonNode toggle a node's schedulability.

func DeleteResource

func DeleteResource(rc *plugin.RequestContext) (any, error)

func DrainNode

func DrainNode(rc *plugin.RequestContext) (any, error)

DrainNode cordons a node (Unschedulable=true) and evicts its pods through the Eviction API, honoring PodDisruptionBudgets. Mirror/static and DaemonSet pods are skipped (as kubectl drain does); bare pods are skipped unless force.

func ExecStream

func ExecStream(rc *plugin.RequestContext, client plugin.ClientStream) error

ExecStream runs an interactive exec into a pod container, bridged to the terminal panel. Exec uses a SPDY/WebSocket upgrade; over agent transport that rides the loopback bridge (upgradeConfig), so it works on both transports.

func GetResource

func GetResource(rc *plugin.RequestContext) (any, error)

GetResource returns one object for the detail/YAML view (Secrets redacted).

func GetYAML

func GetYAML(rc *plugin.RequestContext) (any, error)

GetYAML returns a resource as editable YAML (managedFields/status stripped).

func HelmRelease

func HelmRelease(rc *plugin.RequestContext) (any, error)

HelmRelease returns one release's detail (status, chart, notes).

func HelmReleases

func HelmReleases(rc *plugin.RequestContext) (any, error)

func ListResource

func ListResource(rc *plugin.RequestContext) (any, error)

ListResource lists any kind via the dynamic client (built-in GVR or CRD).

func LogsStream

func LogsStream(rc *plugin.RequestContext, client plugin.ClientStream) error

LogsStream streams a pod container's logs to the client. Pod logs are a plain chunked GET (no upgrade), so this works over both direct and agent transport through the session's REST client.

func NodeMetrics

func NodeMetrics(rc *plugin.RequestContext, client plugin.ClientStream) error

NodeMetrics streams one node's CPU/memory usage vs capacity.

func NodePods

func NodePods(rc *plugin.RequestContext) (any, error)

NodePods lists the pods scheduled on a node (for the node detail).

func PodProxyURL

func PodProxyURL(rc *plugin.RequestContext) (any, error)

PodProxyURL is the pod equivalent of ServiceProxyURL: it proxies straight to a pod's container port (a browser-usable, HTTP form of `kubectl port-forward`).

func ResourceEvents

func ResourceEvents(rc *plugin.RequestContext) (any, error)

ResourceEvents lists the events involving one object, for its detail Events tab.

func RestartResource

func RestartResource(rc *plugin.RequestContext) (any, error)

RestartResource triggers a rolling restart (the kubectl rollout-restart stamp).

func RolloutUndo

func RolloutUndo(rc *plugin.RequestContext) (any, error)

RolloutUndo rolls a Deployment back to its previous revision: it finds the owned ReplicaSet with the highest revision below the Deployment's current one and patches the Deployment's pod template back to that ReplicaSet's template.

func Routes

func Routes() []plugin.Route

Routes wires the generic, catalog-driven Kubernetes routes. One set of routes (parameterized by {kind}) serves every built-in kind and every CRD.

func ScaleResource

func ScaleResource(rc *plugin.RequestContext) (any, error)

ScaleResource sets spec.replicas on scalable workloads.

func ServiceProxyURL

func ServiceProxyURL(rc *plugin.RequestContext) (any, error)

ServiceProxyURL returns the gateway URL that proxies to a Service's web port for an "Open in browser" link. It picks the most likely web port (an http port, else an https one, else the first) unless an explicit port is given.

func TemplateYAML

func TemplateYAML(rc *plugin.RequestContext) (any, error)

TemplateYAML builds a starter manifest for a kind, derived dynamically from the resolved GroupVersionKind (and the scoped namespace) — never a hardcoded blob.

func TreeCRDGroup

func TreeCRDGroup(rc *plugin.RequestContext) (any, error)

TreeCRDGroup lists the CRD kinds belonging to one API group.

func TreeCRDs

func TreeCRDs(rc *plugin.RequestContext) (any, error)

TreeCRDs groups installed CRDs by API group under Custom Resources: a flat "Definitions" list of every CRD, then one expandable folder per group whose children are that group's kinds.

func TreeCategory

func TreeCategory(rc *plugin.RequestContext) (any, error)

TreeCategory returns a category's kinds as leaves plus any nested sub-groups (e.g. Admission Policies under Config, Gateway API under Network).

func TreeGatewayAPI

func TreeGatewayAPI(rc *plugin.RequestContext) (any, error)

TreeGatewayAPI nests the Gateway API CRD kinds under Network.

func TreeHelm

func TreeHelm(_ *plugin.RequestContext) (any, error)

TreeHelm lists the Helm sub-items (Releases; Charts/repos are out of scope).

func TreeSubgroup

func TreeSubgroup(rc *plugin.RequestContext) (any, error)

TreeSubgroup returns the kinds belonging to a nested sub-group.

func TriggerCronJob

func TriggerCronJob(rc *plugin.RequestContext) (any, error)

TriggerCronJob manually creates a Job from a CronJob's jobTemplate, mirroring `kubectl create job --from=cronjob/<name>`.

func UncordonNode

func UncordonNode(rc *plugin.RequestContext) (any, error)

func WatchResource

func WatchResource(rc *plugin.RequestContext, client plugin.ClientStream) error

WatchResource streams live ResourceEvents for a kind so the generic table/tree patches in place. It uses the API watch directly (the dynamic client's Watch), scoped to the same namespace as the list.

func WorkloadPods

func WorkloadPods(rc *plugin.RequestContext) (any, error)

WorkloadPods lists the pods a workload owns, matched by its selector labels.

Types

type ApplyRequest

type ApplyRequest struct {
	Content string `json:"content"`
	DryRun  bool   `json:"dryRun"`
}

ApplyRequest is the code_editor save body, optionally a dry-run.

type DrainRequest

type DrainRequest struct {
	GracePeriodSeconds int64 `json:"gracePeriodSeconds"`
	Force              bool  `json:"force"` // evict bare (unmanaged) pods too
}

type Plugin

type Plugin struct{}

func New

func New() *Plugin

func (*Plugin) Connect

func (p *Plugin) Connect(ctx context.Context, cfg plugin.ConnectConfig) (plugin.Session, error)

func (*Plugin) Manifest

func (p *Plugin) Manifest() plugin.Manifest

func (*Plugin) Routes

func (p *Plugin) Routes() []plugin.Route

type Row

type Row map[string]any

Row is one table/tree record: a flat field map the generic renderer displays.

type ScaleRequest

type ScaleRequest struct {
	Replicas int64 `json:"replicas"`
}

type Session

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

Session is a live connection to one Kubernetes cluster. It holds every per-connection client; the plugin struct stays stateless. Heavy machinery (informers) is opened lazily and guarded by mu.

func Unwrap

func Unwrap(sess plugin.Session) (*Session, error)

Unwrap recovers the concrete Session from a plugin.Session, looking through a wrapper (e.g. the recording layer) that exposes Session().

func (*Session) Clientset

func (s *Session) Clientset() *kubeclient.Clientset

Clientset exposes the typed client for built-in API groups.

func (*Session) Close

func (s *Session) Close() error

Close stops lazily-started machinery (watches, the upgrade bridge).

func (*Session) DefaultNamespace

func (s *Session) DefaultNamespace() string

DefaultNamespace is the connection's configured default ("" = all namespaces).

func (*Session) Discovery

Discovery exposes cached API discovery (kinds, CRDs, server version).

func (*Session) Dynamic

func (s *Session) Dynamic() dynamic.Interface

Dynamic exposes the unstructured client used for every kind, including CRDs.

func (*Session) HealthCheck

func (s *Session) HealthCheck(ctx context.Context) error

HealthCheck probes connectivity and auth with a context-bound /version call (allowed for every principal, so it never trips on a scoped credential).

func (*Session) Mapper

func (s *Session) Mapper() meta.RESTMapper

Mapper resolves a GroupVersionKind to its REST resource (and scope).

func (*Session) Metrics

func (s *Session) Metrics() *metricsclient.Clientset

Metrics exposes the metrics.k8s.io client (may be unavailable on a cluster without metrics-server; callers degrade gracefully).

func (*Session) OpenChannel

func (s *Session) OpenChannel(_ context.Context, _ plugin.ChannelRequest) (plugin.Channel, error)

OpenChannel is implemented in step 3 (pod logs/exec/port-forward); core resources stream via informer-backed watch routes, not channels.

func (*Session) ServeHTTPProxy

func (s *Session) ServeHTTPProxy(w http.ResponseWriter, r *http.Request)

ServeHTTPProxy reverse-proxies a browser request to a Service or Pod port. It reaches the workload through the pod port-forward subresource — an L4 tunnel — so the app's own Authorization/cookies pass through to the backend, which the API server's HTTP proxy would otherwise strip. The incoming path is `/{services|pods}/{ns}/{name}/{port}/{rest...}`; generic HTML/redirect/cookie rewriting and the service worker live in the shared webproxy package.

Jump to

Keyboard shortcuts

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