Skip to content

Commit 958ff15

Browse files
⚠️ bump k8s to 1.23-alpha.3
This PR bumps the k8s dependencies to 1.23-alpha.3 **Note** Since k8s 1.23 uses go-logr/logr v1.1.0, this PR also bumps logr to the latest version. Co-authored-by: "Morlay"<morlay.null@gmail.com>
1 parent c73b143 commit 958ff15

File tree

14 files changed

+357
-183
lines changed

14 files changed

+357
-183
lines changed

go.mod

+16-17
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ module sigs.k8s.io/controller-runtime
33
go 1.16
44

55
require (
6-
github.com/evanphx/json-patch v4.11.0+incompatible
7-
github.com/fsnotify/fsnotify v1.4.9
8-
github.com/go-logr/logr v0.4.0
9-
github.com/go-logr/zapr v0.4.0
6+
github.com/evanphx/json-patch v5.6.0+incompatible
7+
github.com/fsnotify/fsnotify v1.5.1
8+
github.com/go-logr/logr v1.2.0
9+
github.com/go-logr/zapr v1.2.0
1010
github.com/imdario/mergo v0.3.12 // indirect
11-
github.com/onsi/ginkgo v1.16.4
12-
github.com/onsi/gomega v1.15.0
11+
github.com/onsi/ginkgo v1.16.5
12+
github.com/onsi/gomega v1.16.0
1313
github.com/prometheus/client_golang v1.11.0
1414
github.com/prometheus/client_model v0.2.0
15-
go.uber.org/goleak v1.1.10
16-
go.uber.org/zap v1.19.0
17-
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2
15+
go.uber.org/goleak v1.1.12
16+
go.uber.org/zap v1.19.1
17+
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8
1818
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
1919
gomodules.xyz/jsonpatch/v2 v2.2.0
20-
google.golang.org/appengine v1.6.7 // indirect
21-
k8s.io/api v0.22.2
22-
k8s.io/apiextensions-apiserver v0.22.2
23-
k8s.io/apimachinery v0.22.2
24-
k8s.io/client-go v0.22.2
25-
k8s.io/component-base v0.22.2
26-
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
27-
sigs.k8s.io/yaml v1.2.0
20+
k8s.io/api v0.23.0-alpha.3
21+
k8s.io/apiextensions-apiserver v0.22.3
22+
k8s.io/apimachinery v0.23.0-alpha.3
23+
k8s.io/client-go v0.23.0-alpha.3
24+
k8s.io/component-base v0.23.0-alpha.3
25+
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
26+
sigs.k8s.io/yaml v1.3.0
2827
)

go.sum

+221-36
Large diffs are not rendered by default.

pkg/builder/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
305305
}
306306

307307
// Setup the logger.
308-
if ctrlOptions.Log == nil {
308+
if ctrlOptions.Log.GetSink() == nil {
309309
ctrlOptions.Log = blder.mgr.GetLogger()
310310
}
311311
ctrlOptions.Log = ctrlOptions.Log.WithValues("reconciler group", gvk.Group, "reconciler kind", gvk.Kind)

pkg/builder/controller_test.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ type testLogger struct {
5757
logr.Logger
5858
}
5959

60-
func (l *testLogger) WithName(_ string) logr.Logger {
60+
func (l *testLogger) Init(logr.RuntimeInfo) {
61+
}
62+
63+
func (l *testLogger) Enabled(int) bool {
64+
return true
65+
}
66+
67+
func (l *testLogger) Info(level int, msg string, keysAndValues ...interface{}) {
68+
}
69+
70+
func (l *testLogger) WithValues(keysAndValues ...interface{}) logr.LogSink {
6171
return l
6272
}
63-
func (l *testLogger) WithValues(_ ...interface{}) logr.Logger {
73+
74+
func (l *testLogger) WithName(name string) logr.LogSink {
6475
return l
6576
}
6677

@@ -227,7 +238,7 @@ var _ = Describe("application", func() {
227238

228239
logger := &testLogger{}
229240
newController = func(name string, mgr manager.Manager, options controller.Options) (controller.Controller, error) {
230-
if options.Log == logger {
241+
if options.Log.GetSink() == logger {
231242
return controller.New(name, mgr, options)
232243
}
233244
return nil, fmt.Errorf("logger expected %T but found %T", logger, options.Log)
@@ -240,7 +251,7 @@ var _ = Describe("application", func() {
240251
instance, err := ControllerManagedBy(m).
241252
For(&appsv1.ReplicaSet{}).
242253
Owns(&appsv1.ReplicaSet{}).
243-
WithLogger(logger).
254+
WithLogger(logr.New(logger)).
244255
Build(noop)
245256
Expect(err).NotTo(HaveOccurred())
246257
Expect(instance).NotTo(BeNil())

pkg/cluster/cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func setOptionsDefaults(options Options) Options {
245245
}
246246
}
247247

248-
if options.Logger == nil {
248+
if options.Logger.GetSink() == nil {
249249
options.Logger = logf.RuntimeLog.WithName("cluster")
250250
}
251251

pkg/controller/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
104104
return nil, fmt.Errorf("must specify Name for Controller")
105105
}
106106

107-
if options.Log == nil {
107+
if options.Log.GetSink() == nil {
108108
options.Log = mgr.GetLogger()
109109
}
110110

pkg/internal/recorder/recorder_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var _ = Describe("recorder.Provider", func() {
2929
makeBroadcaster := func() (record.EventBroadcaster, bool) { return record.NewBroadcaster(), true }
3030
Describe("NewProvider", func() {
3131
It("should return a provider instance and a nil error.", func() {
32-
provider, err := recorder.NewProvider(cfg, scheme.Scheme, logr.DiscardLogger{}, makeBroadcaster)
32+
provider, err := recorder.NewProvider(cfg, scheme.Scheme, logr.Discard(), makeBroadcaster)
3333
Expect(provider).NotTo(BeNil())
3434
Expect(err).NotTo(HaveOccurred())
3535
})
@@ -38,14 +38,14 @@ var _ = Describe("recorder.Provider", func() {
3838
// Invalid the config
3939
cfg1 := *cfg
4040
cfg1.Host = "invalid host"
41-
_, err := recorder.NewProvider(&cfg1, scheme.Scheme, logr.DiscardLogger{}, makeBroadcaster)
41+
_, err := recorder.NewProvider(&cfg1, scheme.Scheme, logr.Discard(), makeBroadcaster)
4242
Expect(err).NotTo(BeNil())
4343
Expect(err.Error()).To(ContainSubstring("failed to init client"))
4444
})
4545
})
4646
Describe("GetEventRecorder", func() {
4747
It("should return a recorder instance.", func() {
48-
provider, err := recorder.NewProvider(cfg, scheme.Scheme, logr.DiscardLogger{}, makeBroadcaster)
48+
provider, err := recorder.NewProvider(cfg, scheme.Scheme, logr.Discard(), makeBroadcaster)
4949
Expect(err).NotTo(HaveOccurred())
5050

5151
recorder := provider.GetEventRecorderFor("test")

pkg/log/deleg.go

+35-63
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ import (
2525
// loggerPromise knows how to populate a concrete logr.Logger
2626
// with options, given an actual base logger later on down the line.
2727
type loggerPromise struct {
28-
logger *DelegatingLogger
28+
logger *DelegatingLogSink
2929
childPromises []*loggerPromise
3030
promisesLock sync.Mutex
3131

32-
name *string
33-
tags []interface{}
34-
level int
32+
name *string
33+
tags []interface{}
3534
}
3635

37-
func (p *loggerPromise) WithName(l *DelegatingLogger, name string) *loggerPromise {
36+
func (p *loggerPromise) WithName(l *DelegatingLogSink, name string) *loggerPromise {
3837
res := &loggerPromise{
3938
logger: l,
4039
name: &name,
@@ -48,7 +47,7 @@ func (p *loggerPromise) WithName(l *DelegatingLogger, name string) *loggerPromis
4847
}
4948

5049
// WithValues provides a new Logger with the tags appended.
51-
func (p *loggerPromise) WithValues(l *DelegatingLogger, tags ...interface{}) *loggerPromise {
50+
func (p *loggerPromise) WithValues(l *DelegatingLogSink, tags ...interface{}) *loggerPromise {
5251
res := &loggerPromise{
5352
logger: l,
5453
tags: tags,
@@ -61,61 +60,53 @@ func (p *loggerPromise) WithValues(l *DelegatingLogger, tags ...interface{}) *lo
6160
return res
6261
}
6362

64-
func (p *loggerPromise) V(l *DelegatingLogger, level int) *loggerPromise {
65-
res := &loggerPromise{
66-
logger: l,
67-
level: level,
68-
promisesLock: sync.Mutex{},
69-
}
70-
71-
p.promisesLock.Lock()
72-
defer p.promisesLock.Unlock()
73-
p.childPromises = append(p.childPromises, res)
74-
return res
75-
}
76-
7763
// Fulfill instantiates the Logger with the provided logger.
78-
func (p *loggerPromise) Fulfill(parentLogger logr.Logger) {
79-
logger := logr.WithCallDepth(parentLogger, 1)
64+
func (p *loggerPromise) Fulfill(parentLogSink logr.LogSink) {
65+
sink := parentLogSink
8066
if p.name != nil {
81-
logger = logger.WithName(*p.name)
67+
sink = sink.WithName(*p.name)
8268
}
8369

8470
if p.tags != nil {
85-
logger = logger.WithValues(p.tags...)
86-
}
87-
if p.level != 0 {
88-
logger = logger.V(p.level)
71+
sink = sink.WithValues(p.tags...)
8972
}
9073

9174
p.logger.lock.Lock()
92-
p.logger.logger = logger
75+
p.logger.logger = sink
9376
p.logger.promise = nil
9477
p.logger.lock.Unlock()
9578

9679
for _, childPromise := range p.childPromises {
97-
childPromise.Fulfill(logger)
80+
childPromise.Fulfill(sink)
9881
}
9982
}
10083

101-
// DelegatingLogger is a logr.Logger that delegates to another logr.Logger.
84+
// DelegatingLogSink is a logsink that delegates to another logr.LogSink.
10285
// If the underlying promise is not nil, it registers calls to sub-loggers with
10386
// the logging factory to be populated later, and returns a new delegating
10487
// logger. It expects to have *some* logr.Logger set at all times (generally
10588
// a no-op logger before the promises are fulfilled).
106-
type DelegatingLogger struct {
89+
type DelegatingLogSink struct {
10790
lock sync.RWMutex
108-
logger logr.Logger
91+
logger logr.LogSink
10992
promise *loggerPromise
93+
info logr.RuntimeInfo
94+
}
95+
96+
// Init implements logr.LogSink.
97+
func (l *DelegatingLogSink) Init(info logr.RuntimeInfo) {
98+
l.lock.Lock()
99+
defer l.lock.Unlock()
100+
l.info = info
110101
}
111102

112103
// Enabled tests whether this Logger is enabled. For example, commandline
113104
// flags might be used to set the logging verbosity and disable some info
114105
// logs.
115-
func (l *DelegatingLogger) Enabled() bool {
106+
func (l *DelegatingLogSink) Enabled(level int) bool {
116107
l.lock.RLock()
117108
defer l.lock.RUnlock()
118-
return l.logger.Enabled()
109+
return l.logger.Enabled(level)
119110
}
120111

121112
// Info logs a non-error message with the given key/value pairs as context.
@@ -124,10 +115,10 @@ func (l *DelegatingLogger) Enabled() bool {
124115
// the log line. The key/value pairs can then be used to add additional
125116
// variable information. The key/value pairs should alternate string
126117
// keys and arbitrary values.
127-
func (l *DelegatingLogger) Info(msg string, keysAndValues ...interface{}) {
118+
func (l *DelegatingLogSink) Info(level int, msg string, keysAndValues ...interface{}) {
128119
l.lock.RLock()
129120
defer l.lock.RUnlock()
130-
l.logger.Info(msg, keysAndValues...)
121+
l.logger.Info(level, msg, keysAndValues...)
131122
}
132123

133124
// Error logs an error, with the given message and key/value pairs as context.
@@ -138,57 +129,38 @@ func (l *DelegatingLogger) Info(msg string, keysAndValues ...interface{}) {
138129
// The msg field should be used to add context to any underlying error,
139130
// while the err field should be used to attach the actual error that
140131
// triggered this log line, if present.
141-
func (l *DelegatingLogger) Error(err error, msg string, keysAndValues ...interface{}) {
132+
func (l *DelegatingLogSink) Error(err error, msg string, keysAndValues ...interface{}) {
142133
l.lock.RLock()
143134
defer l.lock.RUnlock()
144135
l.logger.Error(err, msg, keysAndValues...)
145136
}
146137

147-
// V returns an Logger value for a specific verbosity level, relative to
148-
// this Logger. In other words, V values are additive. V higher verbosity
149-
// level means a log message is less important. It's illegal to pass a log
150-
// level less than zero.
151-
func (l *DelegatingLogger) V(level int) logr.Logger {
152-
l.lock.RLock()
153-
defer l.lock.RUnlock()
154-
155-
if l.promise == nil {
156-
return l.logger.V(level)
157-
}
158-
159-
res := &DelegatingLogger{logger: l.logger}
160-
promise := l.promise.V(res, level)
161-
res.promise = promise
162-
163-
return res
164-
}
165-
166138
// WithName provides a new Logger with the name appended.
167-
func (l *DelegatingLogger) WithName(name string) logr.Logger {
139+
func (l *DelegatingLogSink) WithName(name string) logr.LogSink {
168140
l.lock.RLock()
169141
defer l.lock.RUnlock()
170142

171143
if l.promise == nil {
172144
return l.logger.WithName(name)
173145
}
174146

175-
res := &DelegatingLogger{logger: l.logger}
147+
res := &DelegatingLogSink{logger: l.logger}
176148
promise := l.promise.WithName(res, name)
177149
res.promise = promise
178150

179151
return res
180152
}
181153

182154
// WithValues provides a new Logger with the tags appended.
183-
func (l *DelegatingLogger) WithValues(tags ...interface{}) logr.Logger {
155+
func (l *DelegatingLogSink) WithValues(tags ...interface{}) logr.LogSink {
184156
l.lock.RLock()
185157
defer l.lock.RUnlock()
186158

187159
if l.promise == nil {
188160
return l.logger.WithValues(tags...)
189161
}
190162

191-
res := &DelegatingLogger{logger: l.logger}
163+
res := &DelegatingLogSink{logger: l.logger}
192164
promise := l.promise.WithValues(res, tags...)
193165
res.promise = promise
194166

@@ -198,16 +170,16 @@ func (l *DelegatingLogger) WithValues(tags ...interface{}) logr.Logger {
198170
// Fulfill switches the logger over to use the actual logger
199171
// provided, instead of the temporary initial one, if this method
200172
// has not been previously called.
201-
func (l *DelegatingLogger) Fulfill(actual logr.Logger) {
173+
func (l *DelegatingLogSink) Fulfill(actual logr.LogSink) {
202174
if l.promise != nil {
203175
l.promise.Fulfill(actual)
204176
}
205177
}
206178

207-
// NewDelegatingLogger constructs a new DelegatingLogger which uses
179+
// NewDelegatingLogSink constructs a new DelegatingLogSink which uses
208180
// the given logger before it's promise is fulfilled.
209-
func NewDelegatingLogger(initial logr.Logger) *DelegatingLogger {
210-
l := &DelegatingLogger{
181+
func NewDelegatingLogSink(initial logr.LogSink) *DelegatingLogSink {
182+
l := &DelegatingLogSink{
211183
logger: initial,
212184
promise: &loggerPromise{promisesLock: sync.Mutex{}},
213185
}

pkg/log/log.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ func SetLogger(l logr.Logger) {
4747
defer loggerWasSetLock.Unlock()
4848

4949
loggerWasSet = true
50-
Log.Fulfill(l)
50+
dlog.Fulfill(l.GetSink())
5151
}
5252

5353
// It is safe to assume that if this wasn't set within the first 30 seconds of a binaries
54-
// lifetime, it will never get set. The DelegatingLogger causes a high number of memory
55-
// allocations when not given an actual Logger, so we set a NullLogger to avoid that.
54+
// lifetime, it will never get set. The DelegatingLogSink causes a high number of memory
55+
// allocations when not given an actual Logger, so we set a NullLogSink to avoid that.
5656
//
57-
// We need to keep the DelegatingLogger because we have various inits() that get a logger from
57+
// We need to keep the DelegatingLogSink because we have various inits() that get a logger from
5858
// here. They will always get executed before any code that imports controller-runtime
5959
// has a chance to run and hence to set an actual logger.
6060
func init() {
@@ -64,7 +64,7 @@ func init() {
6464
loggerWasSetLock.Lock()
6565
defer loggerWasSetLock.Unlock()
6666
if !loggerWasSet {
67-
Log.Fulfill(NullLogger{})
67+
dlog.Fulfill(NullLogSink{})
6868
}
6969
}()
7070
}
@@ -78,14 +78,17 @@ var (
7878
// to another logr.Logger. You *must* call SetLogger to
7979
// get any actual logging. If SetLogger is not called within
8080
// the first 30 seconds of a binaries lifetime, it will get
81-
// set to a NullLogger.
82-
var Log = NewDelegatingLogger(NullLogger{})
81+
// set to a NullLogSink.
82+
var (
83+
dlog = NewDelegatingLogSink(NullLogSink{})
84+
Log = logr.New(dlog)
85+
)
8386

8487
// FromContext returns a logger with predefined values from a context.Context.
8588
func FromContext(ctx context.Context, keysAndValues ...interface{}) logr.Logger {
86-
var log logr.Logger = Log
89+
log := Log
8790
if ctx != nil {
88-
if logger := logr.FromContext(ctx); logger != nil {
91+
if logger, err := logr.FromContext(ctx); err == nil {
8992
log = logger
9093
}
9194
}

0 commit comments

Comments
 (0)