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
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 ¶
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 ¶
ParsePods extracts pods from an app-pods websocket frame. Non-pod frames yield nil.
func (Pod) ContainerNames ¶ added in v0.5.0
ContainerNames returns just the container names, for the -c picker.
func (Pod) ReadyCount ¶ added in v0.5.0
ReadyCount returns how many of the pod's containers are ready, and how many there are, for a kubectl-style "1/2" READY cell.