Merge pull request #32823 from nikhiljindal/descNs

Automatic merge from submit-queue

Allow kubectl describe ns to pass if server does not support resource quotas and limit ranges

Fixes https://github.com/kubernetes/kubernetes/issues/32629

Context: federation-apiserver does not support limit ranges and resource quotas. Hence `kubectl describe ns` fails right now.
Fixing it so that `kubectl describe ns` does not error out and atleast prints information about the namespace.

cc @kubernetes/sig-cluster-federation @kubernetes/kubectl
This commit is contained in:
Kubernetes Submit Queue 2016-09-17 04:04:20 -07:00 committed by GitHub
commit 8fd414537b
2 changed files with 31 additions and 3 deletions

View File

@ -173,13 +173,24 @@ func (d *NamespaceDescriber) Describe(namespace, name string, describerSettings
}
resourceQuotaList, err := d.Core().ResourceQuotas(name).List(api.ListOptions{})
if err != nil {
return "", err
if errors.IsNotFound(err) {
// Server does not support resource quotas.
// Not an error, will not show resource quotas information.
resourceQuotaList = nil
} else {
return "", err
}
}
limitRangeList, err := d.Core().LimitRanges(name).List(api.ListOptions{})
if err != nil {
return "", err
if errors.IsNotFound(err) {
// Server does not support limit ranges.
// Not an error, will not show limit ranges information.
limitRangeList = nil
} else {
return "", err
}
}
return describeNamespace(ns, resourceQuotaList, limitRangeList)
}

View File

@ -86,6 +86,23 @@ func TestDescribePodTolerations(t *testing.T) {
}
}
func TestDescribeNamespace(t *testing.T) {
fake := fake.NewSimpleClientset(&api.Namespace{
ObjectMeta: api.ObjectMeta{
Name: "myns",
},
})
c := &describeClient{T: t, Namespace: "", Interface: fake}
d := NamespaceDescriber{c}
out, err := d.Describe("", "myns", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "myns") {
t.Errorf("unexpected out: %s", out)
}
}
func TestDescribeService(t *testing.T) {
fake := fake.NewSimpleClientset(&api.Service{
ObjectMeta: api.ObjectMeta{