appstate

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

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

This section is empty.

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 last message read (useful for --debug and for refining the parser). An app with no running pods yields (nil, raw, nil).

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