From 0a4c136863dc97ccfd7fbae767df745c30fe9473 Mon Sep 17 00:00:00 2001 From: Franco Bruno Lavayen Date: Fri, 30 Sep 2022 16:17:52 -0300 Subject: [PATCH 1/6] [CONSUL-491] Support admin_access_log_path value for Windows (#71) --- command/connect/envoy/envoy.go | 44 ++-- command/connect/envoy/envoy_test.go | 46 +++- .../envoy/testdata/defaults-windows.golden | 210 ++++++++++++++++++ command/registry.go | 5 +- 4 files changed, 282 insertions(+), 23 deletions(-) create mode 100644 command/connect/envoy/testdata/defaults-windows.golden diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index bd5be872ef..953c7d42d7 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -7,6 +7,7 @@ import ( "net" "os" "os/exec" + "runtime" "strings" "github.com/mitchellh/cli" @@ -22,13 +23,14 @@ import ( "github.com/hashicorp/consul/tlsutil" ) -func New(ui cli.Ui) *cmd { +func New(ui cli.Ui, osPlatform string) *cmd { c := &cmd{UI: ui} - c.init() + c.init(osPlatform) return c } -const DefaultAdminAccessLogPath = "/dev/null" +const DefaultUnixAdminAccessLogPath = "/dev/null" +const DefaultWindowsAdminAccessLogPath = "nul" type cmd struct { UI cli.Ui @@ -82,7 +84,7 @@ var supportedGateways = map[string]api.ServiceKind{ "ingress": api.ServiceKindIngressGateway, } -func (c *cmd) init() { +func (c *cmd) init(osPlatform string) { c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags.StringVar(&c.proxyID, "proxy-id", os.Getenv("CONNECT_PROXY_ID"), @@ -108,10 +110,17 @@ func (c *cmd) init() { "The full path to the envoy binary to run. By default will just search "+ "$PATH. Ignored if -bootstrap is used.") - 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)) + 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.adminBind, "admin-bind", "localhost:19000", "The address:port to start envoy's admin server on. Envoy requires this "+ @@ -259,10 +268,11 @@ func (c *cmd) Run(args []string) int { return 1 } // TODO: refactor - return c.run(c.flags.Args()) + osPlatform := runtime.GOOS + return c.run(c.flags.Args(), osPlatform) } -func (c *cmd) run(args []string) int { +func (c *cmd) run(args []string, osPlatform string) int { if c.nodeName != "" && c.proxyID == "" { c.UI.Error("'-node-name' requires '-proxy-id'") @@ -429,7 +439,7 @@ func (c *cmd) run(args []string) int { } // Generate config - bootstrapJson, err := c.generateConfig() + bootstrapJson, err := c.generateConfig(osPlatform) if err != nil { c.UI.Error(err.Error()) return 1 @@ -472,7 +482,7 @@ func (c *cmd) findBinary() (string, error) { return exec.LookPath("envoy") } -func (c *cmd) templateArgs() (*BootstrapTplArgs, error) { +func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) { httpCfg := api.DefaultConfig() c.http.MergeOntoConfig(httpCfg) @@ -515,7 +525,11 @@ func (c *cmd) templateArgs() (*BootstrapTplArgs, error) { adminAccessLogPath := c.adminAccessLogPath if adminAccessLogPath == "" { - adminAccessLogPath = DefaultAdminAccessLogPath + if osPlatform == "windows" { + adminAccessLogPath = DefaultWindowsAdminAccessLogPath + } else { + adminAccessLogPath = DefaultUnixAdminAccessLogPath + } } // Fallback to the old certificate configuration, if none was defined. @@ -556,8 +570,8 @@ func (c *cmd) templateArgs() (*BootstrapTplArgs, error) { }, nil } -func (c *cmd) generateConfig() ([]byte, error) { - args, err := c.templateArgs() +func (c *cmd) generateConfig(osPlatform string) ([]byte, error) { + args, err := c.templateArgs(osPlatform) if err != nil { return nil, err } diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index 31c078dc99..4bb2032da8 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -24,9 +24,11 @@ import ( var update = flag.Bool("update", false, "update golden files") +const defaultOSPlatform = "linux" + func TestEnvoyCommand_noTabs(t *testing.T) { t.Parallel() - if strings.ContainsRune(New(nil).Help(), '\t') { + if strings.ContainsRune(New(nil, defaultOSPlatform).Help(), '\t') { t.Fatal("help has tabs") } } @@ -64,8 +66,8 @@ func TestEnvoyGateway_Validation(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui) - c.init() + c := New(ui, defaultOSPlatform) + c.init(defaultOSPlatform) code := c.Run(tc.args) if code == 0 { @@ -120,6 +122,7 @@ type generateConfigTestCase struct { AgentSelf110 bool // fake the agent API from versions v1.10 and earlier WantArgs BootstrapTplArgs WantErr string + OSPlatform string } // This tests the args we use to generate the template directly because they @@ -160,6 +163,28 @@ func TestGenerateConfig(t *testing.T) { PrometheusScrapePath: "/metrics", }, }, + { + Name: "defaults-windows", + Flags: []string{"-proxy-id", "test-proxy"}, + WantArgs: BootstrapTplArgs{ + ProxyCluster: "test-proxy", + ProxyID: "test-proxy", + // We don't know this til after the lookup so it will be empty in the + // initial args call we are testing here. + ProxySourceService: "", + GRPC: GRPC{ + AgentAddress: "127.0.0.1", + AgentPort: "8502", // Note this is the gRPC port + }, + AdminAccessLogPath: "nul", + AdminBindAddress: "127.0.0.1", + AdminBindPort: "19000", + LocalAgentClusterName: xds.LocalAgentClusterName, + PrometheusBackendPort: "", + PrometheusScrapePath: "/metrics", + }, + OSPlatform: "windows", + }, { Name: "defaults-nodemeta", Flags: []string{"-proxy-id", "test-proxy", "-node-name", "test-node"}, @@ -1101,8 +1126,14 @@ func TestGenerateConfig(t *testing.T) { client, err := api.NewClient(&api.Config{Address: srv.URL, TLSConfig: api.TLSConfig{InsecureSkipVerify: true}}) require.NoError(t, err) + // Default OS Platform "linux". Custom value should be set in the test case + osPlatform := "linux" + if tc.OSPlatform == "windows" { + osPlatform = tc.OSPlatform + } + ui := cli.NewMockUi() - c := New(ui) + c := New(ui, osPlatform) // explicitly set the client to one which can connect to the httptest.Server c.client = client @@ -1111,7 +1142,7 @@ func TestGenerateConfig(t *testing.T) { args := append([]string{"-bootstrap"}, myFlags...) require.NoError(t, c.flags.Parse(args)) - code := c.run(c.flags.Args()) + code := c.run(c.flags.Args(), osPlatform) if tc.WantErr == "" { require.Equal(t, 0, code, ui.ErrorWriter.String()) } else { @@ -1122,7 +1153,8 @@ func TestGenerateConfig(t *testing.T) { // Verify we handled the env and flags right first to get correct template // args. - got, err := c.templateArgs() + got, err := c.templateArgs(osPlatform) + require.NoError(t, err) // Error cases should have returned above require.Equal(t, &tc.WantArgs, got) @@ -1215,7 +1247,7 @@ func TestEnvoy_GatewayRegistration(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui) + c := New(ui, defaultOSPlatform) code := c.Run(tc.args) if code != 0 { diff --git a/command/connect/envoy/testdata/defaults-windows.golden b/command/connect/envoy/testdata/defaults-windows.golden new file mode 100644 index 0000000000..59ef580c5d --- /dev/null +++ b/command/connect/envoy/testdata/defaults-windows.golden @@ -0,0 +1,210 @@ +{ + "admin": { + "access_log_path": "nul", + "address": { + "socket_address": { + "address": "127.0.0.1", + "port_value": 19000 + } + } + }, + "node": { + "cluster": "test", + "id": "test-proxy", + "metadata": { + "namespace": "default", + "partition": "default" + } + }, + "layered_runtime": { + "layers": [ + { + "name": "base", + "static_layer": { + "re2.max_program_size.error_level": 1048576 + } + } + ] + }, + "static_resources": { + "clusters": [ + { + "name": "local_agent", + "ignore_health_on_host_removal": false, + "connect_timeout": "1s", + "type": "STATIC", + "http2_protocol_options": {}, + "loadAssignment": { + "clusterName": "local_agent", + "endpoints": [ + { + "lbEndpoints": [ + { + "endpoint": { + "address": { + "socket_address": { + "address": "127.0.0.1", + "port_value": 8502 + } + } + } + } + ] + } + ] + } + } + ] + }, + "stats_config": { + "stats_tags": [ + { + "regex": "^cluster\\.(?:passthrough~)?((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.custom_hash" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.service_subset" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.service" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.namespace" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:([^.]+)\\.)?[^.]+\\.internal[^.]*\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.partition" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.datacenter" + }, + { + "regex": "^cluster\\.([^.]+\\.(?:[^.]+\\.)?([^.]+)\\.external\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.peer" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.routing_type" + }, + { + "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", + "tag_name": "consul.destination.trust_domain" + }, + { + "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.destination.target" + }, + { + "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", + "tag_name": "consul.destination.full_target" + }, + { + "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.(([^.]+)(?:\\.[^.]+)?(?:\\.[^.]+)?\\.[^.]+\\.)", + "tag_name": "consul.upstream.service" + }, + { + "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.[^.]+)?\\.([^.]+)\\.)", + "tag_name": "consul.upstream.datacenter" + }, + { + "regex": "^(?:tcp|http)\\.upstream_peered\\.([^.]+(?:\\.[^.]+)?\\.([^.]+)\\.)", + "tag_name": "consul.upstream.peer" + }, + { + "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.([^.]+(?:\\.([^.]+))?(?:\\.[^.]+)?\\.[^.]+\\.)", + "tag_name": "consul.upstream.namespace" + }, + { + "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.([^.]+))?\\.[^.]+\\.)", + "tag_name": "consul.upstream.partition" + }, + { + "regex": "^cluster\\.((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.custom_hash" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.service_subset" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.service" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.namespace" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", + "tag_name": "consul.datacenter" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", + "tag_name": "consul.routing_type" + }, + { + "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", + "tag_name": "consul.trust_domain" + }, + { + "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", + "tag_name": "consul.target" + }, + { + "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", + "tag_name": "consul.full_target" + }, + { + "tag_name": "local_cluster", + "fixed_value": "test" + }, + { + "tag_name": "consul.source.service", + "fixed_value": "test" + }, + { + "tag_name": "consul.source.namespace", + "fixed_value": "default" + }, + { + "tag_name": "consul.source.partition", + "fixed_value": "default" + }, + { + "tag_name": "consul.source.datacenter", + "fixed_value": "dc1" + } + ], + "use_all_default_tags": true + }, + "dynamic_resources": { + "lds_config": { + "ads": {}, + "resource_api_version": "V3" + }, + "cds_config": { + "ads": {}, + "resource_api_version": "V3" + }, + "ads_config": { + "api_type": "DELTA_GRPC", + "transport_api_version": "V3", + "grpc_services": { + "initial_metadata": [ + { + "key": "x-consul-token", + "value": "" + } + ], + "envoy_grpc": { + "cluster_name": "local_agent" + } + } + } + } +} + diff --git a/command/registry.go b/command/registry.go index 1d34f746ca..5f8980c60a 100644 --- a/command/registry.go +++ b/command/registry.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/consul/command/operator/raft/transferleader" "os" "os/signal" + "runtime" "syscall" "github.com/hashicorp/consul/command/acl" @@ -126,6 +127,8 @@ import ( "github.com/hashicorp/consul/command/cli" ) +const OSPlatform = runtime.GOOS + // RegisteredCommands returns a realized mapping of available CLI commands in a format that // the CLI class can consume. func RegisteredCommands(ui cli.Ui) map[string]mcli.CommandFactory { @@ -181,7 +184,7 @@ func RegisteredCommands(ui cli.Ui) map[string]mcli.CommandFactory { entry{"connect ca get-config", func(ui cli.Ui) (cli.Command, error) { return caget.New(ui), nil }}, entry{"connect ca set-config", func(ui cli.Ui) (cli.Command, error) { return caset.New(ui), nil }}, entry{"connect proxy", func(ui cli.Ui) (cli.Command, error) { return proxy.New(ui, MakeShutdownCh()), nil }}, - entry{"connect envoy", func(ui cli.Ui) (cli.Command, error) { return envoy.New(ui), nil }}, + entry{"connect envoy", func(ui cli.Ui) (cli.Command, error) { return envoy.New(ui, OSPlatform), nil }}, entry{"connect envoy pipe-bootstrap", func(ui cli.Ui) (cli.Command, error) { return pipebootstrap.New(ui), nil }}, entry{"connect expose", func(ui cli.Ui) (cli.Command, error) { return expose.New(ui), nil }}, entry{"connect redirect-traffic", func(ui cli.Ui) (cli.Command, error) { return redirecttraffic.New(ui), nil }}, From 5e0bec20c6359c92819510601b33265539135450 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo <74208929+joselo85@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:35:46 -0300 Subject: [PATCH 2/6] [CONSUL-519] Implement mkfifo Alternative (#84) --- command/connect/envoy/exec_unsupported.go | 4 +- command/connect/envoy/exec_windows.go | 121 ++++++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 command/connect/envoy/exec_windows.go diff --git a/command/connect/envoy/exec_unsupported.go b/command/connect/envoy/exec_unsupported.go index d22b4c8cdf..4125a021e8 100644 --- a/command/connect/envoy/exec_unsupported.go +++ b/command/connect/envoy/exec_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux && !darwin -// +build !linux,!darwin +//go:build !linux && !darwin && !windows +// +build !linux,!darwin,!windows package envoy diff --git a/command/connect/envoy/exec_windows.go b/command/connect/envoy/exec_windows.go new file mode 100644 index 0000000000..e274c1b0b5 --- /dev/null +++ b/command/connect/envoy/exec_windows.go @@ -0,0 +1,121 @@ +//go:build windows +// +build windows + +package envoy + +import ( + "errors" + "fmt" + "os" + "os/exec" + + "path/filepath" + "strings" + + "time" +) + +// testSelfExecOverride is a way for the tests to no fork-bomb themselves by +// self-executing the whole test suite for each case recursively. It's gross but +// the least gross option I could think of. +var testSelfExecOverride string + +func isHotRestartOption(s string) bool { + restartOpts := []string{ + "--restart-epoch", + "--hot-restart-version", + "--drain-time-s", + "--parent-shutdown-time-s", + } + for _, opt := range restartOpts { + if s == opt { + return true + } + if strings.HasPrefix(s, opt+"=") { + return true + } + } + return false +} + +func hasHotRestartOption(argSets ...[]string) bool { + for _, args := range argSets { + for _, opt := range args { + if isHotRestartOption(opt) { + return true + } + } + } + return false +} + +func makeBootstrapTemp(bootstrapJSON []byte) (string, error) { + tempFile := filepath.Join(os.TempDir(), + fmt.Sprintf("envoy-%x-bootstrap.json", time.Now().UnixNano()+int64(os.Getpid()))) + + f, err := os.Create(tempFile) + if err != nil { + return tempFile, err + } + + defer f.Close() + f.Write(bootstrapJSON) + f.Sync() + + // We can't wait for the process since we need to exec into Envoy before it + // will be able to complete so it will be remain as a zombie until Envoy is + // killed then will be reaped by the init process (pid 0). This is all a bit + // gross but the cleanest workaround I can think of for Envoy 1.10 not + // supporting /dev/fd/ config paths any more. So we are done and leaving + // the child to run it's course without reaping it. + return tempFile, nil +} + +func startProc(binary string, args []string) (p *os.Process, err error) { + if binary, err = exec.LookPath(binary); err == nil { + var procAttr os.ProcAttr + procAttr.Files = []*os.File{os.Stdin, + os.Stdout, os.Stderr} + p, err := os.StartProcess(binary, args, &procAttr) + if err == nil { + return p, nil + } + } + return nil, err +} + +func execEnvoy(binary string, prefixArgs, suffixArgs []string, bootstrapJSON []byte) error { + tempFile, err := makeBootstrapTemp(bootstrapJSON) + if err != nil { + os.RemoveAll(tempFile) + return err + } + // We don't defer a cleanup since we are about to Exec into Envoy which means + // defer will never fire. The child process cleans up for us in the happy + // path. + + // We default to disabling hot restart because it makes it easier to run + // multiple envoys locally for testing without them trying to share memory and + // unix sockets and complain about being different IDs. But if user is + // actually configuring hot-restart explicitly with the --restart-epoch option + // then don't disable it! + disableHotRestart := !hasHotRestartOption(prefixArgs, suffixArgs) + + // First argument needs to be the executable name. + envoyArgs := []string{} + envoyArgs = append(envoyArgs, prefixArgs...) + if disableHotRestart { + envoyArgs = append(envoyArgs, "--disable-hot-restart") + } + envoyArgs = append(envoyArgs, suffixArgs...) + envoyArgs = append(envoyArgs, "--config-path", tempFile) + + // Exec + if proc, err := startProc(binary, envoyArgs); err == nil { + proc.Wait() + } else if err != nil { + return errors.New("Failed to exec envoy: " + err.Error()) + } + + return nil +} From 41c02a060ec6777c216588036be46ec21b314572 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo <74208929+joselo85@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:00:28 -0300 Subject: [PATCH 3/6] [CONSUL-542] Create OS Specific Files for Envoy Package (#88) --- .../envoy/admin_access_log_path_unix.go | 6 +++ .../envoy/admin_access_log_path_windows.go | 6 +++ command/connect/envoy/envoy.go | 44 ++++++------------- 3 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 command/connect/envoy/admin_access_log_path_unix.go create mode 100644 command/connect/envoy/admin_access_log_path_windows.go diff --git a/command/connect/envoy/admin_access_log_path_unix.go b/command/connect/envoy/admin_access_log_path_unix.go new file mode 100644 index 0000000000..aedaa15668 --- /dev/null +++ b/command/connect/envoy/admin_access_log_path_unix.go @@ -0,0 +1,6 @@ +//go:build linux || darwin +// +build linux darwin + +package envoy + +const DefaultAdminAccessLogPath = "/dev/null" diff --git a/command/connect/envoy/admin_access_log_path_windows.go b/command/connect/envoy/admin_access_log_path_windows.go new file mode 100644 index 0000000000..d5e7832476 --- /dev/null +++ b/command/connect/envoy/admin_access_log_path_windows.go @@ -0,0 +1,6 @@ +//go:build windows +// +build windows + +package envoy + +const DefaultAdminAccessLogPath = "nul" diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index 953c7d42d7..acf238f29f 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -7,7 +7,6 @@ import ( "net" "os" "os/exec" - "runtime" "strings" "github.com/mitchellh/cli" @@ -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 @@ -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"), @@ -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 "+ @@ -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'") @@ -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 @@ -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) @@ -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. @@ -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 } From c592e5db89cfd722fb8d7181e378d3f975bf9464 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo <74208929+joselo85@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:04:38 -0300 Subject: [PATCH 4/6] [CONSUL-543] Create exec_supported.go (#89) --- command/connect/envoy/exec_supported.go | 60 +++++++++++++++++++++++++ command/connect/envoy/exec_unix.go | 50 --------------------- command/connect/envoy/exec_windows.go | 35 --------------- command/registry.go | 5 +-- 4 files changed, 61 insertions(+), 89 deletions(-) create mode 100644 command/connect/envoy/exec_supported.go diff --git a/command/connect/envoy/exec_supported.go b/command/connect/envoy/exec_supported.go new file mode 100644 index 0000000000..8122765e0d --- /dev/null +++ b/command/connect/envoy/exec_supported.go @@ -0,0 +1,60 @@ +//go:build linux || darwin || windows +// +build linux darwin windows + +package envoy + +import ( + "fmt" + "os" + "strings" +) + +// testSelfExecOverride is a way for the tests to no fork-bomb themselves by +// self-executing the whole test suite for each case recursively. It's gross but +// the least gross option I could think of. +var testSelfExecOverride string + +func isHotRestartOption(s string) bool { + restartOpts := []string{ + "--restart-epoch", + "--hot-restart-version", + "--drain-time-s", + "--parent-shutdown-time-s", + } + for _, opt := range restartOpts { + if s == opt { + return true + } + if strings.HasPrefix(s, opt+"=") { + return true + } + } + return false +} + +func hasHotRestartOption(argSets ...[]string) bool { + for _, args := range argSets { + for _, opt := range args { + if isHotRestartOption(opt) { + return true + } + } + } + return false +} + +// execArgs returns the command and args used to execute a binary. By default it +// will return a command of os.Executable with the args unmodified. This is a shim +// for testing, and can be overridden to execute using 'go run' instead. +var execArgs = func(args ...string) (string, []string, error) { + execPath, err := os.Executable() + if err != nil { + return "", nil, err + } + + if strings.HasSuffix(execPath, "/envoy.test") { + return "", nil, fmt.Errorf("set execArgs to use 'go run' instead of doing a self-exec") + } + + return execPath, args, nil +} diff --git a/command/connect/envoy/exec_unix.go b/command/connect/envoy/exec_unix.go index 9ab83eecfe..3800b13c44 100644 --- a/command/connect/envoy/exec_unix.go +++ b/command/connect/envoy/exec_unix.go @@ -16,56 +16,6 @@ import ( "golang.org/x/sys/unix" ) -// testSelfExecOverride is a way for the tests to no fork-bomb themselves by -// self-executing the whole test suite for each case recursively. It's gross but -// the least gross option I could think of. -var testSelfExecOverride string - -func isHotRestartOption(s string) bool { - restartOpts := []string{ - "--restart-epoch", - "--hot-restart-version", - "--drain-time-s", - "--parent-shutdown-time-s", - } - for _, opt := range restartOpts { - if s == opt { - return true - } - if strings.HasPrefix(s, opt+"=") { - return true - } - } - return false -} - -func hasHotRestartOption(argSets ...[]string) bool { - for _, args := range argSets { - for _, opt := range args { - if isHotRestartOption(opt) { - return true - } - } - } - return false -} - -// execArgs returns the command and args used to execute a binary. By default it -// will return a command of os.Executable with the args unmodified. This is a shim -// for testing, and can be overridden to execute using 'go run' instead. -var execArgs = func(args ...string) (string, []string, error) { - execPath, err := os.Executable() - if err != nil { - return "", nil, err - } - - if strings.HasSuffix(execPath, "/envoy.test") { - return "", nil, fmt.Errorf("set execArgs to use 'go run' instead of doing a self-exec") - } - - return execPath, args, nil -} - func makeBootstrapPipe(bootstrapJSON []byte) (string, error) { pipeFile := filepath.Join(os.TempDir(), fmt.Sprintf("envoy-%x-bootstrap.json", time.Now().UnixNano()+int64(os.Getpid()))) diff --git a/command/connect/envoy/exec_windows.go b/command/connect/envoy/exec_windows.go index e274c1b0b5..61f0404839 100644 --- a/command/connect/envoy/exec_windows.go +++ b/command/connect/envoy/exec_windows.go @@ -10,45 +10,10 @@ import ( "os/exec" "path/filepath" - "strings" "time" ) -// testSelfExecOverride is a way for the tests to no fork-bomb themselves by -// self-executing the whole test suite for each case recursively. It's gross but -// the least gross option I could think of. -var testSelfExecOverride string - -func isHotRestartOption(s string) bool { - restartOpts := []string{ - "--restart-epoch", - "--hot-restart-version", - "--drain-time-s", - "--parent-shutdown-time-s", - } - for _, opt := range restartOpts { - if s == opt { - return true - } - if strings.HasPrefix(s, opt+"=") { - return true - } - } - return false -} - -func hasHotRestartOption(argSets ...[]string) bool { - for _, args := range argSets { - for _, opt := range args { - if isHotRestartOption(opt) { - return true - } - } - } - return false -} - func makeBootstrapTemp(bootstrapJSON []byte) (string, error) { tempFile := filepath.Join(os.TempDir(), fmt.Sprintf("envoy-%x-bootstrap.json", time.Now().UnixNano()+int64(os.Getpid()))) diff --git a/command/registry.go b/command/registry.go index 5f8980c60a..1d34f746ca 100644 --- a/command/registry.go +++ b/command/registry.go @@ -5,7 +5,6 @@ import ( "github.com/hashicorp/consul/command/operator/raft/transferleader" "os" "os/signal" - "runtime" "syscall" "github.com/hashicorp/consul/command/acl" @@ -127,8 +126,6 @@ import ( "github.com/hashicorp/consul/command/cli" ) -const OSPlatform = runtime.GOOS - // RegisteredCommands returns a realized mapping of available CLI commands in a format that // the CLI class can consume. func RegisteredCommands(ui cli.Ui) map[string]mcli.CommandFactory { @@ -184,7 +181,7 @@ func RegisteredCommands(ui cli.Ui) map[string]mcli.CommandFactory { entry{"connect ca get-config", func(ui cli.Ui) (cli.Command, error) { return caget.New(ui), nil }}, entry{"connect ca set-config", func(ui cli.Ui) (cli.Command, error) { return caset.New(ui), nil }}, entry{"connect proxy", func(ui cli.Ui) (cli.Command, error) { return proxy.New(ui, MakeShutdownCh()), nil }}, - entry{"connect envoy", func(ui cli.Ui) (cli.Command, error) { return envoy.New(ui, OSPlatform), nil }}, + entry{"connect envoy", func(ui cli.Ui) (cli.Command, error) { return envoy.New(ui), nil }}, entry{"connect envoy pipe-bootstrap", func(ui cli.Ui) (cli.Command, error) { return pipebootstrap.New(ui), nil }}, entry{"connect expose", func(ui cli.Ui) (cli.Command, error) { return expose.New(ui), nil }}, entry{"connect redirect-traffic", func(ui cli.Ui) (cli.Command, error) { return redirecttraffic.New(ui), nil }}, From ace9e379d2e947b8ef9a1d314bf345089702ee23 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo <74208929+joselo85@users.noreply.github.com> Date: Thu, 10 Nov 2022 16:00:26 -0300 Subject: [PATCH 5/6] [CONSUL-544] Test and Build Changes (#90) --- command/connect/envoy/envoy_test.go | 46 +--- .../envoy/testdata/defaults-windows.golden | 210 ------------------ 2 files changed, 7 insertions(+), 249 deletions(-) delete mode 100644 command/connect/envoy/testdata/defaults-windows.golden diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index 4bb2032da8..31c078dc99 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -24,11 +24,9 @@ import ( var update = flag.Bool("update", false, "update golden files") -const defaultOSPlatform = "linux" - func TestEnvoyCommand_noTabs(t *testing.T) { t.Parallel() - if strings.ContainsRune(New(nil, defaultOSPlatform).Help(), '\t') { + if strings.ContainsRune(New(nil).Help(), '\t') { t.Fatal("help has tabs") } } @@ -66,8 +64,8 @@ func TestEnvoyGateway_Validation(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui, defaultOSPlatform) - c.init(defaultOSPlatform) + c := New(ui) + c.init() code := c.Run(tc.args) if code == 0 { @@ -122,7 +120,6 @@ type generateConfigTestCase struct { AgentSelf110 bool // fake the agent API from versions v1.10 and earlier WantArgs BootstrapTplArgs WantErr string - OSPlatform string } // This tests the args we use to generate the template directly because they @@ -163,28 +160,6 @@ func TestGenerateConfig(t *testing.T) { PrometheusScrapePath: "/metrics", }, }, - { - Name: "defaults-windows", - Flags: []string{"-proxy-id", "test-proxy"}, - WantArgs: BootstrapTplArgs{ - ProxyCluster: "test-proxy", - ProxyID: "test-proxy", - // We don't know this til after the lookup so it will be empty in the - // initial args call we are testing here. - ProxySourceService: "", - GRPC: GRPC{ - AgentAddress: "127.0.0.1", - AgentPort: "8502", // Note this is the gRPC port - }, - AdminAccessLogPath: "nul", - AdminBindAddress: "127.0.0.1", - AdminBindPort: "19000", - LocalAgentClusterName: xds.LocalAgentClusterName, - PrometheusBackendPort: "", - PrometheusScrapePath: "/metrics", - }, - OSPlatform: "windows", - }, { Name: "defaults-nodemeta", Flags: []string{"-proxy-id", "test-proxy", "-node-name", "test-node"}, @@ -1126,14 +1101,8 @@ func TestGenerateConfig(t *testing.T) { client, err := api.NewClient(&api.Config{Address: srv.URL, TLSConfig: api.TLSConfig{InsecureSkipVerify: true}}) require.NoError(t, err) - // Default OS Platform "linux". Custom value should be set in the test case - osPlatform := "linux" - if tc.OSPlatform == "windows" { - osPlatform = tc.OSPlatform - } - ui := cli.NewMockUi() - c := New(ui, osPlatform) + c := New(ui) // explicitly set the client to one which can connect to the httptest.Server c.client = client @@ -1142,7 +1111,7 @@ func TestGenerateConfig(t *testing.T) { args := append([]string{"-bootstrap"}, myFlags...) require.NoError(t, c.flags.Parse(args)) - code := c.run(c.flags.Args(), osPlatform) + code := c.run(c.flags.Args()) if tc.WantErr == "" { require.Equal(t, 0, code, ui.ErrorWriter.String()) } else { @@ -1153,8 +1122,7 @@ func TestGenerateConfig(t *testing.T) { // Verify we handled the env and flags right first to get correct template // args. - got, err := c.templateArgs(osPlatform) - + got, err := c.templateArgs() require.NoError(t, err) // Error cases should have returned above require.Equal(t, &tc.WantArgs, got) @@ -1247,7 +1215,7 @@ func TestEnvoy_GatewayRegistration(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui, defaultOSPlatform) + c := New(ui) code := c.Run(tc.args) if code != 0 { diff --git a/command/connect/envoy/testdata/defaults-windows.golden b/command/connect/envoy/testdata/defaults-windows.golden deleted file mode 100644 index 59ef580c5d..0000000000 --- a/command/connect/envoy/testdata/defaults-windows.golden +++ /dev/null @@ -1,210 +0,0 @@ -{ - "admin": { - "access_log_path": "nul", - "address": { - "socket_address": { - "address": "127.0.0.1", - "port_value": 19000 - } - } - }, - "node": { - "cluster": "test", - "id": "test-proxy", - "metadata": { - "namespace": "default", - "partition": "default" - } - }, - "layered_runtime": { - "layers": [ - { - "name": "base", - "static_layer": { - "re2.max_program_size.error_level": 1048576 - } - } - ] - }, - "static_resources": { - "clusters": [ - { - "name": "local_agent", - "ignore_health_on_host_removal": false, - "connect_timeout": "1s", - "type": "STATIC", - "http2_protocol_options": {}, - "loadAssignment": { - "clusterName": "local_agent", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socket_address": { - "address": "127.0.0.1", - "port_value": 8502 - } - } - } - } - ] - } - ] - } - } - ] - }, - "stats_config": { - "stats_tags": [ - { - "regex": "^cluster\\.(?:passthrough~)?((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.custom_hash" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.service_subset" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.service" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.namespace" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:([^.]+)\\.)?[^.]+\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.partition" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.datacenter" - }, - { - "regex": "^cluster\\.([^.]+\\.(?:[^.]+\\.)?([^.]+)\\.external\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.peer" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.routing_type" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", - "tag_name": "consul.destination.trust_domain" - }, - { - "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.target" - }, - { - "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", - "tag_name": "consul.destination.full_target" - }, - { - "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.(([^.]+)(?:\\.[^.]+)?(?:\\.[^.]+)?\\.[^.]+\\.)", - "tag_name": "consul.upstream.service" - }, - { - "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.[^.]+)?\\.([^.]+)\\.)", - "tag_name": "consul.upstream.datacenter" - }, - { - "regex": "^(?:tcp|http)\\.upstream_peered\\.([^.]+(?:\\.[^.]+)?\\.([^.]+)\\.)", - "tag_name": "consul.upstream.peer" - }, - { - "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.([^.]+(?:\\.([^.]+))?(?:\\.[^.]+)?\\.[^.]+\\.)", - "tag_name": "consul.upstream.namespace" - }, - { - "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.([^.]+))?\\.[^.]+\\.)", - "tag_name": "consul.upstream.partition" - }, - { - "regex": "^cluster\\.((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.custom_hash" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.service_subset" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.service" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.namespace" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.datacenter" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", - "tag_name": "consul.routing_type" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", - "tag_name": "consul.trust_domain" - }, - { - "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.target" - }, - { - "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", - "tag_name": "consul.full_target" - }, - { - "tag_name": "local_cluster", - "fixed_value": "test" - }, - { - "tag_name": "consul.source.service", - "fixed_value": "test" - }, - { - "tag_name": "consul.source.namespace", - "fixed_value": "default" - }, - { - "tag_name": "consul.source.partition", - "fixed_value": "default" - }, - { - "tag_name": "consul.source.datacenter", - "fixed_value": "dc1" - } - ], - "use_all_default_tags": true - }, - "dynamic_resources": { - "lds_config": { - "ads": {}, - "resource_api_version": "V3" - }, - "cds_config": { - "ads": {}, - "resource_api_version": "V3" - }, - "ads_config": { - "api_type": "DELTA_GRPC", - "transport_api_version": "V3", - "grpc_services": { - "initial_metadata": [ - { - "key": "x-consul-token", - "value": "" - } - ], - "envoy_grpc": { - "cluster_name": "local_agent" - } - } - } - } -} - From 7fab79fda2f72f3f1bd73960342ffe98e55eb167 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo Date: Wed, 16 Nov 2022 17:27:01 -0300 Subject: [PATCH 6/6] Implement os.DevNull --- command/connect/envoy/admin_access_log_path_unix.go | 6 ------ command/connect/envoy/admin_access_log_path_windows.go | 6 ------ command/connect/envoy/envoy.go | 2 ++ 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 command/connect/envoy/admin_access_log_path_unix.go delete mode 100644 command/connect/envoy/admin_access_log_path_windows.go diff --git a/command/connect/envoy/admin_access_log_path_unix.go b/command/connect/envoy/admin_access_log_path_unix.go deleted file mode 100644 index aedaa15668..0000000000 --- a/command/connect/envoy/admin_access_log_path_unix.go +++ /dev/null @@ -1,6 +0,0 @@ -//go:build linux || darwin -// +build linux darwin - -package envoy - -const DefaultAdminAccessLogPath = "/dev/null" diff --git a/command/connect/envoy/admin_access_log_path_windows.go b/command/connect/envoy/admin_access_log_path_windows.go deleted file mode 100644 index d5e7832476..0000000000 --- a/command/connect/envoy/admin_access_log_path_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -//go:build windows -// +build windows - -package envoy - -const DefaultAdminAccessLogPath = "nul" diff --git a/command/connect/envoy/envoy.go b/command/connect/envoy/envoy.go index acf238f29f..c5e226e5ff 100644 --- a/command/connect/envoy/envoy.go +++ b/command/connect/envoy/envoy.go @@ -28,6 +28,8 @@ func New(ui cli.Ui) *cmd { return c } +const DefaultAdminAccessLogPath = os.DevNull + type cmd struct { UI cli.Ui flags *flag.FlagSet