Skip to content

Commit

Permalink
Merge pull request kubernetes#31607 from jsafrane/describe-storageclass
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Add kubectl describe storageclass.

Sample output:

```
Name:		fast
Annotations:	storage.beta.kubernetes.io/default-class=true
Provisioner:	kubernetes.io/aws-ebs
Parameters:	type=gp2
No events.

Name:		slow
Annotations:	<none>
Provisioner:	kubernetes.io/aws-ebs
Parameters:	type=sc1
No events.
```
(it looks nicely aligned in terminal)

Proposing 1.4, it's bugfix, not a feature.
  • Loading branch information
Kubernetes Submit Queue authored Sep 9, 2016
2 parents 1d04044 + a683977 commit ba4dba8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/certificates"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/storage"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
client "k8s.io/kubernetes/pkg/client/unversioned"
adapter "k8s.io/kubernetes/pkg/client/unversioned/adapters/internalclientset"
Expand Down Expand Up @@ -116,6 +117,7 @@ func describerMap(c *client.Client) map[unversioned.GroupKind]Describer {
batch.Kind("ScheduledJob"): &ScheduledJobDescriber{adapter.FromUnversionedClient(c)},
apps.Kind("PetSet"): &PetSetDescriber{c},
certificates.Kind("CertificateSigningRequest"): &CertificateSigningRequestDescriber{c},
storage.Kind("StorageClass"): &StorageClassDescriber{c},
}

return m
Expand Down Expand Up @@ -2385,6 +2387,33 @@ func describeNetworkPolicy(networkPolicy *extensions.NetworkPolicy) (string, err
})
}

type StorageClassDescriber struct {
client.Interface
}

func (s *StorageClassDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) {
sc, err := s.Storage().StorageClasses().Get(name)
if err != nil {
return "", err
}
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", sc.Name)
fmt.Fprintf(out, "Annotations:\t%s\n", labels.FormatLabels(sc.Annotations))
fmt.Fprintf(out, "Provisioner:\t%s\n", sc.Provisioner)
fmt.Fprintf(out, "Parameters:\t%s\n", labels.FormatLabels(sc.Parameters))
if describerSettings.ShowEvents {
events, err := s.Events(namespace).Search(sc)
if err != nil {
return err
}
if events != nil {
DescribeEvents(events, out)
}
}
return nil
})
}

// newErrNoDescriber creates a new ErrNoDescriber with the names of the provided types.
func newErrNoDescriber(types ...reflect.Type) error {
names := make([]string, 0, len(types))
Expand Down
34 changes: 34 additions & 0 deletions pkg/kubectl/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
Expand Down Expand Up @@ -606,6 +607,31 @@ func TestDescribeCluster(t *testing.T) {
}
}

func TestDescribeStorageClass(t *testing.T) {
f := testclient.NewSimpleFake(&storage.StorageClass{
ObjectMeta: api.ObjectMeta{
Name: "foo",
ResourceVersion: "4",
Annotations: map[string]string{
"name": "foo",
},
},
Provisioner: "my-provisioner",
Parameters: map[string]string{
"param1": "value1",
"param2": "value2",
},
})
s := StorageClassDescriber{f}
out, err := s.Describe("", "foo", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "foo") {
t.Errorf("unexpected out: %s", out)
}
}

func TestDescribeEvents(t *testing.T) {

events := &api.EventList{
Expand Down Expand Up @@ -704,6 +730,14 @@ func TestDescribeEvents(t *testing.T) {
},
}, events),
},
"StorageClass": &StorageClassDescriber{
testclient.NewSimpleFake(&storage.StorageClass{
ObjectMeta: api.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
}, events),
},
}

for name, d := range m {
Expand Down

0 comments on commit ba4dba8

Please sign in to comment.