appstate

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: GPL-3.0 Imports: 9 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 appstate reads an app's live pods from the Darkube app-pods websocket.

Pods are not exposed over REST (`state.pods` is empty), and the app-state socket carries only aggregate replica counts. The console sources pod names from a separate stream:

wss://api.hamravesh.com/ws/app-pods/?app_id=<id>
Sec-WebSocket-Protocol: json, <console-jwt-access>, <org-slug>

which streams "app_pods_update" frames whose "data" array holds the pods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WatchPods added in v0.7.0

func WatchPods(ctx context.Context, opts Options, onPods func([]Pod) error) error

WatchPods streams the app's pods, calling onPods with the full pod list each time the server sends one, until ctx ends or the connection drops.

The socket is the console's live view: it pushes a fresh app_pods_update on every change to any pod — confirmed 2026-09-27 by watching a rollout go from one pod to two to one. Each frame carries every pod, not a delta, which is why the callback gets the whole list. Frames that carry no pods (the empty list the server sends for an app that has none, and any other message type) are passed through as an empty list, so a caller can show "no pods" as a state.

Types

type Container added in v0.5.0

type Container struct {
	Name         string `json:"name"`
	State        string `json:"state,omitempty"`
	Ready        bool   `json:"ready"`
	RestartCount int    `json:"restart_count"`
	LastState    string `json:"last_state,omitempty"`
}

Container is one container of a pod, with the health the stream reports for it. RestartCount is the counter kubectl shows in its RESTARTS column, and is the fastest way to spot a crash loop the aggregate app state hides behind a steady "not ready".

type Options

type Options struct {
	BaseURL     string // https base; converted to wss
	AccessToken string // Console JWT access token (2nd subprotocol value)
	Org         string // X-Organization slug (3rd subprotocol value)
	AppID       string
	Debug       bool // dump raw JSON messages to stderr
}

Options configures an app-state fetch.

type Pod

type Pod struct {
	Name        string      `json:"name"`
	Namespace   string      `json:"namespace,omitempty"`
	Phase       string      `json:"phase,omitempty"`
	State       string      `json:"state,omitempty"`
	Ready       bool        `json:"ready"`
	Terminating bool        `json:"terminating,omitempty"`
	CreatedAt   time.Time   `json:"created_at,omitzero"`
	Containers  []Container `json:"containers,omitempty"`
}

Pod is a running pod of an app.

func FetchPods

func FetchPods(ctx context.Context, opts Options) ([]Pod, []byte, error)

FetchPods connects to the app-state websocket and returns the app's pods. It also returns the raw JSON of the frame it used (useful for --debug and for refining the parser). An app with no running pods yields (nil, raw, nil).

The first frame after connecting is not to be trusted. Observed 2026-09-27, three connections out of three during a rollout: the server first sends a stale list — one pod, missing the replacement being brought up — and the complete one 100-200ms later. Taking the first frame is what made `get pods` show one pod while the rollout had two, and exec/logs pick their pod from the same read. So the read carries on for settleWindow after the first pod list and returns the last one seen.

func ParsePods

func ParsePods(data []byte) []Pod

ParsePods extracts pods from an app-pods websocket frame. Non-pod frames yield nil.

func (Pod) ContainerNames added in v0.5.0

func (p Pod) ContainerNames() []string

ContainerNames returns just the container names, for the -c picker.

func (Pod) ReadyCount added in v0.5.0

func (p Pod) ReadyCount() (int, int)

ReadyCount returns how many of the pod's containers are ready, and how many there are, for a kubectl-style "1/2" READY cell.

func (Pod) Restarts added in v0.5.0

func (p Pod) Restarts() int

Restarts returns the highest restart count across the pod's containers, which is what a crash loop shows up as.

Jump to

Keyboard shortcuts

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