Skip to content

Commit

Permalink
storageclasses view keeps the same output as kubectl get sc
Browse files Browse the repository at this point in the history
  • Loading branch information
wjiec committed Jun 15, 2023
1 parent 152ace0 commit 2a1256f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 9 additions & 1 deletion internal/render/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"strings"
"time"

"github.com/derailed/k9s/internal/client"
"github.com/derailed/tview"
runewidth "github.com/mattn/go-runewidth"
"github.com/rs/zerolog/log"
"golang.org/x/text/language"
"golang.org/x/text/message"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/duration"

"github.com/derailed/k9s/internal/client"
)

func runesToNum(rr []rune) int64 {
Expand Down Expand Up @@ -298,6 +299,13 @@ func boolPtrToStr(b *bool) string {
return boolToStr(*b)
}

func strPtrToStr(s *string) string {
if s == nil {
return ""
}
return *s
}

// Check if string is in a string list.
func in(ll []string, s string) bool {
for _, l := range ll {
Expand Down
28 changes: 20 additions & 8 deletions internal/render/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package render
import (
"fmt"

"github.com/derailed/k9s/internal/client"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubectl/pkg/util/storage"

"github.com/derailed/k9s/internal/client"
)

// StorageClass renders a K8s StorageClass to screen.
Expand All @@ -19,14 +22,15 @@ func (StorageClass) Header(ns string) Header {
return Header{
HeaderColumn{Name: "NAME"},
HeaderColumn{Name: "PROVISIONER"},
HeaderColumn{Name: "LABELS", Wide: true},
HeaderColumn{Name: "VALID", Wide: true},
HeaderColumn{Name: "RECLAIMPOLICY"},
HeaderColumn{Name: "VOLUMEBINDINGMODE"},
HeaderColumn{Name: "ALLOWVOLUMEEXPANSION"},
HeaderColumn{Name: "AGE", Time: true},
}
}

// Render renders a K8s resource to screen.
func (StorageClass) Render(o interface{}, ns string, r *Row) error {
func (s StorageClass) Render(o interface{}, ns string, r *Row) error {
raw, ok := o.(*unstructured.Unstructured)
if !ok {
return fmt.Errorf("Expected StorageClass, but got %T", o)
Expand All @@ -39,12 +43,20 @@ func (StorageClass) Render(o interface{}, ns string, r *Row) error {

r.ID = client.FQN(client.ClusterScope, sc.ObjectMeta.Name)
r.Fields = Fields{
sc.Name,
string(sc.Provisioner),
mapToStr(sc.Labels),
"",
s.nameWithDefault(sc.ObjectMeta),
sc.Provisioner,
strPtrToStr((*string)(sc.ReclaimPolicy)),
strPtrToStr((*string)(sc.VolumeBindingMode)),
boolPtrToStr(sc.AllowVolumeExpansion),
toAge(sc.GetCreationTimestamp()),
}

return nil
}

func (StorageClass) nameWithDefault(meta metav1.ObjectMeta) string {
if storage.IsDefaultAnnotationText(meta) == "Yes" {
return meta.Name + " (default)"
}
return meta.Name
}

0 comments on commit 2a1256f

Please sign in to comment.