Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions command/connect/envoy/admin_access_log_path_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build linux || darwin
// +build linux darwin

package envoy

const DefaultAdminAccessLogPath = "/dev/null"
6 changes: 6 additions & 0 deletions command/connect/envoy/admin_access_log_path_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build windows
// +build windows

package envoy

const DefaultAdminAccessLogPath = "nul"
44 changes: 14 additions & 30 deletions command/connect/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"os"
"os/exec"
"runtime"
"strings"

"github.com/mitchellh/cli"
Expand All @@ -23,15 +22,12 @@ import (
"github.com/hashicorp/consul/tlsutil"
)

func New(ui cli.Ui, osPlatform string) *cmd {
func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui}
c.init(osPlatform)
c.init()
return c
}

const DefaultUnixAdminAccessLogPath = "/dev/null"
const DefaultWindowsAdminAccessLogPath = "nul"

type cmd struct {
UI cli.Ui
flags *flag.FlagSet
Expand Down Expand Up @@ -82,7 +78,7 @@ var supportedGateways = map[string]api.ServiceKind{
"ingress": api.ServiceKindIngressGateway,
}

func (c *cmd) init(osPlatform string) {
func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)

c.flags.StringVar(&c.proxyID, "proxy-id", os.Getenv("CONNECT_PROXY_ID"),
Expand All @@ -108,17 +104,10 @@ func (c *cmd) init(osPlatform string) {
"The full path to the envoy binary to run. By default will just search "+
"$PATH. Ignored if -bootstrap is used.")

if osPlatform == "windows" {
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultWindowsAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultWindowsAdminAccessLogPath, DefaultWindowsAdminAccessLogPath))
} else {
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultUnixAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultUnixAdminAccessLogPath, DefaultUnixAdminAccessLogPath))
}
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultAdminAccessLogPath, DefaultAdminAccessLogPath))

c.flags.StringVar(&c.adminBind, "admin-bind", "localhost:19000",
"The address:port to start envoy's admin server on. Envoy requires this "+
Expand Down Expand Up @@ -257,11 +246,10 @@ func (c *cmd) Run(args []string) int {
return 1
}
// TODO: refactor
osPlatform := runtime.GOOS
return c.run(c.flags.Args(), osPlatform)
return c.run(c.flags.Args())
}

func (c *cmd) run(args []string, osPlatform string) int {
func (c *cmd) run(args []string) int {

if c.nodeName != "" && c.proxyID == "" {
c.UI.Error("'-node-name' requires '-proxy-id'")
Expand Down Expand Up @@ -428,7 +416,7 @@ func (c *cmd) run(args []string, osPlatform string) int {
}

// Generate config
bootstrapJson, err := c.generateConfig(osPlatform)
bootstrapJson, err := c.generateConfig()
if err != nil {
c.UI.Error(err.Error())
return 1
Expand Down Expand Up @@ -471,7 +459,7 @@ func (c *cmd) findBinary() (string, error) {
return exec.LookPath("envoy")
}

func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {
func (c *cmd) templateArgs() (*BootstrapTplArgs, error) {
httpCfg := api.DefaultConfig()
c.http.MergeOntoConfig(httpCfg)

Expand Down Expand Up @@ -514,11 +502,7 @@ func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {

adminAccessLogPath := c.adminAccessLogPath
if adminAccessLogPath == "" {
if osPlatform == "windows" {
adminAccessLogPath = DefaultWindowsAdminAccessLogPath
} else {
adminAccessLogPath = DefaultUnixAdminAccessLogPath
}
adminAccessLogPath = DefaultAdminAccessLogPath
}

var caPEM string
Expand Down Expand Up @@ -552,8 +536,8 @@ func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {
}, nil
}

func (c *cmd) generateConfig(osPlatform string) ([]byte, error) {
args, err := c.templateArgs(osPlatform)
func (c *cmd) generateConfig() ([]byte, error) {
args, err := c.templateArgs()
if err != nil {
return nil, err
}
Expand Down