Skip to content

Commit

Permalink
enable json format everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Feb 7, 2022
1 parent 1b1ff26 commit 4aebce0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -146,7 +147,8 @@ func main() {

err := logOptions.ValidateAndApply()
if err != nil {
panic(err)
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
Expand Down
4 changes: 3 additions & 1 deletion controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -149,7 +150,8 @@ func main() {

err := logOptions.ValidateAndApply()
if err != nil {
panic(err)
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
Expand Down
2 changes: 2 additions & 0 deletions internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
log := ctrl.LoggerFrom(ctx)

log.Info("abc", "key", "value")

// Fetch the Cluster instance.
cluster := &clusterv1.Cluster{}
if err := r.Client.Get(ctx, req.NamespacedName, cluster); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -189,7 +189,8 @@ func main() {

err := logOptions.ValidateAndApply()
if err != nil {
panic(err)
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
Expand Down
5 changes: 4 additions & 1 deletion test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -108,6 +109,7 @@ func initFlags(fs *pflag.FlagSet) {
func main() {
rand.Seed(time.Now().UnixNano())
if _, err := os.ReadDir("/tmp/"); err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

Expand All @@ -118,7 +120,8 @@ func main() {

err := logOptions.ValidateAndApply()
if err != nil {
panic(err)
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
Expand Down

0 comments on commit 4aebce0

Please sign in to comment.