Skip to content

Commit

Permalink
PV reclaim policy coloring (#73)
Browse files Browse the repository at this point in the history
* PV reclaim policy coloring

* Updated CHANGELOG

* Added more colors
  • Loading branch information
applejag authored Dec 13, 2023
1 parent b37c242 commit ba115a8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions pkg/klock/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions pkg/klock/klock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ba115a8

Please sign in to comment.