Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/#661
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun208 committed Apr 15, 2020
2 parents 84162e1 + 6cccc6b commit 522f1e8
Show file tree
Hide file tree
Showing 76 changed files with 1,293 additions and 79 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## master
* feat kuma-dp and kumactl can communiate with kuma-cp over https
[#633](https://github.com/Kong/kuma/pull/633)
* feat(kuma-cp) envoy configs for fault injections
[#649](https://github.com/Kong/kuma/pull/649)
* feat: endpoints for fetching resources from all meshes
Expand Down Expand Up @@ -43,7 +45,8 @@
[#622](https://github.com/Kong/kuma/pull/622)
* feature: validate `<port>.service.kuma.io/protocol` annotations on K8S Service objects
[#611](https://github.com/Kong/kuma/pull/611)

* feat: added `kumactl get` command for individual resources
[#667](https://github.com/Kong/kuma/pull/667)
## [0.4.0]

> Released on 2020/02/28
Expand Down
7 changes: 6 additions & 1 deletion app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"crypto/tls"
"io/ioutil"
"net/http"
"os"
Expand All @@ -27,7 +28,11 @@ type CatalogClientFactory func(string) (client.CatalogClient, error)
var (
runLog = dataplaneLog.WithName("run")
// overridable by tests
bootstrapGenerator = envoy.NewRemoteBootstrapGenerator(&http.Client{Timeout: 10 * time.Second})
bootstrapGenerator = envoy.NewRemoteBootstrapGenerator(&http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
},
)
catalogClientFactory = client.NewCatalogClient
)

Expand Down
4 changes: 3 additions & 1 deletion app/kumactl/cmd/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apply

import (
"context"
"crypto/tls"
"io/ioutil"
"net/http"
"strings"
Expand Down Expand Up @@ -56,7 +57,8 @@ func NewApplyCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
} else {
if strings.HasPrefix(ctx.args.file, "http://") || strings.HasPrefix(ctx.args.file, "https://") {
client := &http.Client{
Timeout: timeout,
Timeout: timeout,
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
req, err := http.NewRequest("GET", ctx.args.file, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/kumactl/cmd/apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var _ = Describe("kumactl apply", func() {

// then
Expect(resource.Meta.GetName()).To(Equal("sample"))
Expect(resource.Meta.GetMesh()).To(Equal(""))
Expect(resource.Meta.GetMesh()).To(Equal("sample"))
})

It("should apply a new Dataplane resource from URL", func() {
Expand Down Expand Up @@ -251,7 +251,7 @@ var _ = Describe("kumactl apply", func() {

// then
Expect(resource.Meta.GetName()).To(Equal("meshinit"))
Expect(resource.Meta.GetMesh()).To(Equal(""))
Expect(resource.Meta.GetMesh()).To(Equal("meshinit"))
})

It("should return kuma api server error", func() {
Expand Down
9 changes: 9 additions & 0 deletions app/kumactl/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,14 @@ func NewGetCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
cmd.AddCommand(newGetTrafficLogsCmd(ctx))
cmd.AddCommand(newGetTrafficTracesCmd(ctx))
cmd.AddCommand(newGetFaultInjectionsCmd(ctx))
cmd.AddCommand(newGetFaultInjectionCmd(ctx))
cmd.AddCommand(newGetMeshCmd(ctx))
cmd.AddCommand(newGetDataplaneCmd(ctx))
cmd.AddCommand(newGetHealthCheckCmd(ctx))
cmd.AddCommand(newGetProxyTemplateCmd(ctx))
cmd.AddCommand(newGetTrafficLogCmd(ctx))
cmd.AddCommand(newGetTrafficPermissionCmd(ctx))
cmd.AddCommand(newGetTrafficRouteCmd(ctx))
cmd.AddCommand(newGetTrafficTraceCmd(ctx))
return cmd
}
52 changes: 52 additions & 0 deletions app/kumactl/cmd/get/get_dataplane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package get

import (
"context"

"github.com/pkg/errors"

"github.com/Kong/kuma/pkg/core/resources/apis/mesh"

"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/output"
"github.com/Kong/kuma/app/kumactl/pkg/output/printers"
rest_types "github.com/Kong/kuma/pkg/core/resources/model/rest"
"github.com/Kong/kuma/pkg/core/resources/store"
)

func newGetDataplaneCmd(pctx *getContext) *cobra.Command {
cmd := &cobra.Command{
Use: "dataplane NAME",
Short: "Show a single Dataplane resource",
Long: `Show a single Dataplane resource.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
rs, err := pctx.CurrentResourceStore()
if err != nil {
return err
}
name := args[0]
currentMesh := pctx.CurrentMesh()
dataplane := &mesh.DataplaneResource{}
if err := rs.Get(context.Background(), dataplane, store.GetByKey(name, currentMesh)); err != nil {
if store.IsResourceNotFound(err) {
return errors.Errorf("No resources found in %s mesh", currentMesh)
}
return errors.Wrapf(err, "failed to get mesh %s", currentMesh)
}
dataplanes := []*mesh.DataplaneResource{dataplane}
switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printDataplanes(dataplanes, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
return err
}
return printer.Print(rest_types.From.Resource(dataplane), cmd.OutOrStdout())
}
},
}
return cmd
}
8 changes: 4 additions & 4 deletions app/kumactl/cmd/get/get_dataplanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newGetDataplanesCmd(pctx *getContext) *cobra.Command {

switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printDataplanes(&dataplanes, cmd.OutOrStdout())
return printDataplanes(dataplanes.Items, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
Expand All @@ -45,17 +45,17 @@ func newGetDataplanesCmd(pctx *getContext) *cobra.Command {
return cmd
}

func printDataplanes(dataplanes *mesh.DataplaneResourceList, out io.Writer) error {
func printDataplanes(dataplanes []*mesh.DataplaneResource, out io.Writer) error {
data := printers.Table{
Headers: []string{"MESH", "NAME", "TAGS"},
NextRow: func() func() []string {
i := 0
return func() []string {
defer func() { i++ }()
if len(dataplanes.Items) <= i {
if len(dataplanes) <= i {
return nil
}
dataplane := dataplanes.Items[i]
dataplane := dataplanes[i]

return []string{
dataplane.Meta.GetMesh(), // MESH
Expand Down
52 changes: 52 additions & 0 deletions app/kumactl/cmd/get/get_fault_injection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package get

import (
"context"

"github.com/pkg/errors"

"github.com/Kong/kuma/pkg/core/resources/apis/mesh"

"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/output"
"github.com/Kong/kuma/app/kumactl/pkg/output/printers"
rest_types "github.com/Kong/kuma/pkg/core/resources/model/rest"
"github.com/Kong/kuma/pkg/core/resources/store"
)

func newGetFaultInjectionCmd(pctx *getContext) *cobra.Command {
cmd := &cobra.Command{
Use: "fault-injection NAME",
Short: "Show a single Fault-Injection resource",
Long: `Show a single Fault-Injection resource.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
rs, err := pctx.CurrentResourceStore()
if err != nil {
return err
}
name := args[0]
currentMesh := pctx.CurrentMesh()
faultInjection := &mesh.FaultInjectionResource{}
if err := rs.Get(context.Background(), faultInjection, store.GetByKey(name, currentMesh)); err != nil {
if store.IsResourceNotFound(err) {
return errors.Errorf("No resources found in %s mesh", currentMesh)
}
return errors.Wrapf(err, "failed to get mesh %s", currentMesh)
}
faultInjections := []*mesh.FaultInjectionResource{faultInjection}
switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printFaultInjections(faultInjections, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
return err
}
return printer.Print(rest_types.From.Resource(faultInjection), cmd.OutOrStdout())
}
},
}
return cmd
}
12 changes: 6 additions & 6 deletions app/kumactl/cmd/get/get_fault_injections.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newGetFaultInjectionsCmd(pctx *getContext) *cobra.Command {

switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printFaultInjection(&faultInjections, cmd.OutOrStdout())
return printFaultInjections(faultInjections.Items, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
Expand All @@ -45,21 +45,21 @@ func newGetFaultInjectionsCmd(pctx *getContext) *cobra.Command {
return cmd
}

func printFaultInjection(faultInjections *mesh.FaultInjectionResourceList, out io.Writer) error {
func printFaultInjections(faultInjections []*mesh.FaultInjectionResource, out io.Writer) error {
data := printers.Table{
Headers: []string{"MESH", "NAME"},
NextRow: func() func() []string {
i := 0
return func() []string {
defer func() { i++ }()
if len(faultInjections.Items) <= i {
if len(faultInjections) <= i {
return nil
}
faultInjections := faultInjections.Items[i]
faultInjection := faultInjections[i]

return []string{
faultInjections.GetMeta().GetMesh(), // MESH
faultInjections.GetMeta().GetName(), // NAME
faultInjection.GetMeta().GetMesh(), // MESH
faultInjection.GetMeta().GetName(), // NAME
}
}
}(),
Expand Down
50 changes: 50 additions & 0 deletions app/kumactl/cmd/get/get_health_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package get

import (
"context"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/output"
"github.com/Kong/kuma/app/kumactl/pkg/output/printers"
"github.com/Kong/kuma/pkg/core/resources/apis/mesh"
rest_types "github.com/Kong/kuma/pkg/core/resources/model/rest"
"github.com/Kong/kuma/pkg/core/resources/store"
)

func newGetHealthCheckCmd(pctx *getContext) *cobra.Command {
cmd := &cobra.Command{
Use: "healthcheck NAME",
Short: "Show a single HealthCheck resource",
Long: `Show a single HealthCheck resource.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
rs, err := pctx.CurrentResourceStore()
if err != nil {
return err
}
name := args[0]
currentMesh := pctx.CurrentMesh()
healthcheck := &mesh.HealthCheckResource{}
if err := rs.Get(context.Background(), healthcheck, store.GetByKey(name, currentMesh)); err != nil {
if store.IsResourceNotFound(err) {
return errors.Errorf("No resources found in %s mesh", currentMesh)
}
return errors.Wrapf(err, "failed to get mesh %s", currentMesh)
}
healthchecks := []*mesh.HealthCheckResource{healthcheck}
switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printHealthChecks(healthchecks, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
return err
}
return printer.Print(rest_types.From.Resource(healthcheck), cmd.OutOrStdout())
}
},
}
return cmd
}
8 changes: 4 additions & 4 deletions app/kumactl/cmd/get/get_healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newGetHealthChecksCmd(pctx *getContext) *cobra.Command {

switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return PrintHealthChecks(healthChecks, cmd.OutOrStdout())
return printHealthChecks(healthChecks.Items, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
Expand All @@ -45,17 +45,17 @@ func newGetHealthChecksCmd(pctx *getContext) *cobra.Command {
return cmd
}

func PrintHealthChecks(healthChecks *mesh_core.HealthCheckResourceList, out io.Writer) error {
func printHealthChecks(healthChecks []*mesh_core.HealthCheckResource, out io.Writer) error {
data := printers.Table{
Headers: []string{"MESH", "NAME"},
NextRow: func() func() []string {
i := 0
return func() []string {
defer func() { i++ }()
if len(healthChecks.Items) <= i {
if len(healthChecks) <= i {
return nil
}
healthCheck := healthChecks.Items[i]
healthCheck := healthChecks[i]

return []string{
healthCheck.Meta.GetMesh(), // MESH
Expand Down
52 changes: 52 additions & 0 deletions app/kumactl/cmd/get/get_mesh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package get

import (
"context"

"github.com/pkg/errors"

core_mesh "github.com/Kong/kuma/pkg/core/resources/apis/mesh"

"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/output"
"github.com/Kong/kuma/app/kumactl/pkg/output/printers"
rest_types "github.com/Kong/kuma/pkg/core/resources/model/rest"
"github.com/Kong/kuma/pkg/core/resources/store"
)

func newGetMeshCmd(pctx *getContext) *cobra.Command {
cmd := &cobra.Command{
Use: "mesh NAME",
Short: "Show a single Mesh resource",
Long: `Show a single Mesh resource.`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
rs, err := pctx.CurrentResourceStore()
if err != nil {
return err
}
name := args[0]
currentMesh := name
mesh := &core_mesh.MeshResource{}
if err := rs.Get(context.Background(), mesh, store.GetByKey(name, currentMesh)); err != nil {
if store.IsResourceNotFound(err) {
return errors.Errorf("No resources found in %s mesh", currentMesh)
}
return errors.Wrapf(err, "failed to get mesh %s", currentMesh)
}
meshes := []*core_mesh.MeshResource{mesh}
switch format := output.Format(pctx.args.outputFormat); format {
case output.TableFormat:
return printMeshes(meshes, cmd.OutOrStdout())
default:
printer, err := printers.NewGenericPrinter(format)
if err != nil {
return err
}
return printer.Print(rest_types.From.Resource(mesh), cmd.OutOrStdout())
}
},
}
return cmd
}
Loading

0 comments on commit 522f1e8

Please sign in to comment.