mirror of
https://github.com/status-im/consul.git
synced 2025-02-21 18:08:23 +00:00
[1.9.x] command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json (#9984)
Backport of #9980 to `1.9.x` Conflicts: - just the generated golden command/ files
This commit is contained in:
parent
1a28cd9175
commit
0efdb9f0b5
3
.changelog/9980.txt
Normal file
3
.changelog/9980.txt
Normal file
@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
command: when generating envoy bootstrap configs to stdout do not mix informational logs into the json
|
||||
```
|
@ -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
|
||||
@ -365,7 +351,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
|
||||
@ -377,7 +367,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
|
||||
}
|
||||
|
||||
@ -561,7 +551,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)
|
||||
}
|
||||
|
@ -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")
|
||||
@ -821,11 +821,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...)
|
||||
@ -846,7 +841,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")
|
||||
|
@ -183,3 +183,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,4 +13,4 @@
|
||||
"id": "test-proxy"
|
||||
},
|
||||
"custom_field": "foo"
|
||||
}
|
||||
}
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,3 +183,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,3 +183,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,3 +196,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,3 +187,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,3 +173,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,3 +247,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,3 +247,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,3 +247,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,3 +247,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,3 +247,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,3 +72,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,3 +174,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,3 +207,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user