Skip to content

Commit

Permalink
set logr implementation for controller-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfoehrKn committed Nov 29, 2023
1 parent c5d3246 commit 7eee536
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cmd/switcher/switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"os"
"strings"

"github.com/bombsimon/logrusr/v4"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/danielfoehrkn/kubeswitch/pkg"

"github.com/danielfoehrkn/kubeswitch/pkg/cache"
Expand Down Expand Up @@ -271,6 +274,10 @@ func initialize() ([]store.KubeconfigStore, *types.Config, error) {
s.GetLogger().Logger.SetLevel(logrus.DebugLevel)
}

// set 'logr' log implementation for the controller-runtime (otherwise controller-runtime code cannot log)
log := logrusr.New(s.GetLogger().Logger)
logf.SetLogger(log)

// Add cache to the store
// defaults to in-memory cache -> prevents duplicate reads of the same kubeconfig
if cacheCfg := kubeconfigStoreFromConfig.Cache; cacheCfg == nil {
Expand Down Expand Up @@ -315,11 +322,11 @@ func getStoreFromFlagAndEnv(config *types.Config) *types.KubeconfigStore {
}

return &types.KubeconfigStore{
ID: pointer.StringPtr("env-and-flag"),
ID: pointer.String("env-and-flag"),
Kind: types.StoreKind(storageBackend),
KubeconfigName: pointer.StringPtr(kubeconfigName),
KubeconfigName: pointer.String(kubeconfigName),
Paths: paths,
ShowPrefix: pointer.BoolPtr(false),
ShowPrefix: pointer.Bool(false),
}
}

Expand Down

0 comments on commit 7eee536

Please sign in to comment.