Skip to content

Commit

Permalink
chore: Wrap some errors with more information
Browse files Browse the repository at this point in the history
Added more context for errors in logs.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Dec 6, 2023
1 parent cb51362 commit e194ae8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions controllers/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ func CreateAndStartReconciler(ctx context.Context, mgr controllerruntime.Manager
mgrCtx = logr.NewContext(mgrCtx, mgr.GetLogger())

if err := setupManager(mgrCtx, cancel, mgr); err != nil {
return err
return fmt.Errorf("failed to setup manager: %w", err)
}

mgr.GetLogger().Info("starting manager")
if err := mgr.Start(mgrCtx); err != nil {
mgr.GetLogger().Error(err, "problem running manager")
return err
return fmt.Errorf("failed to start manager: %w", err)
}
return nil
}

func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controllerruntime.Manager) error {
runningOnOpenShift, err := common.RunningOnOpenshift(ctx, mgr.GetAPIReader())
if err != nil {
return err
return fmt.Errorf("failed to check if running on openshift: %w", err)
}

templatesFile := filepath.Join(templateBundleDir, "common-templates-"+common_templates.Version+".yaml")
Expand All @@ -68,13 +68,13 @@ func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controller
tektonPipelinesBundlePaths := tekton_bundle.GetTektonPipelineBundlePaths()
tektonPipelinesBundle, err := tekton_bundle.ReadBundle(tektonPipelinesBundlePaths)
if err != nil {
return err
return fmt.Errorf("failed to read tekton pipelines bundle: %w", err)
}

tektonTasksBundlePath := tekton_bundle.GetTektonTasksBundlePath(runningOnOpenShift)
tektonTasksBundle, err := tekton_bundle.ReadBundle([]string{tektonTasksBundlePath})
if err != nil {
return err
return fmt.Errorf("failed to read tekton tasks bundle: %w", err)
}

tektonPipelinesOperand := tekton_pipelines.New(tektonPipelinesBundle)
Expand Down Expand Up @@ -118,7 +118,7 @@ func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controller
crdWatch.SomeCrdRemovedHandler = cancel

if err = crdWatch.Init(ctx, mgr.GetAPIReader()); err != nil {
return err
return fmt.Errorf("failed to initialize CRD watch: %w", err)
}

if missingCrds := crdWatch.MissingCrds(); len(missingCrds) > 0 {
Expand All @@ -131,12 +131,12 @@ func setupManager(ctx context.Context, cancel context.CancelFunc, mgr controller
if runningOnOpenShift {
infrastructureTopology, err = common.GetInfrastructureTopology(ctx, mgr.GetAPIReader())
if err != nil {
return err
return fmt.Errorf("failed to get infrastructure topology: %w", err)
}
}

if err = mgr.Add(crdWatch); err != nil {
return err
return fmt.Errorf("failed to add CRD watch to manager: %w", err)
}

serviceController, err := CreateServiceController(ctx, mgr)
Expand Down
4 changes: 2 additions & 2 deletions internal/crd-watch/crd-watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ func (c *CrdWatch) Start(ctx context.Context) error {
},
})
if err != nil {
return err
return fmt.Errorf("failed to add event handler to informer: %w", err)
}

if err := c.sync(ctx, c.cache); err != nil {
return err
return fmt.Errorf("failed to sync CRD watch: %w", err)
}

// This function has to block, because that is what manager.Runnable expects.
Expand Down

0 comments on commit e194ae8

Please sign in to comment.