-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
proxy list
and proxy read
commands to Consul on Kubernetes CLI
* Add a `PortForward` struct which enables the CLI to port forward `localhost` to Kubernetes Pods. * Add a command, `consul-k8s proxy list`, which lists all Kubernetes Pods running Envoy proxies managed by Consul. * Add a command, `consul-k8s proxy read <podname>`, which prints a summary of the Envoy configuration for the proxy running on a given Pod. * Add behavior testing the new commands to the existing Connect Inject acceptance tests.
- Loading branch information
Thomas Eckert
authored
Aug 9, 2022
1 parent
bfd6407
commit 2d3ca40
Showing
34 changed files
with
5,842 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/hashicorp/consul-k8s/acceptance/framework/config" | ||
) | ||
|
||
// CLI provides access to compile and execute commands with the `consul-k8s` CLI. | ||
type CLI struct { | ||
initialized bool | ||
} | ||
|
||
// NewCLI compiles the `consul-k8s` CLI and returns a handle to execute commands | ||
// with the binary. | ||
func NewCLI() (*CLI, error) { | ||
cmd := exec.Command("go", "install", ".") | ||
cmd.Dir = config.CLIPath | ||
_, err := cmd.Output() | ||
return &CLI{true}, err | ||
} | ||
|
||
// Run runs the CLI with the given args. | ||
func (c *CLI) Run(args ...string) ([]byte, error) { | ||
if !c.initialized { | ||
return nil, fmt.Errorf("CLI must be initialized before calling Run, use `cli.NewCLI()` to initialize.") | ||
} | ||
cmd := exec.Command("cli", args...) | ||
return cmd.Output() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package proxy | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/consul-k8s/cli/common" | ||
"github.com/mitchellh/cli" | ||
) | ||
|
||
// ProxyCommand provides a synopsis for the proxy subcommands (e.g. read). | ||
type ProxyCommand struct { | ||
*common.BaseCommand | ||
} | ||
|
||
// Run prints out information about the subcommands. | ||
func (c *ProxyCommand) Run(args []string) int { | ||
return cli.RunResultHelp | ||
} | ||
|
||
func (c *ProxyCommand) Help() string { | ||
return fmt.Sprintf("%s\n\nUsage: consul-k8s proxy <subcommand>", c.Synopsis()) | ||
} | ||
|
||
func (c *ProxyCommand) Synopsis() string { | ||
return "Inspect Envoy proxies managed by Consul." | ||
} |
Oops, something went wrong.