Skip to content

Commit ca81c46

Browse files
tardieuopenshift-merge-bot[bot]
authored andcommitted
Downgrade StatusReasonConflict errors to debug messages
1 parent c6e4ff0 commit ca81c46

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/project-codeflare/codeflare-operator
33
go 1.22.2
44

55
require (
6+
github.com/go-logr/logr v1.4.2
67
github.com/onsi/ginkgo/v2 v2.19.0
78
github.com/onsi/gomega v1.33.1
89
github.com/open-policy-agent/cert-controller v0.10.1
@@ -51,7 +52,6 @@ require (
5152
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
5253
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
5354
github.com/fsnotify/fsnotify v1.7.0 // indirect
54-
github.com/go-logr/logr v1.4.2 // indirect
5555
github.com/go-logr/zapr v1.3.0 // indirect
5656
github.com/go-openapi/jsonpointer v0.20.0 // indirect
5757
github.com/go-openapi/jsonreference v0.20.2 // indirect

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func main() {
116116
zapOptions.BindFlags(flag.CommandLine)
117117
flag.Parse()
118118

119-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
119+
ctrl.SetLogger(controllers.FilteredLogger(zap.New(zap.UseFlagOptions(&zapOptions))))
120120
klog.SetLogger(ctrl.Log)
121121

122122
setupLog.Info("Build info",

pkg/controllers/support.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package controllers
33
import (
44
"os"
55

6+
"github.com/go-logr/logr"
67
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
78

89
corev1 "k8s.io/api/core/v1"
910
networkingv1 "k8s.io/api/networking/v1"
1011
"k8s.io/apimachinery/pkg/api/equality"
12+
"k8s.io/apimachinery/pkg/api/errors"
1113
"k8s.io/apimachinery/pkg/util/intstr"
1214
"k8s.io/apimachinery/pkg/util/validation/field"
1315
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
@@ -172,3 +174,41 @@ func withEnvVarName(name string) compare[corev1.EnvVar] {
172174
return e1.Name == name
173175
}
174176
}
177+
178+
// logSink implements a log sink with an error log filter
179+
type logSink struct {
180+
sink logr.LogSink
181+
}
182+
183+
func (l logSink) Init(info logr.RuntimeInfo) {
184+
l.sink.Init(info)
185+
}
186+
187+
func (l logSink) Enabled(level int) bool {
188+
return l.sink.Enabled(level)
189+
}
190+
func (l logSink) Info(level int, msg string, keysAndValues ...any) {
191+
l.sink.Info(level, msg, keysAndValues...)
192+
}
193+
194+
func (l logSink) Error(err error, msg string, keysAndValues ...any) {
195+
// downgrade StatusReasonConflict errors to debug messages
196+
if errors.IsConflict(err) {
197+
l.sink.Info(1, msg, append(keysAndValues, "error", err.Error())...)
198+
} else {
199+
l.sink.Error(err, msg, keysAndValues...)
200+
}
201+
}
202+
203+
func (l logSink) WithValues(keysAndValues ...any) logr.LogSink {
204+
return logSink{l.sink.WithValues(keysAndValues...)}
205+
}
206+
207+
func (l logSink) WithName(name string) logr.LogSink {
208+
return logSink{l.sink.WithName(name)}
209+
}
210+
211+
// FilteredLogger returns a copy of the logger with an error log filter
212+
func FilteredLogger(logger logr.Logger) logr.Logger {
213+
return logger.WithSink(logSink{logger.GetSink()})
214+
}

0 commit comments

Comments
 (0)