From 08e608d37e3f5692f0e01434095ca6af3a4f88de Mon Sep 17 00:00:00 2001 From: Tharun Rajendran Date: Fri, 8 May 2020 13:14:36 +0530 Subject: [PATCH] feat(kumactl) get commands with age column (#702) --- CHANGELOG.md | 2 + app/kumactl/cmd/get/get_dataplane.go | 2 +- app/kumactl/cmd/get/get_dataplanes.go | 15 +++-- app/kumactl/cmd/get/get_dataplanes_test.go | 4 +- app/kumactl/cmd/get/get_fault_injection.go | 2 +- app/kumactl/cmd/get/get_fault_injections.go | 12 ++-- .../cmd/get/get_fault_injections_test.go | 3 +- app/kumactl/cmd/get/get_health_check.go | 2 +- app/kumactl/cmd/get/get_healthchecks.go | 12 ++-- app/kumactl/cmd/get/get_healthchecks_test.go | 3 + app/kumactl/cmd/get/get_mesh.go | 2 +- app/kumactl/cmd/get/get_meshes.go | 8 ++- app/kumactl/cmd/get/get_meshes_test.go | 3 +- app/kumactl/cmd/get/get_proxytemplate.go | 2 +- app/kumactl/cmd/get/get_proxytemplates.go | 12 ++-- .../cmd/get/get_proxytemplates_test.go | 3 + app/kumactl/cmd/get/get_secret.go | 2 +- app/kumactl/cmd/get/get_secrets.go | 10 ++- app/kumactl/cmd/get/get_secrets_test.go | 4 +- .../cmd/get/get_single_resource_test.go | 3 + app/kumactl/cmd/get/get_traffic_log.go | 2 +- app/kumactl/cmd/get/get_traffic_logs.go | 12 ++-- app/kumactl/cmd/get/get_traffic_logs_test.go | 3 +- app/kumactl/cmd/get/get_traffic_route.go | 2 +- app/kumactl/cmd/get/get_traffic_routes.go | 12 ++-- .../cmd/get/get_traffic_routes_test.go | 3 + app/kumactl/cmd/get/get_traffic_trace.go | 2 +- app/kumactl/cmd/get/get_traffic_traces.go | 12 ++-- .../cmd/get/get_traffic_traces_test.go | 3 +- app/kumactl/cmd/get/get_trafficpermission.go | 2 +- app/kumactl/cmd/get/get_trafficpermissions.go | 12 ++-- .../cmd/get/get_trafficpermissions_test.go | 3 +- .../cmd/get/testdata/get-dataplane.golden.txt | 4 +- .../get/testdata/get-dataplanes.golden.txt | 6 +- .../get-dataplanes.pagination.golden.txt | 4 +- .../testdata/get-fault-injection.golden.txt | 4 +- .../testdata/get-fault-injections.golden.txt | 6 +- ...get-fault-injections.pagination.golden.txt | 4 +- .../get/testdata/get-healthcheck.golden.txt | 4 +- .../get/testdata/get-healthchecks.golden.txt | 6 +- .../get-healthchecks.pagination.golden.txt | 4 +- .../cmd/get/testdata/get-mesh.golden.txt | 4 +- .../cmd/get/testdata/get-meshes.golden.txt | 6 +- .../testdata/get-meshes.pagination.golden.txt | 4 +- .../get/testdata/get-proxytemplate.golden.txt | 4 +- .../testdata/get-proxytemplates.golden.txt | 6 +- .../get-proxytemplates.pagination.golden.txt | 4 +- .../cmd/get/testdata/get-secret.golden.txt | 4 +- .../cmd/get/testdata/get-secrets.golden.txt | 6 +- .../get/testdata/get-traffic-log.golden.txt | 4 +- .../get/testdata/get-traffic-logs.golden.txt | 6 +- .../get-traffic-logs.pagination.golden.txt | 4 +- .../get-traffic-permission.golden.txt | 4 +- .../get-traffic-permissions.golden.txt | 6 +- ...-traffic-permissions.pagination.golden.txt | 4 +- .../get/testdata/get-traffic-route.golden.txt | 4 +- .../testdata/get-traffic-routes.golden.txt | 6 +- .../get-traffic-routes.pagination.golden.txt | 4 +- .../get/testdata/get-traffic-trace.golden.txt | 4 +- .../testdata/get-traffic-traces.golden.txt | 6 +- .../get-traffic-traces.pagination.golden.txt | 4 +- .../testdata/inspect-dataplanes.golden.txt | 2 +- app/kumactl/pkg/output/table/cells.go | 27 +++++++- app/kumactl/pkg/output/table/cells_test.go | 63 +++++++++++++++++++ 64 files changed, 268 insertions(+), 134 deletions(-) create mode 100644 app/kumactl/pkg/output/table/cells_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index bd26b9af481a..59386bc488be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # CHANGELOG ## master +* feat(kumactl) added age column for get commands and updated `inspect dataplanes` lastConnected and lastUpdated to the new format. + [#702](https://github.com/Kong/kuma/pull/702) * feat(kuma-cp) friendly response in K8s mode [#712](https://github.com/Kong/kuma/pull/712) * chore: upgrade go-control-plane up to v0.9.5 diff --git a/app/kumactl/cmd/get/get_dataplane.go b/app/kumactl/cmd/get/get_dataplane.go index a0e71082f1d4..a9d22c90f8d7 100644 --- a/app/kumactl/cmd/get/get_dataplane.go +++ b/app/kumactl/cmd/get/get_dataplane.go @@ -40,7 +40,7 @@ func newGetDataplaneCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printDataplanes(&dataplanes, cmd.OutOrStdout()) + return printDataplanes(pctx.Now(), &dataplanes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_dataplanes.go b/app/kumactl/cmd/get/get_dataplanes.go index a62016d35c11..b0ceb35126f7 100644 --- a/app/kumactl/cmd/get/get_dataplanes.go +++ b/app/kumactl/cmd/get/get_dataplanes.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -33,7 +34,7 @@ func newGetDataplanesCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printDataplanes(&dataplanes, cmd.OutOrStdout()) + return printDataplanes(pctx.Now(), &dataplanes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -46,9 +47,9 @@ func newGetDataplanesCmd(pctx *listContext) *cobra.Command { return cmd } -func printDataplanes(dataplanes *mesh.DataplaneResourceList, out io.Writer) error { +func printDataplanes(rootTime time.Time, dataplanes *mesh.DataplaneResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME", "TAGS"}, + Headers: []string{"MESH", "NAME", "TAGS", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -59,9 +60,11 @@ func printDataplanes(dataplanes *mesh.DataplaneResourceList, out io.Writer) erro dataplane := dataplanes.Items[i] return []string{ - dataplane.Meta.GetMesh(), // MESH - dataplane.Meta.GetName(), // NAME, - dataplane.Spec.Tags().String(), // TAGS + dataplane.Meta.GetMesh(), // MESH + dataplane.Meta.GetName(), // NAME, + dataplane.Spec.Tags().String(), // TAGS + table.TimeSince(dataplane.Meta.GetModificationTime(), rootTime), // AGE + } } }(), diff --git a/app/kumactl/cmd/get/get_dataplanes_test.go b/app/kumactl/cmd/get/get_dataplanes_test.go index 56149803eef9..2f3e243c7ae3 100644 --- a/app/kumactl/cmd/get/get_dataplanes_test.go +++ b/app/kumactl/cmd/get/get_dataplanes_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" "github.com/Kong/kuma/app/kumactl/cmd" @@ -92,12 +93,13 @@ var _ = Describe("kumactl get dataplanes", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore - + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_fault_injection.go b/app/kumactl/cmd/get/get_fault_injection.go index 49e51aab6f6d..13ff8b08ee59 100644 --- a/app/kumactl/cmd/get/get_fault_injection.go +++ b/app/kumactl/cmd/get/get_fault_injection.go @@ -40,7 +40,7 @@ func newGetFaultInjectionCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printFaultInjections(faultInjections, cmd.OutOrStdout()) + return printFaultInjections(pctx.Now(), faultInjections, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_fault_injections.go b/app/kumactl/cmd/get/get_fault_injections.go index 1b8cbec46f5a..1615a0e5c294 100644 --- a/app/kumactl/cmd/get/get_fault_injections.go +++ b/app/kumactl/cmd/get/get_fault_injections.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetFaultInjectionsCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printFaultInjections(&faultInjections, cmd.OutOrStdout()) + return printFaultInjections(pctx.Now(), &faultInjections, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetFaultInjectionsCmd(pctx *listContext) *cobra.Command { return cmd } -func printFaultInjections(faultInjections *mesh.FaultInjectionResourceList, out io.Writer) error { +func printFaultInjections(rootTime time.Time, faultInjections *mesh.FaultInjectionResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printFaultInjections(faultInjections *mesh.FaultInjectionResourceList, out faultInjection := faultInjections.Items[i] return []string{ - faultInjection.GetMeta().GetMesh(), // MESH - faultInjection.GetMeta().GetName(), // NAME + faultInjection.GetMeta().GetMesh(), // MESH + faultInjection.GetMeta().GetName(), // NAME + table.TimeSince(faultInjection.GetMeta().GetModificationTime(), rootTime), // AGE } } }(), diff --git a/app/kumactl/cmd/get/get_fault_injections_test.go b/app/kumactl/cmd/get/get_fault_injections_test.go index d5de5e206c13..b394c56a4a63 100644 --- a/app/kumactl/cmd/get/get_fault_injections_test.go +++ b/app/kumactl/cmd/get/get_fault_injections_test.go @@ -112,11 +112,12 @@ var _ = Describe("kumactl get fault-injections", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ - Now: time.Now, + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_health_check.go b/app/kumactl/cmd/get/get_health_check.go index 7175a6b47db4..ed428e805a44 100644 --- a/app/kumactl/cmd/get/get_health_check.go +++ b/app/kumactl/cmd/get/get_health_check.go @@ -38,7 +38,7 @@ func newGetHealthCheckCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printHealthChecks(healthchecks, cmd.OutOrStdout()) + return printHealthChecks(pctx.Now(), healthchecks, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_healthchecks.go b/app/kumactl/cmd/get/get_healthchecks.go index cca4eb5635d5..94a211f89b8a 100644 --- a/app/kumactl/cmd/get/get_healthchecks.go +++ b/app/kumactl/cmd/get/get_healthchecks.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetHealthChecksCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printHealthChecks(healthChecks, cmd.OutOrStdout()) + return printHealthChecks(pctx.Now(), healthChecks, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetHealthChecksCmd(pctx *listContext) *cobra.Command { return cmd } -func printHealthChecks(healthChecks *mesh_core.HealthCheckResourceList, out io.Writer) error { +func printHealthChecks(rootTime time.Time, healthChecks *mesh_core.HealthCheckResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printHealthChecks(healthChecks *mesh_core.HealthCheckResourceList, out io.W healthCheck := healthChecks.Items[i] return []string{ - healthCheck.Meta.GetMesh(), // MESH - healthCheck.Meta.GetName(), // NAME + healthCheck.Meta.GetMesh(), // MESH + healthCheck.Meta.GetName(), // NAME + table.TimeSince(healthCheck.Meta.GetModificationTime(), rootTime), //AGE } } }(), diff --git a/app/kumactl/cmd/get/get_healthchecks_test.go b/app/kumactl/cmd/get/get_healthchecks_test.go index 4ea499b2f89f..4da8d251ac04 100644 --- a/app/kumactl/cmd/get/get_healthchecks_test.go +++ b/app/kumactl/cmd/get/get_healthchecks_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" @@ -61,10 +62,12 @@ var _ = Describe("kumactl get healthchecks", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_mesh.go b/app/kumactl/cmd/get/get_mesh.go index 08dd30e417d9..ebc893d2f8c1 100644 --- a/app/kumactl/cmd/get/get_mesh.go +++ b/app/kumactl/cmd/get/get_mesh.go @@ -40,7 +40,7 @@ func newGetMeshCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printMeshes(meshes, cmd.OutOrStdout()) + return printMeshes(pctx.Now(), meshes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_meshes.go b/app/kumactl/cmd/get/get_meshes.go index c80ed5fa9128..5d0e9ce99510 100644 --- a/app/kumactl/cmd/get/get_meshes.go +++ b/app/kumactl/cmd/get/get_meshes.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" core_store "github.com/Kong/kuma/pkg/core/resources/store" @@ -35,7 +36,7 @@ func newGetMeshesCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printMeshes(&meshes, cmd.OutOrStdout()) + return printMeshes(pctx.Now(), &meshes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -48,9 +49,9 @@ func newGetMeshesCmd(pctx *listContext) *cobra.Command { return cmd } -func printMeshes(meshes *mesh.MeshResourceList, out io.Writer) error { +func printMeshes(rootTime time.Time, meshes *mesh.MeshResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"NAME", "mTLS", "METRICS", "LOGGING", "TRACING"}, + Headers: []string{"NAME", "mTLS", "METRICS", "LOGGING", "TRACING", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -91,6 +92,7 @@ func printMeshes(meshes *mesh.MeshResourceList, out io.Writer) error { metrics, // METRICS logging, // LOGGING tracing, // TRACING + table.TimeSince(mesh.GetMeta().GetModificationTime(), rootTime), // AGE } } }(), diff --git a/app/kumactl/cmd/get/get_meshes_test.go b/app/kumactl/cmd/get/get_meshes_test.go index 8f91ad003411..7725c9979f74 100644 --- a/app/kumactl/cmd/get/get_meshes_test.go +++ b/app/kumactl/cmd/get/get_meshes_test.go @@ -132,11 +132,12 @@ var _ = Describe("kumactl get meshes", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ - Now: time.Now, + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_proxytemplate.go b/app/kumactl/cmd/get/get_proxytemplate.go index 3d72ed26d420..b4860ecd2ade 100644 --- a/app/kumactl/cmd/get/get_proxytemplate.go +++ b/app/kumactl/cmd/get/get_proxytemplate.go @@ -40,7 +40,7 @@ func newGetProxyTemplateCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printProxyTemplates(proxyTemplates, cmd.OutOrStdout()) + return printProxyTemplates(pctx.Now(), proxyTemplates, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_proxytemplates.go b/app/kumactl/cmd/get/get_proxytemplates.go index ff3f1a0b5895..62c3c52a7300 100644 --- a/app/kumactl/cmd/get/get_proxytemplates.go +++ b/app/kumactl/cmd/get/get_proxytemplates.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetProxyTemplatesCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printProxyTemplates(proxyTemplates, cmd.OutOrStdout()) + return printProxyTemplates(pctx.Now(), proxyTemplates, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetProxyTemplatesCmd(pctx *listContext) *cobra.Command { return cmd } -func printProxyTemplates(proxyTemplates *mesh_core.ProxyTemplateResourceList, out io.Writer) error { +func printProxyTemplates(rootTime time.Time, proxyTemplates *mesh_core.ProxyTemplateResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printProxyTemplates(proxyTemplates *mesh_core.ProxyTemplateResourceList, ou proxyTemplate := proxyTemplates.Items[i] return []string{ - proxyTemplate.GetMeta().GetMesh(), // MESH - proxyTemplate.GetMeta().GetName(), // NAME + proxyTemplate.GetMeta().GetMesh(), // MESH + proxyTemplate.GetMeta().GetName(), // NAME + table.TimeSince(proxyTemplate.GetMeta().GetModificationTime(), rootTime), //AGE } } }(), diff --git a/app/kumactl/cmd/get/get_proxytemplates_test.go b/app/kumactl/cmd/get/get_proxytemplates_test.go index 2482a28c7c4d..489506039b70 100644 --- a/app/kumactl/cmd/get/get_proxytemplates_test.go +++ b/app/kumactl/cmd/get/get_proxytemplates_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" @@ -60,10 +61,12 @@ var _ = Describe("kumactl get proxytemplates", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_secret.go b/app/kumactl/cmd/get/get_secret.go index 6ad4c066c310..f8b148faed92 100644 --- a/app/kumactl/cmd/get/get_secret.go +++ b/app/kumactl/cmd/get/get_secret.go @@ -37,7 +37,7 @@ func newGetSecretCmd(pctx *getContext) *cobra.Command { secrets := []*system.SecretResource{secret} switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printSecrets(secrets, cmd.OutOrStdout()) + return printSecrets(pctx.Now(), secrets, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_secrets.go b/app/kumactl/cmd/get/get_secrets.go index 7edd8f96ecc2..b02b7423136d 100644 --- a/app/kumactl/cmd/get/get_secrets.go +++ b/app/kumactl/cmd/get/get_secrets.go @@ -3,6 +3,9 @@ package get import ( "context" "io" + "time" + + "github.com/Kong/kuma/app/kumactl/pkg/output/table" "github.com/Kong/kuma/pkg/core/resources/apis/system" @@ -33,7 +36,7 @@ func newGetSecretsCmd(pctx *getContext) *cobra.Command { switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printSecrets(secrets.Items, cmd.OutOrStdout()) + return printSecrets(pctx.Now(), secrets.Items, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -46,9 +49,9 @@ func newGetSecretsCmd(pctx *getContext) *cobra.Command { return cmd } -func printSecrets(secrets []*system.SecretResource, out io.Writer) error { +func printSecrets(rootTime time.Time, secrets []*system.SecretResource, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -61,6 +64,7 @@ func printSecrets(secrets []*system.SecretResource, out io.Writer) error { return []string{ secret.Meta.GetMesh(), // MESH secret.Meta.GetName(), // NAME + table.TimeSince(secret.Meta.GetModificationTime(), rootTime), //AGE } } }(), diff --git a/app/kumactl/cmd/get/get_secrets_test.go b/app/kumactl/cmd/get/get_secrets_test.go index c8f7c9f973ef..20e649e7914f 100644 --- a/app/kumactl/cmd/get/get_secrets_test.go +++ b/app/kumactl/cmd/get/get_secrets_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" "github.com/golang/protobuf/ptypes/wrappers" @@ -67,11 +68,12 @@ var _ = Describe("kumactl get secrets", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore - + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewAdminResourceStore: func(string, *config_proto.Context_AdminApiCredentials) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_single_resource_test.go b/app/kumactl/cmd/get/get_single_resource_test.go index 042b92b2769f..9bebc57261be 100644 --- a/app/kumactl/cmd/get/get_single_resource_test.go +++ b/app/kumactl/cmd/get/get_single_resource_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" "github.com/Kong/kuma/pkg/catalog" catalog_client "github.com/Kong/kuma/pkg/catalog/client" @@ -28,9 +29,11 @@ var _ = Describe("kumactl get [resource] NAME", func() { var rootCmd *cobra.Command var outbuf, errbuf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-01T16:05:36.995Z") BeforeEach(func() { rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_traffic_log.go b/app/kumactl/cmd/get/get_traffic_log.go index 96ea552b5a6a..db83142fc5d4 100644 --- a/app/kumactl/cmd/get/get_traffic_log.go +++ b/app/kumactl/cmd/get/get_traffic_log.go @@ -40,7 +40,7 @@ func newGetTrafficLogCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printTrafficLogs(trafficLogs, cmd.OutOrStdout()) + return printTrafficLogs(pctx.Now(), trafficLogs, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_traffic_logs.go b/app/kumactl/cmd/get/get_traffic_logs.go index 2d0638cd45da..9a7be5c67c6f 100644 --- a/app/kumactl/cmd/get/get_traffic_logs.go +++ b/app/kumactl/cmd/get/get_traffic_logs.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetTrafficLogsCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printTrafficLogs(&trafficLogging, cmd.OutOrStdout()) + return printTrafficLogs(pctx.Now(), &trafficLogging, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetTrafficLogsCmd(pctx *listContext) *cobra.Command { return cmd } -func printTrafficLogs(trafficLogging *mesh.TrafficLogResourceList, out io.Writer) error { +func printTrafficLogs(rootTime time.Time, trafficLogging *mesh.TrafficLogResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printTrafficLogs(trafficLogging *mesh.TrafficLogResourceList, out io.Writer trafficLogging := trafficLogging.Items[i] return []string{ - trafficLogging.GetMeta().GetMesh(), // MESH - trafficLogging.GetMeta().GetName(), // NAME + trafficLogging.GetMeta().GetMesh(), // MESH + trafficLogging.GetMeta().GetName(), // NAME + table.TimeSince(trafficLogging.GetMeta().GetModificationTime(), rootTime), //AGE } } }(), diff --git a/app/kumactl/cmd/get/get_traffic_logs_test.go b/app/kumactl/cmd/get/get_traffic_logs_test.go index a294533a2fa8..0b8679536322 100644 --- a/app/kumactl/cmd/get/get_traffic_logs_test.go +++ b/app/kumactl/cmd/get/get_traffic_logs_test.go @@ -90,11 +90,12 @@ var _ = Describe("kumactl get traffic-logs", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ - Now: time.Now, + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_traffic_route.go b/app/kumactl/cmd/get/get_traffic_route.go index e38bb958d3af..f29f12853f9c 100644 --- a/app/kumactl/cmd/get/get_traffic_route.go +++ b/app/kumactl/cmd/get/get_traffic_route.go @@ -40,7 +40,7 @@ func newGetTrafficRouteCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printTrafficRoutes(trafficRoutes, cmd.OutOrStdout()) + return printTrafficRoutes(pctx.Now(), trafficRoutes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_traffic_routes.go b/app/kumactl/cmd/get/get_traffic_routes.go index 3b49bafcd98b..14eb0ce04d04 100644 --- a/app/kumactl/cmd/get/get_traffic_routes.go +++ b/app/kumactl/cmd/get/get_traffic_routes.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetTrafficRoutesCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printTrafficRoutes(trafficRoutes, cmd.OutOrStdout()) + return printTrafficRoutes(pctx.Now(), trafficRoutes, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetTrafficRoutesCmd(pctx *listContext) *cobra.Command { return cmd } -func printTrafficRoutes(trafficRoutes *mesh_core.TrafficRouteResourceList, out io.Writer) error { +func printTrafficRoutes(rootTime time.Time, trafficRoutes *mesh_core.TrafficRouteResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printTrafficRoutes(trafficRoutes *mesh_core.TrafficRouteResourceList, out i trafficroute := trafficRoutes.Items[i] return []string{ - trafficroute.Meta.GetMesh(), // MESH - trafficroute.Meta.GetName(), // NAME + trafficroute.Meta.GetMesh(), // MESH + trafficroute.Meta.GetName(), // NAME + table.TimeSince(trafficroute.Meta.GetModificationTime(), rootTime), // AGE } } }(), diff --git a/app/kumactl/cmd/get/get_traffic_routes_test.go b/app/kumactl/cmd/get/get_traffic_routes_test.go index c71f03f39dbf..577103e00f5e 100644 --- a/app/kumactl/cmd/get/get_traffic_routes_test.go +++ b/app/kumactl/cmd/get/get_traffic_routes_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" @@ -62,10 +63,12 @@ var _ = Describe("kumactl get traffic-routes", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_traffic_trace.go b/app/kumactl/cmd/get/get_traffic_trace.go index ff35c153b459..af501dfb0ae7 100644 --- a/app/kumactl/cmd/get/get_traffic_trace.go +++ b/app/kumactl/cmd/get/get_traffic_trace.go @@ -38,7 +38,7 @@ func newGetTrafficTraceCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printTrafficTraces(trafficTraces, cmd.OutOrStdout()) + return printTrafficTraces(pctx.Now(), trafficTraces, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_traffic_traces.go b/app/kumactl/cmd/get/get_traffic_traces.go index 64e7c6fdd50f..183a05d4f88d 100644 --- a/app/kumactl/cmd/get/get_traffic_traces.go +++ b/app/kumactl/cmd/get/get_traffic_traces.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetTrafficTracesCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printTrafficTraces(&trafficTraces, cmd.OutOrStdout()) + return printTrafficTraces(pctx.Now(), &trafficTraces, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetTrafficTracesCmd(pctx *listContext) *cobra.Command { return cmd } -func printTrafficTraces(trafficTraces *mesh.TrafficTraceResourceList, out io.Writer) error { +func printTrafficTraces(rootTime time.Time, trafficTraces *mesh.TrafficTraceResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printTrafficTraces(trafficTraces *mesh.TrafficTraceResourceList, out io.Wri trafficTraces := trafficTraces.Items[i] return []string{ - trafficTraces.GetMeta().GetMesh(), // MESH - trafficTraces.GetMeta().GetName(), // NAME + trafficTraces.GetMeta().GetMesh(), // MESH + trafficTraces.GetMeta().GetName(), // NAME + table.TimeSince(trafficTraces.GetMeta().GetModificationTime(), rootTime), // AGE } } }(), diff --git a/app/kumactl/cmd/get/get_traffic_traces_test.go b/app/kumactl/cmd/get/get_traffic_traces_test.go index b22b20881e03..de76105364e6 100644 --- a/app/kumactl/cmd/get/get_traffic_traces_test.go +++ b/app/kumactl/cmd/get/get_traffic_traces_test.go @@ -74,11 +74,12 @@ var _ = Describe("kumactl get traffic-traces", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ - Now: time.Now, + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/get_trafficpermission.go b/app/kumactl/cmd/get/get_trafficpermission.go index 2807ab6a5fe8..3c5afef26beb 100644 --- a/app/kumactl/cmd/get/get_trafficpermission.go +++ b/app/kumactl/cmd/get/get_trafficpermission.go @@ -40,7 +40,7 @@ func newGetTrafficPermissionCmd(pctx *getContext) *cobra.Command { } switch format := output.Format(pctx.args.outputFormat); format { case output.TableFormat: - return printTrafficPermissions(trafficPermissions, cmd.OutOrStdout()) + return printTrafficPermissions(pctx.Now(), trafficPermissions, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { diff --git a/app/kumactl/cmd/get/get_trafficpermissions.go b/app/kumactl/cmd/get/get_trafficpermissions.go index a3f26eda3831..b9ee38598305 100644 --- a/app/kumactl/cmd/get/get_trafficpermissions.go +++ b/app/kumactl/cmd/get/get_trafficpermissions.go @@ -3,6 +3,7 @@ package get import ( "context" "io" + "time" "github.com/Kong/kuma/app/kumactl/pkg/output/table" @@ -34,7 +35,7 @@ func newGetTrafficPermissionsCmd(pctx *listContext) *cobra.Command { switch format := output.Format(pctx.getContext.args.outputFormat); format { case output.TableFormat: - return printTrafficPermissions(&trafficPermissions, cmd.OutOrStdout()) + return printTrafficPermissions(pctx.Now(), &trafficPermissions, cmd.OutOrStdout()) default: printer, err := printers.NewGenericPrinter(format) if err != nil { @@ -47,9 +48,9 @@ func newGetTrafficPermissionsCmd(pctx *listContext) *cobra.Command { return cmd } -func printTrafficPermissions(trafficPermissions *mesh.TrafficPermissionResourceList, out io.Writer) error { +func printTrafficPermissions(rootTime time.Time, trafficPermissions *mesh.TrafficPermissionResourceList, out io.Writer) error { data := printers.Table{ - Headers: []string{"MESH", "NAME"}, + Headers: []string{"MESH", "NAME", "AGE"}, NextRow: func() func() []string { i := 0 return func() []string { @@ -60,8 +61,9 @@ func printTrafficPermissions(trafficPermissions *mesh.TrafficPermissionResourceL trafficPermission := trafficPermissions.Items[i] return []string{ - trafficPermission.GetMeta().GetMesh(), // MESH - trafficPermission.GetMeta().GetName(), // NAME + trafficPermission.GetMeta().GetMesh(), // MESH + trafficPermission.GetMeta().GetName(), // NAME + table.TimeSince(trafficPermission.GetMeta().GetModificationTime(), rootTime), //AGE } } }(), diff --git a/app/kumactl/cmd/get/get_trafficpermissions_test.go b/app/kumactl/cmd/get/get_trafficpermissions_test.go index 33fb447fd519..a6653e37940f 100644 --- a/app/kumactl/cmd/get/get_trafficpermissions_test.go +++ b/app/kumactl/cmd/get/get_trafficpermissions_test.go @@ -84,11 +84,12 @@ var _ = Describe("kumactl get traffic-permissions", func() { var rootCmd *cobra.Command var buf *bytes.Buffer var store core_store.ResourceStore + rootTime, _ := time.Parse(time.RFC3339, "2008-04-27T16:05:36.995Z") BeforeEach(func() { // setup rootCtx = &kumactl_cmd.RootContext{ Runtime: kumactl_cmd.RootRuntime{ - Now: time.Now, + Now: func() time.Time { return rootTime }, NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) { return store, nil }, diff --git a/app/kumactl/cmd/get/testdata/get-dataplane.golden.txt b/app/kumactl/cmd/get/testdata/get-dataplane.golden.txt index dfeeb4dfe9f3..fdd8b66b9504 100644 --- a/app/kumactl/cmd/get/testdata/get-dataplane.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-dataplane.golden.txt @@ -1,2 +1,2 @@ -MESH NAME TAGS -default dataplane-1 service=metrics,mobile version=v1 \ No newline at end of file +MESH NAME TAGS AGE +default dataplane-1 service=metrics,mobile version=v1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-dataplanes.golden.txt b/app/kumactl/cmd/get/testdata/get-dataplanes.golden.txt index d90acd57f7cf..5be2c667e400 100644 --- a/app/kumactl/cmd/get/testdata/get-dataplanes.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-dataplanes.golden.txt @@ -1,3 +1,3 @@ -MESH NAME TAGS -default experiment service=metrics,mobile version=v1 -default example service=web version=v2 +MESH NAME TAGS AGE +default experiment service=metrics,mobile version=v1 292y +default example service=web version=v2 292y diff --git a/app/kumactl/cmd/get/testdata/get-dataplanes.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-dataplanes.pagination.golden.txt index 122eb186abb1..1d4fba5cd6df 100644 --- a/app/kumactl/cmd/get/testdata/get-dataplanes.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-dataplanes.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME TAGS -default experiment service=metrics,mobile version=v1 +MESH NAME TAGS AGE +default experiment service=metrics,mobile version=v1 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-fault-injection.golden.txt b/app/kumactl/cmd/get/testdata/get-fault-injection.golden.txt index ce913656fa47..409f5f0faa33 100644 --- a/app/kumactl/cmd/get/testdata/get-fault-injection.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-fault-injection.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default fault-injection-1 \ No newline at end of file +MESH NAME AGE +default fault-injection-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-fault-injections.golden.txt b/app/kumactl/cmd/get/testdata/get-fault-injections.golden.txt index 0a2b34dd4788..a6c4ec25239b 100644 --- a/app/kumactl/cmd/get/testdata/get-fault-injections.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-fault-injections.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default fi1 -default fi2 \ No newline at end of file +MESH NAME AGE +default fi1 292y +default fi2 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-fault-injections.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-fault-injections.pagination.golden.txt index 2496443cad40..5848016f7d89 100644 --- a/app/kumactl/cmd/get/testdata/get-fault-injections.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-fault-injections.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default fi1 +MESH NAME AGE +default fi1 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-healthcheck.golden.txt b/app/kumactl/cmd/get/testdata/get-healthcheck.golden.txt index f331c00fcfc2..4050ae801269 100644 --- a/app/kumactl/cmd/get/testdata/get-healthcheck.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-healthcheck.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default healthcheck-1 \ No newline at end of file +MESH NAME AGE +default healthcheck-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-healthchecks.golden.txt b/app/kumactl/cmd/get/testdata/get-healthchecks.golden.txt index 7f942dee132a..84b2f790828f 100644 --- a/app/kumactl/cmd/get/testdata/get-healthchecks.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-healthchecks.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default web-to-backend -default backend-to-db +MESH NAME AGE +default web-to-backend 292y +default backend-to-db 292y diff --git a/app/kumactl/cmd/get/testdata/get-healthchecks.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-healthchecks.pagination.golden.txt index b671584eb545..b4144848323b 100644 --- a/app/kumactl/cmd/get/testdata/get-healthchecks.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-healthchecks.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default web-to-backend +MESH NAME AGE +default web-to-backend 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-mesh.golden.txt b/app/kumactl/cmd/get/testdata/get-mesh.golden.txt index 622b3c1b3ddd..8d4a70391eac 100644 --- a/app/kumactl/cmd/get/testdata/get-mesh.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-mesh.golden.txt @@ -1,2 +1,2 @@ -NAME mTLS METRICS LOGGING TRACING -mesh-1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu +NAME mTLS METRICS LOGGING TRACING AGE +mesh-1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu 292y diff --git a/app/kumactl/cmd/get/testdata/get-meshes.golden.txt b/app/kumactl/cmd/get/testdata/get-meshes.golden.txt index 7242defced6e..11f7eb729429 100644 --- a/app/kumactl/cmd/get/testdata/get-meshes.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-meshes.golden.txt @@ -1,3 +1,3 @@ -NAME mTLS METRICS LOGGING TRACING -mesh1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu -mesh2 off off off off +NAME mTLS METRICS LOGGING TRACING AGE +mesh1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu 292y +mesh2 off off off off 292y diff --git a/app/kumactl/cmd/get/testdata/get-meshes.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-meshes.pagination.golden.txt index 12d54ea4b193..8e74491d8c84 100644 --- a/app/kumactl/cmd/get/testdata/get-meshes.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-meshes.pagination.golden.txt @@ -1,4 +1,4 @@ -NAME mTLS METRICS LOGGING TRACING -mesh1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu +NAME mTLS METRICS LOGGING TRACING AGE +mesh1 builtin/builtin-1 prometheus/prometheus-1 logstash, file zipkin-us, zipkin-eu 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-proxytemplate.golden.txt b/app/kumactl/cmd/get/testdata/get-proxytemplate.golden.txt index 7c867d52536e..0b7142d00eae 100644 --- a/app/kumactl/cmd/get/testdata/get-proxytemplate.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-proxytemplate.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default proxytemplate-1 \ No newline at end of file +MESH NAME AGE +default proxytemplate-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-proxytemplates.golden.txt b/app/kumactl/cmd/get/testdata/get-proxytemplates.golden.txt index d6516e346dd5..09c986b5e074 100644 --- a/app/kumactl/cmd/get/testdata/get-proxytemplates.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-proxytemplates.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default custom-template -default another-template +MESH NAME AGE +default custom-template 292y +default another-template 292y diff --git a/app/kumactl/cmd/get/testdata/get-proxytemplates.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-proxytemplates.pagination.golden.txt index 58ed57bb3686..8fb9c02fff6e 100644 --- a/app/kumactl/cmd/get/testdata/get-proxytemplates.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-proxytemplates.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default custom-template +MESH NAME AGE +default custom-template 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-secret.golden.txt b/app/kumactl/cmd/get/testdata/get-secret.golden.txt index 10da2b34bc80..92d4bbcde569 100644 --- a/app/kumactl/cmd/get/testdata/get-secret.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-secret.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default secret-1 +MESH NAME AGE +default secret-1 292y diff --git a/app/kumactl/cmd/get/testdata/get-secrets.golden.txt b/app/kumactl/cmd/get/testdata/get-secrets.golden.txt index f267b7993a74..8e845871e8e2 100644 --- a/app/kumactl/cmd/get/testdata/get-secrets.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-secrets.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default sec-1 -default sec-2 +MESH NAME AGE +default sec-1 292y +default sec-2 292y diff --git a/app/kumactl/cmd/get/testdata/get-traffic-log.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-log.golden.txt index 3e3501eb8dee..982646c9116a 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-log.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-log.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default traffic-log-1 \ No newline at end of file +MESH NAME AGE +default traffic-log-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-traffic-logs.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-logs.golden.txt index 5291a25da97c..bed512a5c82c 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-logs.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-logs.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default web1-to-backend1 -default web2-to-backend2 +MESH NAME AGE +default web1-to-backend1 292y +default web2-to-backend2 292y diff --git a/app/kumactl/cmd/get/testdata/get-traffic-logs.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-logs.pagination.golden.txt index 7613e2052127..ebe39cc767bb 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-logs.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-logs.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default web1-to-backend1 +MESH NAME AGE +default web1-to-backend1 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-traffic-permission.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-permission.golden.txt index 689a598ae0d2..3ec026c4678d 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-permission.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-permission.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default traffic-permission-1 \ No newline at end of file +MESH NAME AGE +default traffic-permission-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-traffic-permissions.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-permissions.golden.txt index 5291a25da97c..bed512a5c82c 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-permissions.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-permissions.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default web1-to-backend1 -default web2-to-backend2 +MESH NAME AGE +default web1-to-backend1 292y +default web2-to-backend2 292y diff --git a/app/kumactl/cmd/get/testdata/get-traffic-permissions.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-permissions.pagination.golden.txt index 7613e2052127..ebe39cc767bb 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-permissions.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-permissions.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default web1-to-backend1 +MESH NAME AGE +default web1-to-backend1 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-traffic-route.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-route.golden.txt index b3660e641773..5f9eb0adb0d2 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-route.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-route.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default traffic-route-1 \ No newline at end of file +MESH NAME AGE +default traffic-route-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-traffic-routes.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-routes.golden.txt index 7f942dee132a..84b2f790828f 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-routes.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-routes.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default web-to-backend -default backend-to-db +MESH NAME AGE +default web-to-backend 292y +default backend-to-db 292y diff --git a/app/kumactl/cmd/get/testdata/get-traffic-routes.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-routes.pagination.golden.txt index b671584eb545..b4144848323b 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-routes.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-routes.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default web-to-backend +MESH NAME AGE +default web-to-backend 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/get/testdata/get-traffic-trace.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-trace.golden.txt index 4952e2142f9a..789bdb894dc2 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-trace.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-trace.golden.txt @@ -1,2 +1,2 @@ -MESH NAME -default traffic-trace-1 \ No newline at end of file +MESH NAME AGE +default traffic-trace-1 292y \ No newline at end of file diff --git a/app/kumactl/cmd/get/testdata/get-traffic-traces.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-traces.golden.txt index 4be9e58fd44e..a544261488fb 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-traces.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-traces.golden.txt @@ -1,3 +1,3 @@ -MESH NAME -default web1 -default web2 +MESH NAME AGE +default web1 292y +default web2 292y diff --git a/app/kumactl/cmd/get/testdata/get-traffic-traces.pagination.golden.txt b/app/kumactl/cmd/get/testdata/get-traffic-traces.pagination.golden.txt index b9d82c3d751b..e6a26a397ff3 100644 --- a/app/kumactl/cmd/get/testdata/get-traffic-traces.pagination.golden.txt +++ b/app/kumactl/cmd/get/testdata/get-traffic-traces.pagination.golden.txt @@ -1,4 +1,4 @@ -MESH NAME -default web1 +MESH NAME AGE +default web1 292y Rerun command with --offset=1 argument to retrieve more resources diff --git a/app/kumactl/cmd/inspect/testdata/inspect-dataplanes.golden.txt b/app/kumactl/cmd/inspect/testdata/inspect-dataplanes.golden.txt index d967aadee8a7..7e7c67d68a29 100644 --- a/app/kumactl/cmd/inspect/testdata/inspect-dataplanes.golden.txt +++ b/app/kumactl/cmd/inspect/testdata/inspect-dataplanes.golden.txt @@ -1,3 +1,3 @@ MESH NAME TAGS STATUS LAST CONNECTED AGO LAST UPDATED AGO TOTAL UPDATES TOTAL ERRORS -default experiment service=metrics,mobile version=v1 Online 2h3m4s never 30 3 +default experiment service=metrics,mobile version=v1 Online 2h never 30 3 default example service=example Offline never never 0 0 \ No newline at end of file diff --git a/app/kumactl/pkg/output/table/cells.go b/app/kumactl/pkg/output/table/cells.go index c24d598f65c8..5de7cf669897 100644 --- a/app/kumactl/pkg/output/table/cells.go +++ b/app/kumactl/pkg/output/table/cells.go @@ -28,5 +28,30 @@ func Ago(m *time.Time, now time.Time) string { if m == nil { return "never" } - return now.Sub(*m).Truncate(time.Second).String() + d := now.Sub(*m) + return Duration(d) +} + +// TimeSince to calculate age of resources +func TimeSince(m time.Time, now time.Time) string { + d := now.Sub(m) + return Duration(d) +} + +// Duration returns a readable representation of the provided time +func Duration(d time.Duration) string { + if seconds := int(d.Seconds()); seconds < -1 { + return fmt.Sprintf("never") + } else if seconds < 0 { + return fmt.Sprintf("0s") + } else if seconds < 60 { + return fmt.Sprintf("%ds", seconds) + } else if minutes := int(d.Minutes()); minutes < 60 { + return fmt.Sprintf("%dm", minutes) + } else if hours := int(d.Hours()); hours < 24 { + return fmt.Sprintf("%dh", hours) + } else if hours < 24*365 { + return fmt.Sprintf("%dd", hours/24) + } + return fmt.Sprintf("%dy", int(d.Hours()/24/365)) } diff --git a/app/kumactl/pkg/output/table/cells_test.go b/app/kumactl/pkg/output/table/cells_test.go new file mode 100644 index 000000000000..9198af72ec2b --- /dev/null +++ b/app/kumactl/pkg/output/table/cells_test.go @@ -0,0 +1,63 @@ +package table_test + +import ( + "time" + + . "github.com/onsi/ginkgo/extensions/table" + + "github.com/Kong/kuma/app/kumactl/pkg/output/table" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("HumanDuration", func() { + type testCase struct { + input time.Duration + output string + } + DescribeTable("should return the correct human readable duration", func(given testCase) { + Expect(table.Duration(given.input)).To(Equal(given.output)) + }, + Entry("should return never for invalid time", testCase{ + input: -2 * time.Second, + output: "never", + }), + Entry("should return 0s if seconds is 0", testCase{ + input: 0, + output: "0s", + }), + Entry("should return second", testCase{ + input: time.Second, + output: "1s", + }), + Entry("should return seconds if duration is less than a minute", testCase{ + input: time.Minute - time.Millisecond, + output: "59s", + }), + Entry("should return minute if duration is minute", testCase{ + input: time.Minute, + output: "1m", + }), + Entry("should return minutes if duration is less than a milliseconds for hour", testCase{ + input: time.Hour - time.Millisecond, + output: "59m", + }), + Entry("should return the correct year if duration is less than a seconds for hour", testCase{ + input: 3*time.Hour - time.Millisecond, + output: "2h", + }), + Entry("should return the day", testCase{ + input: 24 * time.Hour, + output: "1d", + }), + Entry("should return the year", testCase{ + input: 365 * 24 * time.Hour, + output: "1y", + }), + Entry("should return the year if duration is less than a hour for a year", testCase{ + input: 10 * 365 * 24 * time.Hour, + output: "10y", + }), + ) +})