diff --git a/controlplane/kubeadm/internal/etcd/etcd.go b/controlplane/kubeadm/internal/etcd/etcd.go index f71da187ad58..e19ad844d386 100644 --- a/controlplane/kubeadm/internal/etcd/etcd.go +++ b/controlplane/kubeadm/internal/etcd/etcd.go @@ -24,7 +24,9 @@ import ( "github.com/pkg/errors" "go.etcd.io/etcd/api/v3/etcdserverpb" + "go.etcd.io/etcd/client/pkg/v3/logutil" clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap/zapcore" "google.golang.org/grpc" kerrors "k8s.io/apimachinery/pkg/util/errors" @@ -138,6 +140,12 @@ type ClientConfiguration struct { CallTimeout time.Duration } +var ( + // Create the etcdClientLogger only once. Otherwise every call of clientv3.New + // would create its own logger which leads to a lot of memory allocations. + etcdClientLogger, _ = logutil.CreateDefaultZapLogger(zapcore.InfoLevel) +) + // NewClient creates a new etcd client with the given configuration. func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) { dialer, err := proxy.NewDialer(config.Proxy) @@ -151,7 +159,8 @@ func NewClient(ctx context.Context, config ClientConfiguration) (*Client, error) DialOptions: []grpc.DialOption{ grpc.WithContextDialer(dialer.DialContextWithAddr), }, - TLS: config.TLSConfig, + TLS: config.TLSConfig, + Logger: etcdClientLogger, }) if err != nil { return nil, errors.Wrap(err, "unable to create etcd client") diff --git a/go.mod b/go.mod index babd14346e81..aab291e11f71 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,9 @@ require ( github.com/spf13/viper v1.19.0 github.com/valyala/fastjson v1.6.4 go.etcd.io/etcd/api/v3 v3.5.17 + go.etcd.io/etcd/client/pkg/v3 v3.5.17 go.etcd.io/etcd/client/v3 v3.5.17 + go.uber.org/zap v1.27.0 golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/oauth2 v0.24.0 golang.org/x/text v0.21.0 @@ -125,7 +127,6 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect github.com/vincent-petithory/dataurl v1.0.0 // indirect github.com/x448/float16 v0.8.4 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect go.opentelemetry.io/otel v1.28.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect @@ -135,7 +136,6 @@ require ( go.opentelemetry.io/otel/trace v1.28.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.27.0 // indirect go4.org v0.0.0-20201209231011-d4a079459e60 // indirect golang.org/x/crypto v0.31.0 // indirect golang.org/x/net v0.33.0 // indirect