From 3f335ca628807682f06495097d8d2555415ea552 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 10 Nov 2020 17:03:33 +0900 Subject: [PATCH] Fix panic on startup when misconfigured (#154) Fixes #153 --- github/github.go | 4 ---- main.go | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/github/github.go b/github/github.go index 440a7fd9..692488f7 100644 --- a/github/github.go +++ b/github/github.go @@ -9,14 +9,12 @@ import ( "time" "github.com/bradleyfalzon/ghinstallation" - "github.com/go-logr/logr" "github.com/google/go-github/v32/github" "golang.org/x/oauth2" ) // Config contains configuration for Github client type Config struct { - Log logr.Logger EnterpriseURL string `split_words:"true"` AppID int64 `split_words:"true"` AppInstallationID int64 `split_words:"true"` @@ -46,7 +44,6 @@ func (c *Config) NewClient() (*Client, error) { } else { tr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, c.AppID, c.AppInstallationID, c.AppPrivateKey) if err != nil { - c.Log.Error(err, "Authentication failed") return nil, fmt.Errorf("authentication failed: %v", err) } httpClient = &http.Client{Transport: tr} @@ -56,7 +53,6 @@ func (c *Config) NewClient() (*Client, error) { var err error client, err = github.NewEnterpriseClient(c.EnterpriseURL, c.EnterpriseURL, httpClient) if err != nil { - c.Log.Error(err, "Enterprise client creation failed") return nil, fmt.Errorf("enterprise client creation failed: %v", err) } githubBaseURL = fmt.Sprintf("%s://%s%s", client.BaseURL.Scheme, client.BaseURL.Host, strings.TrimSuffix(client.BaseURL.Path, "api/v3/")) diff --git a/main.go b/main.go index f01a16c9..63fcff1f 100644 --- a/main.go +++ b/main.go @@ -82,15 +82,17 @@ func main() { flag.DurationVar(&syncPeriod, "sync-period", 10*time.Minute, "Determines the minimum frequency at which K8s resources managed by this controller are reconciled. When you use autoscaling, set to a lower value like 10 minute, because this corresponds to the minimum time to react on demand change") flag.Parse() + logger := zap.New(func(o *zap.Options) { + o.Development = true + }) + ghClient, err = c.NewClient() if err != nil { fmt.Fprintln(os.Stderr, "Error: Client creation failed.", err) os.Exit(1) } - ctrl.SetLogger(zap.New(func(o *zap.Options) { - o.Development = true - })) + ctrl.SetLogger(logger) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme,