blocknode

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVethNotFound is returned by Resolve when no host interface has an ifindex
	// matching the pod's eth0 iflink. The host-side veth may not yet be visible
	// (Cilium is still setting up the veth pair); callers should retry.
	ErrVethNotFound = errorx.ExternalError.New("host veth not yet visible for pod iflink")

	// ErrVethNotReady is returned (via errors.Join) when exec into the pod fails
	// because the container is not yet started or is not exec-capable. Callers
	// should retry after the pod reaches ContainersReady.
	ErrVethNotReady = errorx.ExternalError.New("pod container not ready for veth iflink exec")
)

Functions

This section is empty.

Types

type BlockNodeHandler added in v0.22.1

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

BlockNodeHandler implements daemonkit.ComponentHandler for all block-node HTTP routes under the /block_node/ prefix.

To add a new monitor for the block-node component:

  1. Add a field for the monitor and its state func to this struct.
  2. Register the new route(s) in RegisterRoutes.
  3. Implement the handler method(s) on *BlockNodeHandler.

func NewBlockNodeHandler added in v0.22.1

func NewBlockNodeHandler(mon *TrafficShaperMonitor, trafficShaperStateFn func() daemonkit.MonitorState) *BlockNodeHandler

NewBlockNodeHandler constructs a BlockNodeHandler. mon and trafficShaperStateFn may be nil when the traffic-shaper monitor is disabled.

func (*BlockNodeHandler) RegisterRoutes added in v0.22.1

func (h *BlockNodeHandler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes implements daemonkit.ComponentHandler. All routes are prefixed with /block_node/.

Current routes:

GET /block_node/traffic_shaper/status — traffic-shaper monitor health

type ComponentConfig

type ComponentConfig struct {
	TrafficShaperEnabled bool

	// KubeconfigPath is the path to the BN-scoped kubeconfig. Required when
	// TrafficShaperEnabled is true (used to exec into BN pods to resolve veths).
	KubeconfigPath string

	// Namespace is the Kubernetes namespace (orbit) where BN pods run.
	// Required when TrafficShaperEnabled is true.
	Namespace string
}

ComponentConfig holds inputs needed to build the block-node component.

type ComponentResult

type ComponentResult struct {
	// Monitors is the ordered slice of monitors to run under the supervisor.
	Monitors []daemonkit.MonitorRunner

	// TrafficShaperMonitor is non-nil when the traffic-shaper monitor is enabled.
	// daemon.go uses this to construct BlockNodeHandler with the correct
	// trafficShaperStateFn closure after the component's StatusTracker is created.
	TrafficShaperMonitor *TrafficShaperMonitor
}

ComponentResult contains the monitors built by NewComponent and a reference to the TrafficShaperMonitor (when enabled) so daemon.go can wire the HTTP handler with the per-component StatusTracker closure after the component is assembled.

func NewComponent

func NewComponent(cfg ComponentConfig) (ComponentResult, error)

NewComponent constructs all enabled monitors for the block-node component and returns them alongside any references needed for HTTP handler wiring.

type Endpoint added in v0.23.0

type Endpoint struct {
	Address string `json:"address"`
	Port    string `json:"port"`
}

Endpoint is one side (local or remote) of a NetworkConnection. Port is a string because the BN reports "*" (any port) alongside numeric ports, and Address may be a single IP or a CIDR (e.g. "10.10.1.0/24").

type NetworkConnection added in v0.23.0

type NetworkConnection struct {
	Local       Endpoint `json:"local"`
	Remote      Endpoint `json:"remote"`
	Category    string   `json:"category"`
	TLSRequired bool     `json:"tls_required"`
}

NetworkConnection is one active endpoint reported by a statusz endpoint. Category is left as the raw BN string here — mapping categories to policy names and nft sets is a separate concern from reading the endpoint.

type NetworkData added in v0.23.0

type NetworkData struct {
	ActiveEndpoints []NetworkConnection `json:"active_endpoints"`
}

NetworkData is the decoded payload of a statusz endpoint: the set of active endpoints the BN currently reports.

type StatuszClient added in v0.23.0

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

StatuszClient reads a Block Node's statusz REST/JSON endpoints.

func NewStatuszClient added in v0.23.0

func NewStatuszClient(baseURL string) *StatuszClient

NewStatuszClient returns a StatuszClient that reads statusz endpoints under baseURL (e.g. "http://10.0.0.5:8080"), using an HTTP client with a bounded per-request timeout.

func (*StatuszClient) InboundClients added in v0.23.0

func (c *StatuszClient) InboundClients(ctx context.Context) (NetworkData, error)

InboundClients fetches GET {base}/statusz/inbound-clients and decodes the NetworkData payload.

func (*StatuszClient) OutboundClients added in v0.23.0

func (c *StatuszClient) OutboundClients(ctx context.Context) (NetworkData, error)

OutboundClients fetches GET {base}/statusz/outbound-clients and decodes the NetworkData payload.

type TrafficShaperMonitor added in v0.22.1

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

TrafficShaperMonitor is the daemonkit.MonitorRunner for the block-node traffic-shaper workflow. It owns two long-lived responsibilities that run concurrently under Run:

  • the pod-lifecycle watcher (resolves host-side veths and installs/rebinds ingress HTB qdiscs — implemented in #748/#749), and
  • the statusz poll loop (diffs statusz membership against live nft sets and applies deltas — implemented in #751/#752/#754/#755).

Each responsibility is independently retried with exponential back-off so a fault in one cannot stop the other or crash the daemon.

func NewTrafficShaperMonitor added in v0.22.1

func NewTrafficShaperMonitor(resolver *VethResolver) *TrafficShaperMonitor

NewTrafficShaperMonitor constructs a TrafficShaperMonitor with the given VethResolver. The resolver is wired into runPodWatcher by #748; it is held here so #748 can use it without further constructor changes.

func (*TrafficShaperMonitor) Name added in v0.22.1

func (m *TrafficShaperMonitor) Name() string

Name implements daemonkit.MonitorRunner.

func (*TrafficShaperMonitor) Run added in v0.22.1

Run implements daemonkit.MonitorRunner. It starts the pod-lifecycle watcher and the statusz poll loop concurrently and blocks until ctx is cancelled. It always returns nil: subsystem faults are absorbed by superviseResponsibility, so the only way Run returns is a clean ctx cancellation.

type TrafficShaperStatusResponse added in v0.22.1

type TrafficShaperStatusResponse struct {
	Monitor daemonkit.MonitorState `json:"monitor"`
}

TrafficShaperStatusResponse is the view returned by GET /block_node/traffic_shaper/status. For #746 it carries only the supervisor-level health of the monitor goroutine (running/backoff/stopped). Per-subsystem and degraded-state reporting is added by #750.

type VethResolver added in v0.22.1

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

VethResolver resolves the host-side veth peer of a BN pod by matching the pod's eth0 iflink against the host's /sys/class/net/*/ifindex entries.

Algorithm (v4 design §8.1.1):

  1. Exec "cat /sys/class/net/eth0/iflink" inside the pod → the host-side veth's ifindex.
  2. Scan /sys/class/net/*/ifindex on the host for the matching interface.

func NewVethResolver added in v0.22.1

func NewVethResolver(cfg VethResolverConfig) (*VethResolver, error)

NewVethResolver builds a VethResolver backed by the k8s exec API. The REST config and typed k8s client are built once from cfg.KubeconfigPath and reused across Resolve calls (matching the UpgradeMonitor pattern).

func (*VethResolver) Resolve added in v0.22.1

func (r *VethResolver) Resolve(ctx context.Context, pod *corev1.Pod) (string, error)

Resolve returns the host-side veth name (e.g. "lxc1a2b3c4d") for the given pod's eth0 interface.

Callers should retry on both ErrVethNotFound (veth not yet visible) and any error wrapping ErrVethNotReady (container not yet exec-capable).

type VethResolverConfig added in v0.22.1

type VethResolverConfig struct {
	// KubeconfigPath is the path to the BN-scoped kubeconfig used to exec
	// into the BN pod to read its eth0 iflink.
	KubeconfigPath string

	// SysClassNet is the host-side /sys/class/net path to scan for ifindex
	// files. Defaults to /sys/class/net when empty; override in tests.
	SysClassNet string
}

VethResolverConfig holds inputs for NewVethResolver.

Jump to

Keyboard shortcuts

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