Describe and get support for the updated api + tests

This commit is contained in:
Marcin 2016-11-09 13:39:16 +01:00
parent 5f8e76b479
commit 9cee1456a6
4 changed files with 64 additions and 13 deletions

View File

@ -2415,6 +2415,7 @@ func (p *PodDisruptionBudgetDescriber) Describe(namespace, name string, describe
fmt.Fprintf(out, "Selector:\t<unset>\n")
}
fmt.Fprintf(out, "Status:\n")
fmt.Fprintf(out, " Allowed disruptions:\t%d\n", pdb.Status.PodDisruptionsAllowed)
fmt.Fprintf(out, " Current:\t%d\n", pdb.Status.CurrentHealthy)
fmt.Fprintf(out, " Desired:\t%d\n", pdb.Status.DesiredHealthy)
fmt.Fprintf(out, " Total:\t%d\n", pdb.Status.ExpectedPods)

View File

@ -31,9 +31,11 @@ import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
"k8s.io/kubernetes/pkg/apis/storage"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/util/intstr"
)
type describeClient struct {
@ -694,6 +696,30 @@ func TestDescribeStorageClass(t *testing.T) {
}
}
func TestDescribePodDisruptionBudget(t *testing.T) {
f := fake.NewSimpleClientset(&policy.PodDisruptionBudget{
ObjectMeta: api.ObjectMeta{
Namespace: "ns1",
Name: "pdb1",
CreationTimestamp: unversioned.Time{Time: time.Now().Add(1.9e9)},
},
Spec: policy.PodDisruptionBudgetSpec{
MinAvailable: intstr.FromInt(22),
},
Status: policy.PodDisruptionBudgetStatus{
PodDisruptionsAllowed: 5,
},
})
s := PodDisruptionBudgetDescriber{f}
out, err := s.Describe("ns1", "pdb1", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "pdb1") {
t.Errorf("unexpected out: %s", out)
}
}
func TestDescribeEvents(t *testing.T) {
events := &api.EventList{

View File

@ -475,7 +475,7 @@ func (h *HumanReadablePrinter) AfterPrint(output io.Writer, res string) error {
var (
podColumns = []string{"NAME", "READY", "STATUS", "RESTARTS", "AGE"}
podTemplateColumns = []string{"TEMPLATE", "CONTAINER(S)", "IMAGE(S)", "PODLABELS"}
podDisruptionBudgetColumns = []string{"NAME", "MIN-AVAILABLE", "SELECTOR", "DISRUPTIONS"}
podDisruptionBudgetColumns = []string{"NAME", "MIN-AVAILABLE", "ALLOWED-DISRUPTIONS", "AGE"}
replicationControllerColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
replicaSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
jobColumns = []string{"NAME", "DESIRED", "SUCCESSFUL", "AGE"}
@ -842,20 +842,11 @@ func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, opti
return err
}
}
selector := "<none>"
if pdb.Spec.Selector != nil {
selector = unversioned.FormatLabelSelector(pdb.Spec.Selector)
}
disruptions := "Disallowed"
if pdb.Status.PodDisruptionAllowed {
disruptions = "Allowed"
}
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n",
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
name,
pdb.Spec.MinAvailable.String(),
selector,
disruptions,
pdb.Status.PodDisruptionsAllowed,
translateTimestamp(pdb.CreationTimestamp),
); err != nil {
return err
}

View File

@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/policy"
kubectltesting "k8s.io/kubernetes/pkg/kubectl/testing"
"k8s.io/kubernetes/pkg/runtime"
yamlserializer "k8s.io/kubernetes/pkg/runtime/serializer/yaml"
@ -1622,3 +1623,35 @@ func TestPrintService(t *testing.T) {
buf.Reset()
}
}
func TestPrintPodDisruptionBudget(t *testing.T) {
tests := []struct {
pdb policy.PodDisruptionBudget
expect string
}{
{
policy.PodDisruptionBudget{
ObjectMeta: api.ObjectMeta{
Namespace: "ns1",
Name: "pdb1",
CreationTimestamp: unversioned.Time{Time: time.Now().Add(1.9e9)},
},
Spec: policy.PodDisruptionBudgetSpec{
MinAvailable: intstr.FromInt(22),
},
Status: policy.PodDisruptionBudgetStatus{
PodDisruptionsAllowed: 5,
},
},
"pdb1\t22\t5\t0s\n",
}}
buf := bytes.NewBuffer([]byte{})
for _, test := range tests {
printPodDisruptionBudget(&test.pdb, buf, PrintOptions{false, false, false, false, true, false, false, "", []string{}})
if buf.String() != test.expect {
t.Fatalf("Expected: %s, got: %s", test.expect, buf.String())
}
buf.Reset()
}
}