From ba115a8170b4e22702f9baf833380bb1bbdf2b4d Mon Sep 17 00:00:00 2001 From: "kalle (jag)" <2477952+applejag@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:10:11 +0100 Subject: [PATCH] PV reclaim policy coloring (#73) * PV reclaim policy coloring * Updated CHANGELOG * Added more colors --- CHANGELOG.md | 2 ++ pkg/klock/color.go | 22 +++++++++++++++++++--- pkg/klock/klock.go | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c5b36..70749ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/). where `NotReady,SchedulingDisabled` would have red `NotReady` and orange `SchedulingDisabled`. (#69) +- Added coloring on PV/StorageClass reclaim policy and PV/PVC status. (#73) + - Changed to Go 1.21.5 to resolve vulnerability [GO-2023-2182](https://pkg.go.dev/vuln/GO-2023-2182), for denial of service in net/http, and [GO-2023-2185](https://pkg.go.dev/vuln/GO-2023-2185) for insecure parsing of Windows paths with a `\??\` prefix. (#72) diff --git a/pkg/klock/color.go b/pkg/klock/color.go index 1f28170..c0a9401 100644 --- a/pkg/klock/color.go +++ b/pkg/klock/color.go @@ -126,7 +126,10 @@ func StatusStyle(status string) lipgloss.Style { "Evicted", "FailedScheduling", "Error", - "ErrImagePull": + "ErrImagePull", + + // PVC status + "Lost": return StyleStatusError case // from https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/events/event.go @@ -160,7 +163,14 @@ func StatusStyle(status string) lipgloss.Style { "ContainerCreating", "PodInitializing", "Terminating", - "Warning": + "Warning", + + // PV reclaim policy + "Delete", + + // PVC status + "Available", + "Released": return StyleStatusWarning case "Running", @@ -173,7 +183,13 @@ func StatusStyle(status string) lipgloss.Style { "Normal", "VolumeResizeSuccessful", "FileSystemResizeSuccessful", - "Ready": + "Ready", + + // PV reclaim policy + "Retain", + + // PVC status + "Bound": return StyleStatusOK } // some ok status, not colored: diff --git a/pkg/klock/klock.go b/pkg/klock/klock.go index 658061e..8959439 100644 --- a/pkg/klock/klock.go +++ b/pkg/klock/klock.go @@ -524,6 +524,14 @@ func (p *Printer) parseCell(cell any, row metav1.TableRow, eventType watch.Event } } return cell + case p.apiVersion == "storage.k8s.io/v1" && p.kind == "StorageClass" && columnNameLower == "reclaimpolicy": + return StatusColumn(cellStr) + case p.apiVersion == "v1" && p.kind == "PersistentVolume" && columnNameLower == "reclaim policy": + return StatusColumn(cellStr) + case p.apiVersion == "v1" && p.kind == "PersistentVolume" && columnNameLower == "status": + return StatusColumn(cellStr) + case p.apiVersion == "v1" && p.kind == "PersistentVolumeClaim" && columnNameLower == "status": + return StatusColumn(cellStr) // Only parse fraction (e.g "1/2") if the resources was not deleted, // so we don't have colored fraction on a grayed-out row. case eventType != watch.Deleted: