Skip to content

Commit c0bd847

Browse files
authored
Merge pull request #12606 from sbueringer/pr-reduce-noisy-logs
🌱 Reduce noisy logs
2 parents 0e93d88 + f0cfc05 commit c0bd847

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
152152
}
153153

154154
// Reconcile handles KubeadmConfig events.
155-
func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, rerr error) {
155+
func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (retRes ctrl.Result, rerr error) {
156156
log := ctrl.LoggerFrom(ctx)
157157

158158
// Look up the kubeadm config
@@ -273,6 +273,12 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
273273
if err := patchHelper.Patch(ctx, config, patchOpts...); err != nil {
274274
rerr = kerrors.NewAggregate([]error{rerr, err})
275275
}
276+
277+
// Note: controller-runtime logs a warning that non-empty result is ignored
278+
// if error is not nil, so setting result here to empty to avoid noisy warnings.
279+
if rerr != nil {
280+
retRes = ctrl.Result{}
281+
}
276282
}()
277283

278284
// Ignore deleted KubeadmConfigs.

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
261261
res = ctrl.Result{RequeueAfter: 20 * time.Second}
262262
}
263263
}
264+
265+
// Note: controller-runtime logs a warning that non-empty result is ignored
266+
// if error is not nil, so setting result here to empty to avoid noisy warnings.
267+
if reterr != nil {
268+
res = ctrl.Result{}
269+
}
264270
}()
265271

266272
if !kcp.DeletionTimestamp.IsZero() {

util/apiwarnings/expressions.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import (
2525
// warning that the API server returns when a finalizer is not domain-qualified.
2626
func DomainQualifiedFinalizerWarning(domain string) regexp.Regexp {
2727
return *regexp.MustCompile(
28-
fmt.Sprintf("^metadata.finalizers:.*%s.*prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers$", domain),
28+
fmt.Sprintf("^metadata.finalizers:.*%s.*prefer a domain-qualified finalizer name (including a path \\(\\/\\) )?to avoid accidental conflicts with other finalizer writers$", domain),
2929
)
3030
}
31+
32+
// DeprecationWarning is a regular expression that matches a
33+
// warning that the API server returns when using a type that is deprecated.
34+
func DeprecationWarning() regexp.Regexp {
35+
return *regexp.MustCompile("^.*is deprecated; use .*$")
36+
}

util/apiwarnings/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func DefaultHandler(l logr.Logger) *DiscardMatchingHandler {
6161
Logger: l,
6262
Expressions: []regexp.Regexp{
6363
DomainQualifiedFinalizerWarning(clusterv1.GroupVersion.Group),
64+
DeprecationWarning(),
6465
},
6566
}
6667
}

util/apiwarnings/handler_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,23 @@ func TestDefaultHandler(t *testing.T) {
110110
wantLogged: true,
111111
},
112112
{
113-
name: "do not log, if warning matches at least one expression",
113+
name: "do not log, if warning matches at least one expression (domain-qualified finalizer)",
114114
code: 299,
115115
message: `metadata.finalizers: "dockermachine.infrastructure.cluster.x-k8s.io": prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers`,
116116
wantLogged: false,
117117
},
118+
{
119+
name: "do not log, if warning matches at least one expression (domain-qualified finalizer)",
120+
code: 299,
121+
message: `metadata.finalizers: "cluster.cluster.x-k8s.io": prefer a domain-qualified finalizer name including a path (/) to avoid accidental conflicts with other finalizer writers`,
122+
wantLogged: false,
123+
},
124+
{
125+
name: "do not log, if warning matches at least one expression (deprecation warning)",
126+
code: 299,
127+
message: `controlplane.cluster.x-k8s.io/v1beta1 KubeadmControlPlane is deprecated; use controlplane.cluster.x-k8s.io/v1beta2 KubeadmControlPlane`,
128+
wantLogged: false,
129+
},
118130
}
119131
for _, tt := range tests {
120132
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)