status

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanvasClient

type CanvasClient interface {
	// GetConversationInfoContext resolves channel metadata, including any existing channel canvas.
	GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)

	// GetConversationsContext lists channels, used to resolve configured channel names to IDs.
	GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) ([]slack.Channel, string, error)

	// CreateChannelCanvasContext creates a channel canvas.
	CreateChannelCanvasContext(ctx context.Context, channel string, documentContent slack.DocumentContent, options ...slack.CreateChannelCanvasOption) (string, error)

	// EditCanvasContext applies changes to an existing canvas.
	EditCanvasContext(ctx context.Context, params slack.EditCanvasParams) error
}

CanvasClient is the narrow slice of the Slack API the status canvas needs.

Keeping it an interface rather than taking *slack.Client directly lets the publisher be tested without a Slack server, and documents exactly which four calls this feature makes.

type CatalogEntry

type CatalogEntry struct {
	Kind       string
	Namespace  string
	Name       string
	Images     []ContainerImage
	Ready      int32
	Desired    int32
	RollingOut bool
	Health     Health
}

CatalogEntry describes one opt-in workload in the service catalog.

type ClusterState

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

ClusterState holds the current view of the cluster, built from a mix of periodic snapshots and event deltas. It is safe for concurrent use: the event observer writes while the publisher reads.

func NewClusterState

func NewClusterState(clusterName string, maxWarnings int) *ClusterState

NewClusterState returns an empty ClusterState for the given cluster name.

func (*ClusterState) AddWarning

func (s *ClusterState) AddWarning(w Warning)

AddWarning applies a single warning event, updating an existing entry for the same object/reason in place rather than appending a duplicate. The running count never walks backwards, since events can be delivered out of order.

func (*ClusterState) ApplySnapshot

func (s *ClusterState) ApplySnapshot(data SnapshotData)

ApplySnapshot replaces the collected sections with a fresh full snapshot, deriving the overall health from it. Clears any pending stale flags, since a full snapshot already refreshed everything.

func (*ClusterState) MarkStale

func (s *ClusterState) MarkStale(sections ...Section)

MarkStale flags the given sections as needing a re-collect.

This deliberately does not bump the revision: marking stale means "re-collect this", not "the canvas changed". Bumping here would publish an unchanged canvas on every event that carries no renderable data.

func (*ClusterState) Revision

func (s *ClusterState) Revision() int64

Revision returns a counter that increases every time the state changes in a way that would change the rendered canvas. The publisher uses this to skip redundant renders.

func (*ClusterState) Snapshot

func (s *ClusterState) Snapshot() Snapshot

Snapshot returns a deep copy of the current state, safe to render outside the lock.

func (*ClusterState) TakeStale

func (s *ClusterState) TakeStale() []Section

TakeStale returns the sections flagged stale since the last call and clears the flags.

type Collector

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

Collector builds a full cluster snapshot by listing resources directly.

Listing rather than watching is deliberate: the canvas renders a whole-cluster view that is rewritten in full on every update, so a point-in-time list is exactly the shape needed. It also makes the snapshot self-correcting, since it never depends on having seen every intermediate event.

func NewCollector

func NewCollector(log logrus.FieldLogger, k8sCli kubernetes.Interface, cfg config.StatusCanvas) (*Collector, error)

NewCollector returns a Collector for the given configuration.

func (*Collector) Collect

func (c *Collector) Collect(ctx context.Context) (SnapshotData, error)

Collect gathers a full cluster snapshot.

A failure in one section does not abandon the whole snapshot: a canvas showing four of five sections plus a logged error is more useful than no update at all. Errors are aggregated and returned so the caller can log them, while the returned data holds whatever did succeed.

type ContainerImage

type ContainerImage struct {
	Container string
	Image     string
	Version   string
}

ContainerImage describes one container's declared image and version.

type GraphQLClient

type GraphQLClient interface {
	Client() *graphql.Client
	DeploymentID() string
}

GraphQLClient defines GraphQL client.

type GraphQLStatusReporter

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

GraphQLStatusReporter reports status to GraphQL server.

func (*GraphQLStatusReporter) ReportDeploymentConnectionInit

func (r *GraphQLStatusReporter) ReportDeploymentConnectionInit(ctx context.Context, k8sVer string) error

ReportDeploymentConnectionInit reports connection initialization.

func (*GraphQLStatusReporter) ReportDeploymentFailure

func (r *GraphQLStatusReporter) ReportDeploymentFailure(ctx context.Context, errMsg string) error

ReportDeploymentFailure reports deployment failure to GraphQL server.

func (*GraphQLStatusReporter) ReportDeploymentShutdown

func (r *GraphQLStatusReporter) ReportDeploymentShutdown(ctx context.Context) error

ReportDeploymentShutdown reports deployment shutdown to GraphQL server.

func (*GraphQLStatusReporter) ReportDeploymentStartup

func (r *GraphQLStatusReporter) ReportDeploymentStartup(ctx context.Context) error

ReportDeploymentStartup reports deployment startup to GraphQL server.

func (*GraphQLStatusReporter) SetLogger

func (r *GraphQLStatusReporter) SetLogger(logger logrus.FieldLogger)

func (*GraphQLStatusReporter) SetResourceVersion

func (r *GraphQLStatusReporter) SetResourceVersion(resourceVersion int)

SetResourceVersion sets resource version.

type Health

type Health string

Health describes the health of a single entry or of the cluster as a whole.

const (
	// HealthOK means the entry is in its desired state.
	HealthOK Health = "ok"
	// HealthDegraded means the entry is impaired but still serving.
	HealthDegraded Health = "degraded"
	// HealthFailing means the entry is not serving at all.
	HealthFailing Health = "failing"
	// HealthUnknown means health could not be determined.
	HealthUnknown Health = "unknown"
)

func WorseOf

func WorseOf(a, b Health) Health

WorseOf returns whichever of a and b is worse.

Unknown ranks worse than OK: a health that could not be determined should not read as healthy.

type Node

type Node struct {
	Name        string
	Health      Health
	Ready       string
	Schedulable bool
	KubeletVer  string
	Reason      string
}

Node describes one cluster node.

type NoopStatusReporter

type NoopStatusReporter struct{}

func (NoopStatusReporter) ReportDeploymentConnectionInit

func (n NoopStatusReporter) ReportDeploymentConnectionInit(context.Context, string) error

func (NoopStatusReporter) ReportDeploymentFailure

func (n NoopStatusReporter) ReportDeploymentFailure(context.Context, string) error

func (NoopStatusReporter) ReportDeploymentShutdown

func (n NoopStatusReporter) ReportDeploymentShutdown(context.Context) error

func (NoopStatusReporter) ReportDeploymentStartup

func (n NoopStatusReporter) ReportDeploymentStartup(context.Context) error

func (NoopStatusReporter) SetLogger

func (n NoopStatusReporter) SetLogger(logrus.FieldLogger)

func (NoopStatusReporter) SetResourceVersion

func (n NoopStatusReporter) SetResourceVersion(int)

type Observer

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

Observer applies Kubernetes source plugin events to the cluster state, so the canvas reacts to changes without waiting for the next full snapshot.

What an event can contribute is limited by the plugin boundary. Source events are serialized to JSON before reaching the agent, and the Kubernetes source event type excludes the underlying object from that JSON. Events therefore carry identity, reason and message, but no object status. The consequence is a split:

  • Warnings need only what the event already carries, so they are applied directly.
  • Nodes, workloads and the catalog need replica counts, conditions and images, so the event can only flag those sections stale. The publisher then asks the collector for fresh data.

The alternative, inferring status from an event's reason string, would put guessed data on the canvas; marking stale keeps the collector the single source of truth for anything status-shaped.

func NewObserver

func NewObserver(log logrus.FieldLogger, state *ClusterState, cfg config.StatusCanvas) *Observer

NewObserver returns an Observer feeding the given cluster state.

func (*Observer) ObserveEvent

func (o *Observer) ObserveEvent(pluginName string, rawObject any)

ObserveEvent applies a single source plugin event to the cluster state.

It never blocks and never fails the caller: the dispatcher calls this on the hot path of event delivery, and a canvas update must not interfere with sending notifications.

type Publisher

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

Publisher keeps one Slack channel canvas per configured channel in sync with the cluster state.

func NewPublisher

func NewPublisher(log logrus.FieldLogger, cfg config.StatusCanvas, client CanvasClient, collector *Collector, state *ClusterState) *Publisher

NewPublisher returns a Publisher for the given configuration.

func (*Publisher) Start

func (p *Publisher) Start(ctx context.Context) error

Start collects an initial snapshot, publishes it, and then keeps the canvas up to date until the context is cancelled.

Two timers drive it. The update ticker is the debounce window: it publishes only when the state revision moved, so a burst of events produces one canvas write. The snapshot ticker re-lists the cluster, which both picks up changes no event described and corrects any drift.

type Renderer

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

Renderer turns a Snapshot into the canvas markdown body.

Render is a pure function of its input: determinism is load-bearing, because the publisher skips writing the canvas when the rendered body is unchanged from the last write.

func NewRenderer

func NewRenderer(cfg config.StatusCanvas) *Renderer

NewRenderer returns a Renderer for the given configuration.

func (*Renderer) Render

func (r *Renderer) Render(snap Snapshot) string

Render returns the full canvas markdown body for the given snapshot.

type ResVerClient

type ResVerClient interface {
	GetResourceVersion(ctx context.Context) (int, error)
}

ResVerClient defines client for getting resource version.

type Section

type Section string

Section identifies one part of the rendered canvas.

const (
	// SectionSummary is the cluster-wide summary section.
	SectionSummary Section = "summary"
	// SectionNodes is the node health section.
	SectionNodes Section = "nodes"
	// SectionWorkloads is the unhealthy workloads section.
	SectionWorkloads Section = "workloads"
	// SectionCatalog is the service catalog section.
	SectionCatalog Section = "catalog"
	// SectionWarnings is the recent warning events section.
	SectionWarnings Section = "warnings"
)

type Snapshot

type Snapshot struct {
	Summary   Summary
	Nodes     []Node
	Workloads []Workload
	Catalog   []CatalogEntry
	Warnings  []Warning
}

Snapshot is a point-in-time, read-only view of the cluster state.

type SnapshotData

type SnapshotData struct {
	Summary   Summary
	Nodes     []Node
	Workloads []Workload
	Catalog   []CatalogEntry
	Warnings  []Warning
}

SnapshotData is the output of a single collection pass.

type StatusReporter

type StatusReporter interface {
	ReportDeploymentConnectionInit(ctx context.Context, k8sVer string) error
	ReportDeploymentStartup(ctx context.Context) error
	ReportDeploymentShutdown(ctx context.Context) error
	ReportDeploymentFailure(ctx context.Context, errMsg string) error
	SetResourceVersion(resourceVersion int)
	SetLogger(logger logrus.FieldLogger)
}

func GetReporter

func GetReporter(remoteCfgEnabled bool, gql GraphQLClient, resVerClient ResVerClient, log logrus.FieldLogger) StatusReporter

type Summary

type Summary struct {
	ClusterName       string
	KubernetesVer     string
	NodesTotal        int
	NodesReady        int
	NamespacesInScope int
	PodsTotal         int
	PodsUnhealthy     int
	WorkloadsTotal    int
	Health            Health
	SnapshotAt        time.Time
}

Summary holds cluster-wide counters and the overall health verdict.

type Warning

type Warning struct {
	Namespace string
	Kind      string
	Name      string
	Reason    string
	Message   string
	Count     int32
	Timestamp time.Time
}

Warning describes one recent warning event.

type Workload

type Workload struct {
	Kind      string
	Namespace string
	Name      string
	Health    Health
	Ready     int32
	Desired   int32
	Reason    string
	Restarts  int32
}

Workload describes one workload or pod that is not in its desired state.

Jump to

Keyboard shortcuts

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