Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#252 - kumactl get for single entities #667

Merged
merged 30 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2c8a5fa
feature(kumactl) added get command for single resources
tharun208 Apr 6, 2020
e8399bc
feature(kumactl) added get command for single resources
tharun208 Apr 6, 2020
3169c9e
feature(kumactl) added get command for single resource
tharun208 Apr 7, 2020
872170d
feature(kumactl) added get command for single resource
tharun208 Apr 7, 2020
62818d3
feature(kumactl) added get command for single resource
tharun208 Apr 7, 2020
8ffcb9d
feature(kumactl) added get command for single resource
tharun208 Apr 7, 2020
b4e56ab
generic test
jakubdyszkiewicz Apr 8, 2020
7a1c4c5
Merge pull request #1 from Kong/get-cmd
tharun208 Apr 8, 2020
dcdc6e7
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
e93ab12
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
de1a42e
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
b6b4aeb
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
fbba3cd
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
5fc3a5c
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
cdc4320
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
3d3bd6c
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
817be60
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
fd7e49d
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
763917f
feature(kumactl) added get command for single resource
tharun208 Apr 8, 2020
e0b668f
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
1328221
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
6250cf1
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
8349fd4
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
6214080
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
786ad24
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
89ed592
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
9cfcd66
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
c322ccf
feature(kumactl) added get command for single resource
tharun208 Apr 10, 2020
4f1c41b
feature(kumactl) added get command for single resource
tharun208 Apr 14, 2020
c87453c
Merge remote-tracking branch 'origin/master' into feat/#252
tharun208 Apr 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/kumactl/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ func NewGetCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
cmd.AddCommand(newGetTrafficLogsCmd(ctx))
cmd.AddCommand(newGetTrafficTracesCmd(ctx))
cmd.AddCommand(newGetFaultInjectionsCmd(ctx))
cmd.AddCommand(newGetEntitiesCmd(ctx))
return cmd
}
54 changes: 54 additions & 0 deletions app/kumactl/cmd/get/get_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package get

import (
"fmt"

"github.com/Kong/kuma/pkg/core/resources/apis/mesh"
"github.com/Kong/kuma/pkg/core/resources/model"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func newGetEntitiesCmd(pctx *getContext) *cobra.Command {
cmd := &cobra.Command{
Use: "resource TYPE NAME",
Short: "Show Single Resource",
Long: `Show Single Resource.`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
_, err := pctx.CurrentResourceStore()
if err != nil {
return err
}
resourceTypeArg := args[0]

var resourceType model.ResourceType
switch resourceTypeArg {
case "mesh":
resourceType = mesh.MeshType
case "dataplane":
resourceType = mesh.DataplaneType
case "healthcheck":
resourceType = mesh.HealthCheckType
case "proxytemplate":
resourceType = mesh.ProxyTemplateType
case "traffic-log":
resourceType = mesh.TrafficLogType
case "traffic-permission":
resourceType = mesh.TrafficPermissionType
case "traffic-route":
resourceType = mesh.TrafficRouteType
case "traffic-trace":
resourceType = mesh.TrafficTraceType
case "fault-injection":
resourceType = mesh.FaultInjectionType

default:
return errors.Errorf("unknown TYPE: %s. Allowed values: mesh, dataplane, healthcheck, proxytemplate, traffic-log, traffic-permission, traffic-route, traffic-trace, fault-injection", resourceTypeArg)
}
fmt.Println("resource", resourceType)
return nil
},
}
return cmd
}
77 changes: 77 additions & 0 deletions app/kumactl/cmd/get/get_resources_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package get_test

import (
"bytes"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/cmd"
kumactl_cmd "github.com/Kong/kuma/app/kumactl/pkg/cmd"
config_proto "github.com/Kong/kuma/pkg/config/app/kumactl/v1alpha1"
core_store "github.com/Kong/kuma/pkg/core/resources/store"
memory_resources "github.com/Kong/kuma/pkg/plugins/resources/memory"
)

var _ = Describe("kumactl get TYPE NAME", func() {
var rootCtx *kumactl_cmd.RootContext
var rootCmd *cobra.Command
var outbuf, errbuf *bytes.Buffer
var store core_store.ResourceStore

BeforeEach(func() {
// setup
rootCtx = &kumactl_cmd.RootContext{
Runtime: kumactl_cmd.RootRuntime{
Now: time.Now,
NewResourceStore: func(*config_proto.ControlPlaneCoordinates_ApiServer) (core_store.ResourceStore, error) {
return store, nil
},
},
}
store = memory_resources.NewStore()

rootCmd = cmd.NewRootCmd(rootCtx)
outbuf = &bytes.Buffer{}
errbuf = &bytes.Buffer{}
rootCmd.SetOut(outbuf)
rootCmd.SetErr(errbuf)
})
It("should throw an error in case of no args", func() {
// given
rootCmd.SetArgs([]string{
"get", "resource"})

// when
err := rootCmd.Execute()

// then
Expect(err).To(HaveOccurred())
// and
Expect(err.Error()).To(Equal("accepts 2 arg(s), received 0"))
// and
Expect(outbuf.String()).To(MatchRegexp(`Error: accepts 2 arg\(s\), received 0`))
// and
Expect(errbuf.Bytes()).To(BeEmpty())
})
It("should throw an error in case of unsupported resource type", func() {
// given
rootCmd.SetArgs([]string{
"get", "resource", "some-type", "some-name"})

// when
err := rootCmd.Execute()

// then
Expect(err).To(HaveOccurred())
// and
Expect(err.Error()).To(Equal("unknown TYPE: some-type. Allowed values: mesh, dataplane, healthcheck, proxytemplate, traffic-log, traffic-permission, traffic-route, traffic-trace, fault-injection"))
// and
Expect(outbuf.String()).To(MatchRegexp(`unknown TYPE: some-type. Allowed values: mesh, dataplane, healthcheck, proxytemplate, traffic-log, traffic-permission, traffic-route, traffic-trace, fault-injection`))
// and
Expect(errbuf.Bytes()).To(BeEmpty())
})
})
1 change: 1 addition & 0 deletions docs/cmd/kumactl/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ Available Commands:
healthchecks Show HealthChecks
meshes Show Meshes
proxytemplates Show ProxyTemplates
resource Show Single Resource
traffic-logs Show TrafficLogs
traffic-permissions Show TrafficPermissions
traffic-routes Show TrafficRoutes
Expand Down