Skip to content

Commit 8734a21

Browse files
committed
Add separate log level flag
1 parent 2e898fa commit 8734a21

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

controlplane/kubeadm/controllers/alias.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import (
2020
"context"
2121
"time"
2222

23-
"go.uber.org/zap"
23+
"go.uber.org/zap/zapcore"
2424
ctrl "sigs.k8s.io/controller-runtime"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626
"sigs.k8s.io/controller-runtime/pkg/controller"
2727

2828
"sigs.k8s.io/cluster-api/controllers/clustercache"
2929
kubeadmcontrolplanecontrollers "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/controllers"
30-
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/etcd"
3130
)
3231

3332
// KubeadmControlPlaneReconciler reconciles a KubeadmControlPlane object.
@@ -38,6 +37,7 @@ type KubeadmControlPlaneReconciler struct {
3837

3938
EtcdDialTimeout time.Duration
4039
EtcdCallTimeout time.Duration
40+
EtcdLogLevel zapcore.Level
4141

4242
// WatchFilterValue is the label value used to filter events prior to reconciliation.
4343
WatchFilterValue string
@@ -53,12 +53,8 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
5353
ClusterCache: r.ClusterCache,
5454
EtcdDialTimeout: r.EtcdDialTimeout,
5555
EtcdCallTimeout: r.EtcdCallTimeout,
56+
EtcdLogLevel: r.EtcdLogLevel,
5657
WatchFilterValue: r.WatchFilterValue,
5758
RemoteConditionsGracePeriod: r.RemoteConditionsGracePeriod,
5859
}).SetupWithManager(ctx, mgr, options)
5960
}
60-
61-
// SetEtcdLogger allows to redefine ETCD client logger.
62-
func SetEtcdLogger(logger *zap.Logger) {
63-
etcd.SetLogger(logger)
64-
}

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type KubeadmControlPlaneReconciler struct {
8787

8888
EtcdDialTimeout time.Duration
8989
EtcdCallTimeout time.Duration
90+
EtcdLogLevel zapcore.Level
9091

9192
// WatchFilterValue is the label value used to filter events prior to reconciliation.
9293
WatchFilterValue string
@@ -112,7 +113,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
112113
}
113114

114115
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "kubeadmcontrolplane")
115-
etcdLogger, err := logutil.CreateDefaultZapLogger(0 - zapcore.Level(predicateLog.GetV()))
116+
etcdLogger, err := logutil.CreateDefaultZapLogger(r.EtcdLogLevel)
116117
if err != nil {
117118
return errors.Wrap(err, "failed to create ETCD client zap logger")
118119
}

controlplane/kubeadm/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/pkg/errors"
2929
"github.com/spf13/pflag"
30+
"go.uber.org/zap/zapcore"
3031
appsv1 "k8s.io/api/apps/v1"
3132
corev1 "k8s.io/api/core/v1"
3233
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -100,6 +101,7 @@ var (
100101
skipCRDMigrationPhases []string
101102
etcdDialTimeout time.Duration
102103
etcdCallTimeout time.Duration
104+
etcdLogLevel int8
103105
)
104106

105107
func init() {
@@ -190,6 +192,9 @@ func InitFlags(fs *pflag.FlagSet) {
190192
fs.DurationVar(&etcdCallTimeout, "etcd-call-timeout-duration", etcd.DefaultCallTimeout,
191193
"Duration that the etcd client waits at most for read and write operations to etcd.")
192194

195+
fs.Int8Var(&etcdLogLevel, "etcd-client-log-level", int8(zapcore.InfoLevel),
196+
"Logging level for etcd client.")
197+
193198
flags.AddManagerOptions(fs, &managerOptions)
194199

195200
feature.MutableGates.AddFlag(fs)
@@ -425,6 +430,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
425430
WatchFilterValue: watchFilterValue,
426431
EtcdDialTimeout: etcdDialTimeout,
427432
EtcdCallTimeout: etcdCallTimeout,
433+
EtcdLogLevel: zapcore.Level(etcdLogLevel),
428434
RemoteConditionsGracePeriod: remoteConditionsGracePeriod,
429435
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
430436
setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane")

0 commit comments

Comments
 (0)