mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
kubectl add show-labels flag to make it more readable
This commit is contained in:
@@ -195,7 +195,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
|
||||
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
||||
return t.Describer, t.Err
|
||||
},
|
||||
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
||||
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
||||
return t.Printer, t.Err
|
||||
},
|
||||
Validator: func(validate bool, cacheDir string) (validation.Schema, error) {
|
||||
@@ -253,7 +253,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
|
||||
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
|
||||
return t.Describer, t.Err
|
||||
},
|
||||
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
||||
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
||||
return t.Printer, t.Err
|
||||
},
|
||||
Validator: func(validate bool, cacheDir string) (validation.Schema, error) {
|
||||
@@ -327,7 +327,7 @@ func stringBody(body string) io.ReadCloser {
|
||||
|
||||
func ExamplePrintReplicationControllerWithNamespace() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, []string{})
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, false, []string{})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
@@ -369,7 +369,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
|
||||
|
||||
func ExamplePrintPodWithWideFormat() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, false, false, []string{})
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, false, false, false, []string{})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
@@ -402,6 +402,45 @@ func ExamplePrintPodWithWideFormat() {
|
||||
// test1 1/2 podPhase 6 10y kubernetes-minion-abcd
|
||||
}
|
||||
|
||||
func ExamplePrintPodWithShowLabels() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, true, false, []string{})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
}
|
||||
nodeName := "kubernetes-minion-abcd"
|
||||
cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr)
|
||||
pod := &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "test1",
|
||||
CreationTimestamp: unversioned.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
Labels: map[string]string{
|
||||
"l1": "key",
|
||||
"l2": "value",
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: "podPhase",
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
}
|
||||
err := f.PrintObject(cmd, pod, os.Stdout)
|
||||
if err != nil {
|
||||
fmt.Printf("Unexpected error: %v", err)
|
||||
}
|
||||
// Output:
|
||||
// NAME READY STATUS RESTARTS AGE LABELS
|
||||
// test1 1/2 podPhase 6 10y l1=key,l2=value
|
||||
}
|
||||
|
||||
func newAllPhasePodList() *api.PodList {
|
||||
nodeName := "kubernetes-minion-abcd"
|
||||
return &api.PodList{
|
||||
@@ -496,7 +535,7 @@ func newAllPhasePodList() *api.PodList {
|
||||
|
||||
func ExamplePrintPodHideTerminated() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, []string{})
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
@@ -516,7 +555,7 @@ func ExamplePrintPodHideTerminated() {
|
||||
|
||||
func ExamplePrintPodShowAll() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, true, false, []string{})
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, true, false, false, []string{})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
@@ -538,7 +577,7 @@ func ExamplePrintPodShowAll() {
|
||||
|
||||
func ExamplePrintServiceWithNamespacesAndLabels() {
|
||||
f, tf, codec := NewAPIFactory()
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, []string{"l1"})
|
||||
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, false, []string{"l1"})
|
||||
tf.Client = &fake.RESTClient{
|
||||
Codec: codec,
|
||||
Client: nil,
|
||||
|
||||
Reference in New Issue
Block a user