mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Describe and get support for the updated api + tests
This commit is contained in:
parent
5f8e76b479
commit
9cee1456a6
@ -2415,6 +2415,7 @@ func (p *PodDisruptionBudgetDescriber) Describe(namespace, name string, describe
|
|||||||
fmt.Fprintf(out, "Selector:\t<unset>\n")
|
fmt.Fprintf(out, "Selector:\t<unset>\n")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(out, "Status:\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, " Current:\t%d\n", pdb.Status.CurrentHealthy)
|
||||||
fmt.Fprintf(out, " Desired:\t%d\n", pdb.Status.DesiredHealthy)
|
fmt.Fprintf(out, " Desired:\t%d\n", pdb.Status.DesiredHealthy)
|
||||||
fmt.Fprintf(out, " Total:\t%d\n", pdb.Status.ExpectedPods)
|
fmt.Fprintf(out, " Total:\t%d\n", pdb.Status.ExpectedPods)
|
||||||
|
@ -31,9 +31,11 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/policy"
|
||||||
"k8s.io/kubernetes/pkg/apis/storage"
|
"k8s.io/kubernetes/pkg/apis/storage"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||||
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
type describeClient struct {
|
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) {
|
func TestDescribeEvents(t *testing.T) {
|
||||||
|
|
||||||
events := &api.EventList{
|
events := &api.EventList{
|
||||||
|
@ -475,7 +475,7 @@ func (h *HumanReadablePrinter) AfterPrint(output io.Writer, res string) error {
|
|||||||
var (
|
var (
|
||||||
podColumns = []string{"NAME", "READY", "STATUS", "RESTARTS", "AGE"}
|
podColumns = []string{"NAME", "READY", "STATUS", "RESTARTS", "AGE"}
|
||||||
podTemplateColumns = []string{"TEMPLATE", "CONTAINER(S)", "IMAGE(S)", "PODLABELS"}
|
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"}
|
replicationControllerColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
|
||||||
replicaSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
|
replicaSetColumns = []string{"NAME", "DESIRED", "CURRENT", "READY", "AGE"}
|
||||||
jobColumns = []string{"NAME", "DESIRED", "SUCCESSFUL", "AGE"}
|
jobColumns = []string{"NAME", "DESIRED", "SUCCESSFUL", "AGE"}
|
||||||
@ -842,20 +842,11 @@ func printPodDisruptionBudget(pdb *policy.PodDisruptionBudget, w io.Writer, opti
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n",
|
||||||
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",
|
|
||||||
name,
|
name,
|
||||||
pdb.Spec.MinAvailable.String(),
|
pdb.Spec.MinAvailable.String(),
|
||||||
selector,
|
pdb.Status.PodDisruptionsAllowed,
|
||||||
disruptions,
|
translateTimestamp(pdb.CreationTimestamp),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
|
"k8s.io/kubernetes/pkg/apis/policy"
|
||||||
kubectltesting "k8s.io/kubernetes/pkg/kubectl/testing"
|
kubectltesting "k8s.io/kubernetes/pkg/kubectl/testing"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
yamlserializer "k8s.io/kubernetes/pkg/runtime/serializer/yaml"
|
yamlserializer "k8s.io/kubernetes/pkg/runtime/serializer/yaml"
|
||||||
@ -1622,3 +1623,35 @@ func TestPrintService(t *testing.T) {
|
|||||||
buf.Reset()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user