mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Quiet embedded etcd logs
This commit is contained in:
parent
068e4c55a8
commit
f283deee6b
@ -17,14 +17,24 @@ limitations under the License.
|
|||||||
package testing
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||||
|
|
||||||
|
grpclogsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"go.etcd.io/etcd/tests/v3/integration"
|
"go.etcd.io/etcd/tests/v3/integration"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var grpc_logger grpclogsettable.SettableLoggerV2
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// override logger set up by etcd integration test package
|
||||||
|
grpc_logger = grpclogsettable.ReplaceGrpcLoggerV2()
|
||||||
|
}
|
||||||
|
|
||||||
// EtcdTestServer encapsulates the datastructures needed to start local instance for testing
|
// EtcdTestServer encapsulates the datastructures needed to start local instance for testing
|
||||||
type EtcdTestServer struct {
|
type EtcdTestServer struct {
|
||||||
CertificatesDir string
|
CertificatesDir string
|
||||||
@ -45,8 +55,9 @@ func (m *EtcdTestServer) Terminate(t *testing.T) {
|
|||||||
// NewUnsecuredEtcd3TestClientServer creates a new client and server for testing
|
// NewUnsecuredEtcd3TestClientServer creates a new client and server for testing
|
||||||
func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storagebackend.Config) {
|
func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storagebackend.Config) {
|
||||||
integration.BeforeTestExternal(t)
|
integration.BeforeTestExternal(t)
|
||||||
|
grpc_logger.Set(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, &testErrorWriter{t}))
|
||||||
server := &EtcdTestServer{
|
server := &EtcdTestServer{
|
||||||
v3Cluster: integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}),
|
v3Cluster: integration.NewClusterV3(&noLogT{t}, &integration.ClusterConfig{Size: 1}),
|
||||||
}
|
}
|
||||||
server.V3Client = server.v3Cluster.RandClient()
|
server.V3Client = server.v3Cluster.RandClient()
|
||||||
config := &storagebackend.Config{
|
config := &storagebackend.Config{
|
||||||
@ -59,3 +70,21 @@ func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storageb
|
|||||||
}
|
}
|
||||||
return server, config
|
return server, config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type noLogT struct {
|
||||||
|
testing.TB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *noLogT) Log(s ...interface{}) {
|
||||||
|
}
|
||||||
|
func (q *noLogT) Logf(s string, params ...interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
|
type testErrorWriter struct {
|
||||||
|
testing.TB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *testErrorWriter) Write(b []byte) (int, error) {
|
||||||
|
t.TB.Error(string(b))
|
||||||
|
return len(b), nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user