Skip to content

Commit

Permalink
use ctxlog from shipwright packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Jul 8, 2021
1 parent 45bd730 commit 2b56144
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
21 changes: 11 additions & 10 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/shipwright-io/build/pkg/ctxlog"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -26,8 +27,7 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
)

// variables to hold command-line flags
Expand Down Expand Up @@ -64,7 +64,9 @@ func main() {
opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
l := ctxlog.NewLogger("shipwrightBuild-controller")

ctx := ctxlog.NewParentContext(l)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand All @@ -75,32 +77,31 @@ func main() {
LeaderElectionID: "01a9b2d1.shipwright.io",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
ctxlog.Error(ctx, err, "unable to start manager")
os.Exit(1)
}

if err = (&controllers.ShipwrightBuildReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("ShipwrightBuild"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ShipwrightBuild")
ctxlog.Error(ctx, err, "unable to create controller")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("health", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
ctxlog.Error(ctx, err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("check", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
ctxlog.Error(ctx, err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
ctxlog.Info(ctx, "starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
ctxlog.Error(ctx, err, "problem running manager")
os.Exit(1)
}
}
1 change: 0 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ var _ = BeforeSuite(func() {
err = (&ShipwrightBuildReconciler{
Client: mgr.GetClient(),
Scheme: scheme.Scheme,
Log: ctrl.Log.WithName("controllers").WithName("shipwrightbuild"),
}).SetupWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit 2b56144

Please sign in to comment.