mirror of
https://github.com/k3s-io/k3s.git
synced 2026-06-09 00:33:35 -04:00
lint: unexported-return
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
46c7ade9e9
commit
49d080c7b7
2 changed files with 22 additions and 22 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
// implicit interface check
|
||||
var _ logr.LogSink = &logrusSink{}
|
||||
var _ logr.LogSink = &LogrusSink{}
|
||||
|
||||
// mapLevel maps logr log verbosities to logrus log levels
|
||||
// logr does not have "log levels", but Info prints at verbosity 0
|
||||
|
|
@ -42,46 +42,46 @@ func mapKV(kvs []any) logrus.Fields {
|
|||
}
|
||||
|
||||
// LogrusSink wraps logrus the Logger/Entry types for use as a logr LogSink.
|
||||
type logrusSink struct {
|
||||
type LogrusSink struct {
|
||||
e *logrus.Entry
|
||||
ri logr.RuntimeInfo
|
||||
}
|
||||
|
||||
func NewLogrusSink(l *logrus.Logger) *logrusSink {
|
||||
func NewLogrusSink(l *logrus.Logger) *LogrusSink {
|
||||
if l == nil {
|
||||
l = logrus.StandardLogger()
|
||||
}
|
||||
return &logrusSink{e: logrus.NewEntry(l)}
|
||||
return &LogrusSink{e: logrus.NewEntry(l)}
|
||||
}
|
||||
|
||||
func (ls *logrusSink) AsLogr() logr.Logger {
|
||||
func (ls *LogrusSink) AsLogr() logr.Logger {
|
||||
return logr.New(ls)
|
||||
}
|
||||
|
||||
func (ls *logrusSink) Init(ri logr.RuntimeInfo) {
|
||||
func (ls *LogrusSink) Init(ri logr.RuntimeInfo) {
|
||||
ls.ri = ri
|
||||
}
|
||||
|
||||
func (ls *logrusSink) Enabled(level int) bool {
|
||||
func (ls *LogrusSink) Enabled(level int) bool {
|
||||
return ls.e.Logger.IsLevelEnabled(mapLevel(level))
|
||||
}
|
||||
|
||||
func (ls *logrusSink) Info(level int, msg string, kvs ...any) {
|
||||
func (ls *LogrusSink) Info(level int, msg string, kvs ...any) {
|
||||
ls.e.WithFields(mapKV(kvs)).Log(mapLevel(level), msg)
|
||||
}
|
||||
|
||||
func (ls *logrusSink) Error(err error, msg string, kvs ...any) {
|
||||
func (ls *LogrusSink) Error(err error, msg string, kvs ...any) {
|
||||
ls.e.WithError(err).WithFields(mapKV(kvs)).Error(msg)
|
||||
}
|
||||
|
||||
func (ls *logrusSink) WithValues(kvs ...any) logr.LogSink {
|
||||
return &logrusSink{
|
||||
func (ls *LogrusSink) WithValues(kvs ...any) logr.LogSink {
|
||||
return &LogrusSink{
|
||||
e: ls.e.WithFields(mapKV(kvs)),
|
||||
ri: ls.ri,
|
||||
}
|
||||
}
|
||||
|
||||
func (ls *logrusSink) WithName(name string) logr.LogSink {
|
||||
func (ls *LogrusSink) WithName(name string) logr.LogSink {
|
||||
if base, ok := ls.e.Data["logger"]; ok {
|
||||
name = fmt.Sprintf("%s/%s", base, name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,21 +21,21 @@ type clientPatcher[T runtime.Object] interface {
|
|||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (T, error)
|
||||
}
|
||||
|
||||
// patchWrapper wraps the Patch functions provided by either wrangler or client-go
|
||||
type patchWrapper[T runtime.Object] struct {
|
||||
patcher any
|
||||
// Patcher wraps the Patch functions provided by either wrangler or client-go
|
||||
type Patcher[T runtime.Object] struct {
|
||||
impl any
|
||||
}
|
||||
|
||||
// NewPatcher wraps the provided controller or client for use as a generic patcher
|
||||
// note that the patcher is not validated for use until `Patch` is called
|
||||
func NewPatcher[T runtime.Object](patcher any) *patchWrapper[T] {
|
||||
return &patchWrapper[T]{
|
||||
patcher: patcher,
|
||||
func NewPatcher[T runtime.Object](patcher any) *Patcher[T] {
|
||||
return &Patcher[T]{
|
||||
impl: patcher,
|
||||
}
|
||||
}
|
||||
|
||||
// Patch applies the provided PatchList to the specified resource
|
||||
func (p *patchWrapper[T]) Patch(ctx context.Context, pl *PatchList, name string, subresources ...string) (T, error) {
|
||||
func (p *Patcher[T]) Patch(ctx context.Context, pl *PatchList, name string, subresources ...string) (T, error) {
|
||||
var t T
|
||||
if pl == nil {
|
||||
pl = NewPatchList()
|
||||
|
|
@ -44,13 +44,13 @@ func (p *patchWrapper[T]) Patch(ctx context.Context, pl *PatchList, name string,
|
|||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
if patch, ok := p.patcher.(clientPatcher[T]); ok {
|
||||
if patch, ok := p.impl.(clientPatcher[T]); ok {
|
||||
return patch.Patch(ctx, name, types.JSONPatchType, b, metav1.PatchOptions{}, subresources...)
|
||||
}
|
||||
if patch, ok := p.patcher.(controllerPatcher[T]); ok {
|
||||
if patch, ok := p.impl.(controllerPatcher[T]); ok {
|
||||
return patch.Patch(name, types.JSONPatchType, b, subresources...)
|
||||
}
|
||||
return t, fmt.Errorf("unable to patch %T with %T", t, p.patcher)
|
||||
return t, fmt.Errorf("unable to patch %T with %T", t, p.impl)
|
||||
}
|
||||
|
||||
// PatchList is a generic list of JSONPatch operations to apply to a resource
|
||||
|
|
|
|||
Loading…
Reference in a new issue