command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json (#9980)

Fixes #9921
This commit is contained in:
R.B. Boyer 2021-04-07 14:22:52 -05:00 committed by GitHub
parent 014547159c
commit 36c74bf865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 38 additions and 28 deletions

3
.changelog/9980.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json
```

View File

@ -4,7 +4,6 @@ import (
"errors"
"flag"
"fmt"
"io"
"net"
"os"
"os/exec"
@ -24,17 +23,7 @@ import (
)
func New(ui cli.Ui) *cmd {
ui = &cli.PrefixedUi{
OutputPrefix: "==> ",
InfoPrefix: " ",
ErrorPrefix: "==> ",
Ui: ui,
}
c := &cmd{
UI: ui,
directOut: os.Stdout,
}
c := &cmd{UI: ui}
c.init()
return c
}
@ -47,9 +36,6 @@ type cmd struct {
http *flags.HTTPFlags
help string
client *api.Client
// DirectOut defaults to os.stdout but is a property to allow capture during
// tests to have more useful output.
directOut io.Writer
// flags
meshGateway bool
@ -380,7 +366,11 @@ func (c *cmd) run(args []string) int {
return 1
}
c.UI.Output(fmt.Sprintf("Registered service: %s", svc.Name))
if !c.bootstrap {
// We need stdout to be reserved exclusively for the JSON blob, so
// we omit logging this to Info which also writes to stdout.
c.UI.Info(fmt.Sprintf("Registered service: %s", svc.Name))
}
}
// Generate config
@ -392,7 +382,7 @@ func (c *cmd) run(args []string) int {
if c.bootstrap {
// Just output it and we are done
c.directOut.Write(bootstrapJson)
c.UI.Output(string(bootstrapJson))
return 0
}
@ -578,7 +568,6 @@ func (c *cmd) grpcAddress(httpCfg *api.Config) (GRPC, error) {
// This is the dev mode default and recommended production setting if
// enabled.
port = 8502
c.UI.Info(fmt.Sprintf("Defaulting to grpc port = %d", port))
}
addr = fmt.Sprintf("localhost:%v", port)
}

View File

@ -1,7 +1,6 @@
package envoy
import (
"bytes"
"encoding/json"
"flag"
"io/ioutil"
@ -15,12 +14,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent"
"github.com/hashicorp/consul/agent/xds"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
)
var update = flag.Bool("update", false, "update golden files")
@ -874,11 +874,6 @@ func TestGenerateConfig(t *testing.T) {
// explicitly set the client to one which can connect to the httptest.Server
c.client = client
var outBuf bytes.Buffer
// Capture output since it clutters test output and we can assert on what
// was actually printed this way.
c.directOut = &outBuf
// Run the command
myFlags := copyAndReplaceAll(tc.Flags, "@@TEMPDIR@@", testDirPrefix)
args := append([]string{"-bootstrap"}, myFlags...)
@ -899,7 +894,7 @@ func TestGenerateConfig(t *testing.T) {
require.NoError(err) // Error cases should have returned above
require.Equal(&tc.WantArgs, got)
actual := outBuf.Bytes()
actual := ui.OutputWriter.Bytes()
// If we got the arg handling write, verify output
golden := filepath.Join("testdata", tc.Name+".golden")

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -13,4 +13,4 @@
"id": "test-proxy"
},
"custom_field": "foo"
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -190,3 +190,4 @@
}
}
}

View File

@ -190,3 +190,4 @@
}
}
}

View File

@ -199,3 +199,4 @@
}
}
}

View File

@ -190,3 +190,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -176,3 +176,4 @@
}
}
}

View File

@ -263,3 +263,4 @@
}
}
}

View File

@ -263,3 +263,4 @@
}
}
}

View File

@ -263,3 +263,4 @@
}
}
}

View File

@ -263,3 +263,4 @@
}
}
}

View File

@ -75,3 +75,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -177,3 +177,4 @@
}
}
}

View File

@ -210,3 +210,4 @@
}
}
}