Skip to content

Commit ec68021

Browse files
committed
KCP: stop recreating logger for etcd client
Signed-off-by: Stefan Büringer [email protected]
1 parent 199edc1 commit ec68021

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

controlplane/kubeadm/internal/etcd/etcd.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424

2525
"github.com/pkg/errors"
2626
"go.etcd.io/etcd/api/v3/etcdserverpb"
27+
"go.etcd.io/etcd/client/pkg/v3/logutil"
2728
clientv3 "go.etcd.io/etcd/client/v3"
29+
"go.uber.org/zap/zapcore"
2830
"google.golang.org/grpc"
2931
kerrors "k8s.io/apimachinery/pkg/util/errors"
3032

@@ -138,6 +140,12 @@ type ClientConfiguration struct {
138140
CallTimeout time.Duration
139141
}
140142

143+
var (
144+
// Create the etcdClientLogger only once. Otherwise every call of clientv3.New
145+
// would create its own logger which leads to a lot of memory allocations.
146+
etcdClientLogger, _ = logutil.CreateDefaultZapLogger(zapcore.InfoLevel)
147+
)
148+
141149
// NewClient creates a new etcd client with the given configuration.
142150
func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) {
143151
dialer, err := proxy.NewDialer(config.Proxy)
@@ -151,7 +159,8 @@ func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error)
151159
DialOptions: []grpc.DialOption{
152160
grpc.WithContextDialer(dialer.DialContextWithAddr),
153161
},
154-
TLS: config.TLSConfig,
162+
TLS: config.TLSConfig,
163+
Logger: etcdClientLogger,
155164
})
156165
if err != nil {
157166
return nil, errors.Wrap(err, "unable to create etcd client")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ require (
3232
github.com/spf13/viper v1.19.0
3333
github.com/valyala/fastjson v1.6.4
3434
go.etcd.io/etcd/api/v3 v3.5.15
35+
go.etcd.io/etcd/client/pkg/v3 v3.5.15
3536
go.etcd.io/etcd/client/v3 v3.5.15
37+
go.uber.org/zap v1.27.0
3638
golang.org/x/oauth2 v0.21.0
3739
golang.org/x/text v0.21.0
3840
gomodules.xyz/jsonpatch/v2 v2.4.0
@@ -142,7 +144,6 @@ require (
142144
github.com/subosito/gotenv v1.6.0 // indirect
143145
github.com/vincent-petithory/dataurl v1.0.0 // indirect
144146
github.com/xlab/treeprint v1.2.0 // indirect
145-
go.etcd.io/etcd/client/pkg/v3 v3.5.15 // indirect
146147
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
147148
go.opentelemetry.io/otel v1.24.0 // indirect
148149
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.20.0 // indirect
@@ -153,7 +154,6 @@ require (
153154
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
154155
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
155156
go.uber.org/multierr v1.11.0 // indirect
156-
go.uber.org/zap v1.27.0 // indirect
157157
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
158158
golang.org/x/crypto v0.31.0 // indirect
159159
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect

0 commit comments

Comments
 (0)