Wrap errors in runControllers for additional context

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/3898/head
Brad Davidson 2021-07-02 17:09:02 -07:00 committed by Brad Davidson
parent 422d266da2
commit c434db7cc6
2 changed files with 8 additions and 7 deletions

View File

@ -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)

View File

@ -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) {