From c434db7cc6268480992e6ee5f81e3dcd7fe02735 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Fri, 2 Jul 2021 17:09:02 -0700 Subject: [PATCH] Wrap errors in runControllers for additional context Signed-off-by: Brad Davidson --- pkg/server/context.go | 3 ++- pkg/server/server.go | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/server/context.go b/pkg/server/context.go index fac72708db..13ab286635 100644 --- a/pkg/server/context.go +++ b/pkg/server/context.go @@ -7,6 +7,7 @@ import ( "runtime" "github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io" + "github.com/pkg/errors" "github.com/rancher/k3s/pkg/deploy" "github.com/rancher/k3s/pkg/generated/controllers/k3s.cattle.io" "github.com/rancher/k3s/pkg/version" @@ -56,7 +57,7 @@ func NewContext(ctx context.Context, cfg string) (*Context, error) { restConfig.UserAgent = fmt.Sprintf("%s/%s (%s/%s) %s/%s", managerName, version.Version, runtime.GOOS, runtime.GOARCH, version.Program, version.GitCommit) if err := crds(ctx, restConfig); err != nil { - return nil, err + return nil, errors.Wrap(err, "failed to register CRDs") } k8s := kubernetes.NewForConfigOrDie(restConfig) diff --git a/pkg/server/server.go b/pkg/server/server.go index 7cdee43586..b565ce59c0 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -117,12 +117,12 @@ func runControllers(ctx context.Context, wg *sync.WaitGroup, config *Config) err sc, err := NewContext(ctx, controlConfig.Runtime.KubeConfigAdmin) if err != nil { - return err + return errors.Wrap(err, "failed to create new server context") } wg.Wait() if err := stageFiles(ctx, sc, controlConfig); err != nil { - return err + return errors.Wrap(err, "failed to stage files") } // run migration before we set controlConfig.Runtime.Core @@ -130,24 +130,24 @@ func runControllers(ctx context.Context, wg *sync.WaitGroup, config *Config) err sc.Core.Core().V1().Secret(), sc.Core.Core().V1().Node(), controlConfig.Runtime.NodePasswdFile); err != nil { - logrus.Warn(errors.Wrapf(err, "error migrating node-password file")) + logrus.Warn(errors.Wrap(err, "error migrating node-password file")) } controlConfig.Runtime.Core = sc.Core if controlConfig.Runtime.ClusterControllerStart != nil { if err := controlConfig.Runtime.ClusterControllerStart(ctx); err != nil { - return errors.Wrapf(err, "starting cluster controllers") + return errors.Wrap(err, "failed to start cluster controllers") } } for _, controller := range config.Controllers { if err := controller(ctx, sc); err != nil { - return errors.Wrap(err, "controller") + return errors.Wrapf(err, "failed to start custom controller %s", util.GetFunctionName(controller)) } } if err := sc.Start(ctx); err != nil { - return err + return errors.Wrap(err, "failed to start wranger controllers") } start := func(ctx context.Context) {