Skip to content

Commit

Permalink
Use klog in manager and setup controller-runtime logger (kubernetes-s…
Browse files Browse the repository at this point in the history
…igs#1022)

Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri authored and k8s-ci-robot committed Jun 18, 2019
1 parent bd0628f commit 0ebf076
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 16 deletions.
9 changes: 7 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cmd/manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ go_library(
"//pkg/controller:go_default_library",
"//vendor/k8s.io/client-go/plugin/pkg/client/auth/gcp:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/klog/klogr:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client/config:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/manager:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/runtime/log:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/runtime/signals:go_default_library",
],
)
Expand Down
33 changes: 19 additions & 14 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ package main

import (
"flag"
"log"
"time"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog"
"k8s.io/klog/klogr"
"sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

Expand All @@ -38,39 +39,43 @@ func main() {

flag.Parse()
if *watchNamespace != "" {
log.Printf("Watching cluster-api objects only in namespace %q for reconciliation.", *watchNamespace)
klog.Infof("Watching cluster-api objects only in namespace %q for reconciliation", *watchNamespace)
}
log.Printf("Registering Components.")
// Get a config to talk to the apiserver

// Setup controller-runtime logger.
log.SetLogger(klogr.New())

// Get a config to talk to the api-server.
cfg, err := config.GetConfig()
if err != nil {
log.Fatal(err)
klog.Fatal(err)
}

// Create a new Cmd to provide shared dependencies and start components
// Create a new Cmd to provide shared dependencies and start components.
syncPeriod := 10 * time.Minute
mgr, err := manager.New(cfg, manager.Options{
SyncPeriod: &syncPeriod,
Namespace: *watchNamespace,
})

if err != nil {
log.Fatal(err)
klog.Fatalf("Failed to create new Manager: %v", err)
}

log.Printf("Registering Components.")
klog.Info("Registering Components")

// Setup Scheme for all resources
// Setup Scheme for all resources.
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
klog.Fatal(err)
}

// Setup all Controllers
// Setup all Controllers.
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
klog.Fatal(err)
}

log.Printf("Starting the Cmd.")
klog.Info("Starting the Cmd")

// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
klog.Fatal(mgr.Start(signals.SetupSignalHandler()))
}
13 changes: 13 additions & 0 deletions vendor/k8s.io/klog/klogr/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/k8s.io/klog/klogr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

194 changes: 194 additions & 0 deletions vendor/k8s.io/klog/klogr/klogr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ebf076

Please sign in to comment.