Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storageclasses view keeps the same output as kubectl get sc #2132

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/render/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,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
21 changes: 18 additions & 3 deletions internal/render/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (

"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"
)

// StorageClass renders a K8s StorageClass to screen.
Expand All @@ -19,14 +21,17 @@ func (StorageClass) Header(ns string) Header {
return Header{
HeaderColumn{Name: "NAME"},
HeaderColumn{Name: "PROVISIONER"},
HeaderColumn{Name: "RECLAIMPOLICY"},
HeaderColumn{Name: "VOLUMEBINDINGMODE"},
HeaderColumn{Name: "ALLOWVOLUMEEXPANSION"},
HeaderColumn{Name: "LABELS", Wide: true},
wjiec marked this conversation as resolved.
Show resolved Hide resolved
HeaderColumn{Name: "VALID", Wide: true},
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 +44,22 @@ 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),
s.nameWithDefault(sc.ObjectMeta),
sc.Provisioner,
strPtrToStr((*string)(sc.ReclaimPolicy)),
strPtrToStr((*string)(sc.VolumeBindingMode)),
boolPtrToStr(sc.AllowVolumeExpansion),
mapToStr(sc.Labels),
"",
toAge(sc.GetCreationTimestamp()),
}

return nil
}

func (StorageClass) nameWithDefault(meta metav1.ObjectMeta) string {
if storage.IsDefaultAnnotationText(meta) == "Yes" {
return meta.Name + " (default)"
}
return meta.Name
}
2 changes: 1 addition & 1 deletion internal/render/sc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func TestStorageClassRender(t *testing.T) {

assert.NoError(t, c.Render(load(t, "sc"), "", &r))
assert.Equal(t, "-/standard", r.ID)
assert.Equal(t, render.Fields{"standard", "kubernetes.io/gce-pd"}, r.Fields[:2])
wjiec marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, render.Fields{"standard (default)", "kubernetes.io/gce-pd", "Delete", "Immediate", "true"}, r.Fields[:5])
}
3 changes: 2 additions & 1 deletion internal/render/testdata/sc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
},
"provisioner": "kubernetes.io/gce-pd",
"reclaimPolicy": "Delete",
"volumeBindingMode": "Immediate"
"volumeBindingMode": "Immediate",
"allowVolumeExpansion": true
}