Skip to content

Commit

Permalink
Merge pull request #2 from suvaanshkumar/fix-logger-warning
Browse files Browse the repository at this point in the history
Fix runtime logger warning
  • Loading branch information
suvaanshkumar authored Jan 31, 2025
2 parents acfd48e + 75a2522 commit 0b57d6f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"context"
"io"
"log"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -61,21 +62,23 @@ func main() {
)

kingpin.MustParse(app.Parse(os.Args[1:]))
log.Default().SetOutput(io.Discard)
ctrl.SetLogger(zap.New(zap.WriteTo(io.Discard)))

zl := zap.New(zap.UseDevMode(*debug))
log := logging.NewLogrLogger(zl.WithName("provider-artfactory"))
logr := logging.NewLogrLogger(zl.WithName("provider-artfactory"))
if *debug {
// The controller-runtime runs with a no-op logger by default. It is
// *very* verbose even at info level, so we only provide it a real
// logger when we're running in debug mode.
ctrl.SetLogger(zl)
} else {
// In non debug mode, setting the logger to no-op to fix the runtime warning which says
// log.SetLogger(...) was never called
// logr.SetLogger(...) was never called
ctrl.SetLogger(zap.New(zap.WriteTo(io.Discard)))
}

log.Debug("Starting", "sync-period", syncPeriod.String(), "poll-interval", pollInterval.String(), "max-reconcile-rate", *maxReconcileRate)
logr.Debug("Starting", "sync-period", syncPeriod.String(), "poll-interval", pollInterval.String(), "max-reconcile-rate", *maxReconcileRate)

cfg, err := ctrl.GetConfig()
kingpin.FatalIfError(err, "Cannot get API server rest config")
Expand All @@ -101,7 +104,7 @@ func main() {

o := tjcontroller.Options{
Options: xpcontroller.Options{
Logger: log,
Logger: logr,
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
PollInterval: *pollInterval,
MaxConcurrentReconciles: *maxReconcileRate,
Expand All @@ -114,19 +117,19 @@ func main() {
},
Provider: config.GetProvider(),
// use the following WorkspaceStoreOption to enable the shared gRPC mode
// terraform.WithProviderRunner(terraform.NewSharedProvider(log, os.Getenv("TERRAFORM_NATIVE_PROVIDER_PATH"), terraform.WithNativeProviderArgs("-debuggable")))
WorkspaceStore: terraform.NewWorkspaceStore(log),
// terraform.WithProviderRunner(terraform.NewSharedProvider(logr, os.Getenv("TERRAFORM_NATIVE_PROVIDER_PATH"), terraform.WithNativeProviderArgs("-debuggable")))
WorkspaceStore: terraform.NewWorkspaceStore(logr),
SetupFn: clients.TerraformSetupBuilder(*terraformVersion, *providerSource, *providerVersion),
}

if *enableExternalSecretStores {
o.Features.Enable(features.EnableAlphaExternalSecretStores)
o.SecretStoreConfigGVK = &v1alpha1.StoreConfigGroupVersionKind
log.Info("Alpha feature enabled", "flag", features.EnableAlphaExternalSecretStores)
logr.Info("Alpha feature enabled", "flag", features.EnableAlphaExternalSecretStores)

o.ESSOptions = &tjcontroller.ESSOptions{}
if *essTLSCertsPath != "" {
log.Info("ESS TLS certificates path is set. Loading mTLS configuration.")
logr.Info("ESS TLS certificates path is set. Loading mTLS configuration.")
tCfg, err := certificates.LoadMTLSConfig(filepath.Join(*essTLSCertsPath, "ca.crt"), filepath.Join(*essTLSCertsPath, "tls.crt"), filepath.Join(*essTLSCertsPath, "tls.key"), false)
kingpin.FatalIfError(err, "Cannot load ESS TLS config.")

Expand All @@ -150,7 +153,7 @@ func main() {

if *enableManagementPolicies {
o.Features.Enable(features.EnableBetaManagementPolicies)
log.Info("Beta feature enabled", "flag", features.EnableBetaManagementPolicies)
logr.Info("Beta feature enabled", "flag", features.EnableBetaManagementPolicies)
}

kingpin.FatalIfError(controller.Setup(mgr, o), "Cannot setup Artifactory controllers")
Expand Down

0 comments on commit 0b57d6f

Please sign in to comment.