func Example_printReplicationController() { f, tf, codec := NewAPIFactory() tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{}) tf.Client = &fake.RESTClient{ Codec: codec, Client: nil, } cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) ctrl := &api.ReplicationController{ ObjectMeta: api.ObjectMeta{ Name: "foo", Labels: map[string]string{"foo": "bar"}, CreationTimestamp: unversioned.Time{Time: time.Now().AddDate(-10, 0, 0)}, }, Spec: api.ReplicationControllerSpec{ Replicas: 1, Selector: map[string]string{"foo": "bar"}, Template: &api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: map[string]string{"foo": "bar"}, }, Spec: api.PodSpec{ Containers: []api.Container{ { Name: "foo", Image: "someimage", }, { Name: "foo2", Image: "someimage", }, }, }, }, }, Status: api.ReplicationControllerStatus{ Replicas: 1, }, } mapper, _ := f.Object(false) err := f.PrintObject(cmd, mapper, ctrl, os.Stdout) if err != nil { fmt.Printf("Unexpected error: %v", err) } // Output: // NAME DESIRED CURRENT AGE // foo 1 1 10y }
func Example_printPodHideTerminated() { f, tf, codec := NewAPIFactory() tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{}) tf.Client = &fake.RESTClient{ Codec: codec, Client: nil, } cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) podList := newAllPhasePodList() mapper, _ := f.Object(false) err := f.PrintObject(cmd, mapper, podList, os.Stdout) if err != nil { fmt.Printf("Unexpected error: %v", err) } // Output: // NAME READY STATUS RESTARTS AGE // test1 1/2 Pending 6 10y // test2 1/2 Running 6 10y // test5 1/2 Unknown 6 10y }
func Example_printPodWithShowLabels() { 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}, }, }, } mapper, _ := f.Object(false) err := f.PrintObject(cmd, mapper, 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 Example_printServiceWithNamespacesAndLabels() { f, tf, codec := NewAPIFactory() tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, false, []string{"l1"}) tf.Client = &fake.RESTClient{ Codec: codec, Client: nil, } cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) svc := &api.ServiceList{ Items: []api.Service{ { ObjectMeta: api.ObjectMeta{ Name: "svc1", Namespace: "ns1", CreationTimestamp: unversioned.Time{Time: time.Now().AddDate(-10, 0, 0)}, Labels: map[string]string{ "l1": "value", }, }, Spec: api.ServiceSpec{ Ports: []api.ServicePort{ {Protocol: "UDP", Port: 53}, {Protocol: "TCP", Port: 53}, }, Selector: map[string]string{ "s": "magic", }, ClusterIP: "10.1.1.1", }, Status: api.ServiceStatus{}, }, { ObjectMeta: api.ObjectMeta{ Name: "svc2", Namespace: "ns2", CreationTimestamp: unversioned.Time{Time: time.Now().AddDate(-10, 0, 0)}, Labels: map[string]string{ "l1": "dolla-bill-yall", }, }, Spec: api.ServiceSpec{ Ports: []api.ServicePort{ {Protocol: "TCP", Port: 80}, {Protocol: "TCP", Port: 8080}, }, Selector: map[string]string{ "s": "kazam", }, ClusterIP: "10.1.1.2", }, Status: api.ServiceStatus{}, }}, } ld := util.NewLineDelimiter(os.Stdout, "|") defer ld.Flush() mapper, _ := f.Object(false) err := f.PrintObject(cmd, mapper, svc, ld) if err != nil { fmt.Printf("Unexpected error: %v", err) } // Output: // |NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE L1| // |ns1 svc1 10.1.1.1 <unknown> 53/UDP,53/TCP 10y value| // |ns2 svc2 10.1.1.2 <unknown> 80/TCP,8080/TCP 10y dolla-bill-yall| // || }