Files
pulse/internal/unifiedresources/status.go
T
rcourtman b8a0f87e6b Proxmox and Docker passes: storage words, first paint, table fits
Rebuilds #2432 as one commit on current main. Its branch conflicted
with the Tailwind 4 move (#2443) in StackedDiskBar.tsx and
DockerTasksTable.tsx; the resolution keeps this change and main's class
renames (rounded-sm to rounded-xs). The eight original commits' reasons
follow.

Read PBS datastore status in the storage vocabulary:
The PBS poller reports a datastore as "available", or "unavailable"
when PBS returns an error for it. The datastore adapter mapped that
string through the generic status mapper, which only knows online,
offline and warning, so every healthy PBS datastore showed as
"Unknown" in the Storage tab and an unavailable one was not flagged.

PVE storage already maps the same vocabulary through its own storage
mapper. Share that mapping so a PBS datastore reads online or offline
like any other storage.

Carry shared PBS storage as one cluster row in the mock estate:
The mock emitted each cluster's two shared PBS storages once per node,
each with its own usage figure. The real poller folds a shared storage
into one cluster-scoped entry, which users asked for in issue 1049, so
the demo's Storage tab contradicted the shipped behaviour: ten rows of
"west-backup-primary" with different usage and growth on a five-node
estate, and a hundred on the public demo.

The fixture now carries the merged shape: one row per store with the
reporting nodes listed and a cluster-scoped id, offline only when no
cluster node is online.

Name Proxmox storage types and shared hosts as operators know them:
The Storage tab title-cased any storage type it did not map, so the
default local-lvm on every Proxmox install read "Lvmthin" and an NFS
share read "Nfs". Those types now carry the names the Proxmox UI uses:
LVM-Thin, LVM, NFS, SMB/CIFS, iSCSI, ZFS, BTRFS, GlusterFS and ESXi.

A storage the poller merged across the cluster showed the synthetic
node marker "cluster" as its host. It now reads "Shared", with the
reporting node count when the storage lists its nodes.

Carry PMG metadata on REST-mapped resources:
The Mail Gateway table reads resource.pmg. The REST-to-Resource mapper
set every other provider facet at the top level but kept pmg only under
platformData, so a row sourced from the REST snapshot rendered every
PMG column (version, nodes, mail in, spam, virus, quarantine, queue,
deferred) as a dash. The websocket snapshot carries pmg at the top
level, so the table filled in only when a websocket row happened to
replace the REST row; on a fresh load the two transports race, and
about half the loads stayed blank for good.

The mapper now carries pmg like the other facets, and a test pins it.

Label multi-disk hosts with their fullest disk in Bars mode:
A host with more than one agent-reported disk draws its Disk cell as
one micro-bar per disk and no figure, while a single-disk host shows a
percentage and Trends mode shows one for every host. Bars is the
default view, and most Proxmox nodes have at least local-zfs beside a
data pool, so the question "which node is running out of space?" had
no at-a-glance answer for the rows that matter most; the column's own
sort key was a number the cell never showed.

The cell now carries the fullest disk's usage beside the micro-bars.
Every bar keeps equal weight and no disk is named in the row; the
mount and the per-disk breakdown stay in the title and the tooltip.

Carry source status, action readiness and technology on REST rows:
The same race that blanked the Mail Gateway table applies to three
more fields the API returns: sourceStatus, actionReadiness and
technology. The REST mapper set sourceStatus only under platformData
and dropped the other two, while websocket rows carry all three at the
top level. Docker container lifecycle actions read sourceStatus and
actionReadiness to decide refusals, storage rows read sourceStatus for
freshness, and search suggestions and the assistant context read
technology, so whichever transport won a fresh load decided whether
those consumers saw the data.

The mapper now carries all three, the REST type declares the two it
omitted, and the PMG mapping test pins them.

Fit the Docker containers table and read Swarm state as words:
On a 1280-1536px laptop window the containers table clipped its short
values: the engine read "docker 2…", host names lost their tail, and
the Update control itself was cut off, while the percentage-only CPU
and memory bars had room to spare. The compact widths now give those
columns their share. On a phone the row dropped to "runni…" with an
unreadable Restarts header beside a wrapped Update button; the phone
row now keeps container, state, CPU, memory and Update, and the
restart count stays in the row expansion until mobile width. The
images table on a phone showed "Not c…" for the update verdict and a
clipped host; it keeps image, size and update check there and defers
host and consumers to the expansion.

Swarm services showed the rollout state as the raw token
"rollback_started" and Swarm tasks showed a raw RFC3339 stamp with
microseconds as their start time. The state reads as words and the
start as an age, with the raw values in the title.

Keep demo Docker container names unique per host:
The demo scenario reused its curated container profiles for a second
round on hosts with more containers than profiles, so a host showed
two running "customer-portal" rows and every image's "used by" list
read "customer-portal, customer-portal". Docker refuses two containers
with one name on a host, so the duplicates read as a bug to anyone
evaluating the demo. A reused profile now takes a numbered suffix.

Contract-Neutral: Storage type labels, shared-host label, REST mapper carrying fields websocket rows already carry, Bars-mode disk label and Docker column fits are presentation and mapping only; owning unified-resources and storage-recovery clauses updated; no frontend-primitives primitive, API or runtime boundary change
2026-10-03 21:35:27 +01:00

400 lines
10 KiB
Go

package unifiedresources
import (
"strings"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
)
func statusFromString(status string) ResourceStatus {
switch strings.ToLower(strings.TrimSpace(status)) {
case "online", "running", "ok":
return StatusOnline
case "offline", "down", "stopped":
return StatusOffline
case "warning", "degraded":
return StatusWarning
default:
return StatusUnknown
}
}
func statusFromGuest(status string) ResourceStatus {
switch strings.ToLower(strings.TrimSpace(status)) {
case "running", "online":
return StatusOnline
case "stopped", "offline", "paused":
return StatusOffline
case "warning", "degraded":
return StatusWarning
default:
return StatusUnknown
}
}
// statusFromStorageState maps the storage-native status vocabulary, which
// includes the "available"/"unavailable" pair PVE storage and PBS datastores
// report, onto a resource status. The second result is false when the string
// is not a storage state the caller can act on.
func statusFromStorageState(status string) (ResourceStatus, bool) {
switch strings.ToLower(strings.TrimSpace(status)) {
case "online", "running", "available", "active", "ok":
return StatusOnline, true
case "warning", "degraded":
return StatusWarning, true
case "offline", "down", "unavailable", "error":
return StatusOffline, true
}
return StatusUnknown, false
}
func statusFromStorage(storage models.Storage) ResourceStatus {
if status, ok := statusFromStorageState(storage.Status); ok {
return status
}
if !storage.Active {
return StatusOffline
}
if !storage.Enabled {
return StatusWarning
}
return StatusOnline
}
func statusFromPhysicalDisk(health string) ResourceStatus {
switch strings.ToUpper(strings.TrimSpace(health)) {
case "PASSED", "OK":
return StatusOnline
case "FAILED":
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromCephHealth(health string) ResourceStatus {
switch strings.ToUpper(strings.TrimSpace(health)) {
case "HEALTH_OK", "OK":
return StatusOnline
case "HEALTH_WARN", "WARN":
return StatusWarning
case "HEALTH_ERR", "ERR":
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromDockerState(state string) ResourceStatus {
switch strings.ToLower(strings.TrimSpace(state)) {
case "running":
return StatusOnline
case "created", "exited", "dead", "paused":
return StatusOffline
case "restarting":
return StatusWarning
default:
return StatusUnknown
}
}
func statusFromDockerService(service models.DockerService) ResourceStatus {
desired := service.DesiredTasks
running := service.RunningTasks
if desired <= 0 {
if running > 0 {
return StatusOnline
}
return StatusUnknown
}
if running >= desired {
return StatusOnline
}
if running == 0 {
return StatusOffline
}
return StatusWarning
}
func statusFromDockerTask(task models.DockerTask) ResourceStatus {
current := strings.ToLower(strings.TrimSpace(task.CurrentState))
desired := strings.ToLower(strings.TrimSpace(task.DesiredState))
switch {
case strings.Contains(current, "running"):
return StatusOnline
case strings.Contains(current, "failed"), strings.Contains(current, "rejected"), strings.TrimSpace(task.Error) != "":
return StatusOffline
case strings.Contains(current, "pending"), strings.Contains(current, "starting"), strings.Contains(current, "preparing"), strings.Contains(current, "accepted"):
return StatusWarning
case desired == "shutdown" || strings.Contains(current, "complete"):
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromDockerSwarmNode(node models.DockerNode) ResourceStatus {
state := strings.ToLower(strings.TrimSpace(node.State))
reachability := strings.ToLower(strings.TrimSpace(node.ManagerReachability))
availability := strings.ToLower(strings.TrimSpace(node.Availability))
switch {
case state == "ready" || state == "active":
if reachability == "unreachable" || availability == "pause" || availability == "drain" {
return StatusWarning
}
return StatusOnline
case state == "down" || state == "disconnected":
return StatusOffline
case state == "unknown":
return StatusUnknown
case reachability == "unreachable":
return StatusWarning
default:
return StatusUnknown
}
}
func statusFromPBSInstance(instance models.PBSInstance) ResourceStatus {
primary := strings.ToLower(strings.TrimSpace(instance.Status))
health := strings.ToLower(strings.TrimSpace(instance.ConnectionHealth))
switch {
case primary == "online" || primary == "running" || primary == "ok" || primary == "healthy":
return StatusOnline
case primary == "warning" || primary == "degraded":
return StatusWarning
case primary == "offline" || primary == "down" || primary == "stopped" || primary == "error":
return StatusOffline
}
switch health {
case "online", "running", "ok", "healthy", "connected":
return StatusOnline
case "warning", "degraded":
return StatusWarning
case "offline", "down", "stopped", "error", "disconnected":
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromPMGInstance(instance models.PMGInstance) ResourceStatus {
primary := strings.ToLower(strings.TrimSpace(instance.Status))
health := strings.ToLower(strings.TrimSpace(instance.ConnectionHealth))
switch {
case primary == "online" || primary == "running" || primary == "ok" || primary == "healthy":
return StatusOnline
case primary == "warning" || primary == "degraded":
return StatusWarning
case primary == "offline" || primary == "down" || primary == "stopped" || primary == "error":
return StatusOffline
}
switch health {
case "online", "running", "ok", "healthy", "connected":
return StatusOnline
case "warning", "degraded":
return StatusWarning
case "offline", "down", "stopped", "error", "disconnected":
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromKubernetesCluster(cluster models.KubernetesCluster) ResourceStatus {
switch strings.ToLower(strings.TrimSpace(cluster.Status)) {
case "online", "running", "ready", "healthy":
return StatusOnline
case "warning", "degraded":
return StatusWarning
case "offline", "disconnected", "error":
return StatusOffline
}
if len(cluster.Nodes) == 0 {
return StatusUnknown
}
ready := 0
for _, node := range cluster.Nodes {
if node.Ready {
ready++
}
}
switch {
case ready == len(cluster.Nodes):
return StatusOnline
case ready == 0:
return StatusOffline
default:
return StatusWarning
}
}
func statusFromKubernetesNode(node models.KubernetesNode) ResourceStatus {
if !node.Ready {
return StatusOffline
}
if node.Unschedulable {
return StatusWarning
}
return StatusOnline
}
func statusFromKubernetesPod(pod models.KubernetesPod) ResourceStatus {
phase := strings.ToLower(strings.TrimSpace(pod.Phase))
switch phase {
case "failed", "succeeded":
return StatusOffline
case "running":
if len(pod.Containers) == 0 {
return StatusOnline
}
for _, container := range pod.Containers {
if !container.Ready {
return StatusWarning
}
state := strings.ToLower(strings.TrimSpace(container.State))
if state != "" && state != "running" {
return StatusWarning
}
}
return StatusOnline
case "pending", "unknown":
return StatusWarning
default:
return StatusUnknown
}
}
func statusFromKubernetesDeployment(deployment models.KubernetesDeployment) ResourceStatus {
desired := deployment.DesiredReplicas
available := deployment.AvailableReplicas
if desired <= 0 {
if available > 0 {
return StatusOnline
}
return StatusUnknown
}
if available >= desired {
return StatusOnline
}
if available == 0 {
return StatusOffline
}
return StatusWarning
}
func statusFromKubernetesReplicaSet(replicaSet models.KubernetesReplicaSet) ResourceStatus {
return statusFromReplicaAvailability(replicaSet.DesiredReplicas, replicaSet.ReadyReplicas)
}
func statusFromKubernetesStatefulSet(statefulSet models.KubernetesStatefulSet) ResourceStatus {
return statusFromReplicaAvailability(statefulSet.DesiredReplicas, statefulSet.ReadyReplicas)
}
func statusFromKubernetesDaemonSet(daemonSet models.KubernetesDaemonSet) ResourceStatus {
desired := daemonSet.DesiredNumberScheduled
ready := daemonSet.NumberReady
if daemonSet.NumberMisscheduled > 0 || daemonSet.NumberUnavailable > 0 {
if ready > 0 {
return StatusWarning
}
return StatusOffline
}
return statusFromReplicaAvailability(desired, ready)
}
func statusFromKubernetesJob(job models.KubernetesJob) ResourceStatus {
if job.Failed > 0 {
return StatusOffline
}
if job.Succeeded > 0 {
return StatusOnline
}
if job.Active > 0 {
return StatusWarning
}
return StatusUnknown
}
func statusFromKubernetesCronJob(cronJob models.KubernetesCronJob) ResourceStatus {
if cronJob.Suspend {
return StatusWarning
}
return StatusOnline
}
func statusFromKubernetesEndpointSlice(slice models.KubernetesEndpointSlice) ResourceStatus {
if slice.EndpointCount <= 0 {
return StatusUnknown
}
if slice.ReadyEndpointCount <= 0 {
return StatusWarning
}
return StatusOnline
}
func statusFromKubernetesPhase(phase string) ResourceStatus {
switch strings.ToLower(strings.TrimSpace(phase)) {
case "active", "bound", "available":
return StatusOnline
case "pending", "released":
return StatusWarning
case "failed", "lost", "terminating":
return StatusOffline
default:
return StatusUnknown
}
}
func statusFromKubernetesEvent(event models.KubernetesEvent) ResourceStatus {
if strings.EqualFold(strings.TrimSpace(event.EventType), "warning") {
return StatusWarning
}
return StatusOnline
}
func statusFromKubernetesPodDisruptionBudget(budget models.KubernetesPodDisruptionBudget) ResourceStatus {
if budget.ExpectedPods <= 0 {
return StatusUnknown
}
if budget.CurrentHealthy >= budget.DesiredHealthy {
return StatusOnline
}
if budget.CurrentHealthy <= 0 {
return StatusOffline
}
return StatusWarning
}
func statusFromKubernetesHorizontalPodAutoscaler(autoscaler models.KubernetesHorizontalPodAutoscaler) ResourceStatus {
if autoscaler.MaxReplicas > 0 && autoscaler.DesiredReplicas > autoscaler.MaxReplicas {
return StatusWarning
}
if autoscaler.DesiredReplicas > 0 && autoscaler.CurrentReplicas <= 0 {
return StatusOffline
}
return StatusOnline
}
func statusFromReplicaAvailability(desired, ready int32) ResourceStatus {
if desired <= 0 {
if ready > 0 {
return StatusOnline
}
return StatusUnknown
}
if ready >= desired {
return StatusOnline
}
if ready == 0 {
return StatusOffline
}
return StatusWarning
}