func ExamplePrintServiceWithNamespacesAndLabels() { 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() err := f.PrintObject(cmd, 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| // || }
func ExamplePrintServiceWithNamespacesAndLabels() { f, tf, codec := NewAPIFactory() tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, []string{"l1"}) tf.Client = &client.FakeRESTClient{ Codec: codec, Client: nil, } cmd := NewCmdRun(f, os.Stdout) svc := &api.ServiceList{ Items: []api.Service{ { ObjectMeta: api.ObjectMeta{ Name: "svc1", Namespace: "ns1", 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", 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() err := f.PrintObject(cmd, svc, ld) if err != nil { fmt.Printf("Unexpected error: %v", err) } // Output: // |NAMESPACE NAME LABELS SELECTOR IP(S) PORT(S) L1| // |ns1 svc1 l1=value s=magic 10.1.1.1 53/UDP value| // | 53/TCP | // |ns2 svc2 l1=dolla-bill-yall s=kazam 10.1.1.2 80/TCP dolla-bill-yall| // | 8080/TCP | // || }