Skip to content

Commit

Permalink
[CONSUL-542] Create OS Specific Files for Envoy Package (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
joselo85 committed Dec 21, 2022
1 parent 1860c93 commit 4c004b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
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 @@ -84,7 +80,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 @@ -110,17 +106,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 @@ -268,11 +257,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 @@ -439,7 +427,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 @@ -482,7 +470,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 @@ -525,11 +513,7 @@ func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {

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

// Fallback to the old certificate configuration, if none was defined.
Expand Down Expand Up @@ -570,8 +554,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

0 comments on commit 4c004b5

Please sign in to comment.