Skip to content

Commit

Permalink
feat(kumactl) get commands with age column (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun208 authored May 8, 2020
1 parent b3ba0f0 commit 08e608d
Show file tree
Hide file tree
Showing 64 changed files with 268 additions and 134 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions app/kumactl/cmd/get/get_dataplanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package get
import (
"context"
"io"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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

}
}
}(),
Expand Down
4 changes: 3 additions & 1 deletion app/kumactl/cmd/get/get_dataplanes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"path/filepath"
"strings"
"time"

"github.com/Kong/kuma/app/kumactl/cmd"

Expand Down Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_fault_injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions app/kumactl/cmd/get/get_fault_injections.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package get
import (
"context"
"io"
"time"

"github.com/Kong/kuma/app/kumactl/pkg/output/table"

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
}
}(),
Expand Down
3 changes: 2 additions & 1 deletion app/kumactl/cmd/get/get_fault_injections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions app/kumactl/cmd/get/get_healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package get
import (
"context"
"io"
"time"

"github.com/Kong/kuma/app/kumactl/pkg/output/table"

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
}
}(),
Expand Down
3 changes: 3 additions & 0 deletions app/kumactl/cmd/get/get_healthchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
Expand Down Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions app/kumactl/cmd/get/get_meshes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
}(),
Expand Down
3 changes: 2 additions & 1 deletion app/kumactl/cmd/get/get_meshes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_proxytemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions app/kumactl/cmd/get/get_proxytemplates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package get
import (
"context"
"io"
"time"

"github.com/Kong/kuma/app/kumactl/pkg/output/table"

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
}
}(),
Expand Down
3 changes: 3 additions & 0 deletions app/kumactl/cmd/get/get_proxytemplates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"path/filepath"
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
Expand Down Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion app/kumactl/cmd/get/get_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions app/kumactl/cmd/get/get_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
}
}(),
Expand Down
Loading

0 comments on commit 08e608d

Please sign in to comment.