Skip to content

Commit

Permalink
Refactor longer length inline error checking statements
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Sep 1, 2023
1 parent c8a883b commit 8749d12
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
8 changes: 7 additions & 1 deletion internal/framework/controller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func Register(
}

for field, indexerFunc := range cfg.fieldIndices {
if err := addIndex(ctx, mgr.GetFieldIndexer(), objectType, field, indexerFunc); err != nil {
if err := addIndex(
ctx,
mgr.GetFieldIndexer(),
objectType,
field,
indexerFunc,
); err != nil {
return err
}
}
Expand Down
9 changes: 7 additions & 2 deletions internal/mode/provisioner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ func StartManager(cfg Config) error {
eventCh := make(chan interface{})

for _, regCfg := range controllerRegCfgs {
err := controller.Register(ctx, regCfg.objectType, mgr, eventCh, regCfg.options...)
if err != nil {
if err := controller.Register(
ctx,
regCfg.objectType,
mgr,
eventCh,
regCfg.options...,
); err != nil {
return fmt.Errorf("cannot register controller for %T: %w", regCfg.objectType, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/mode/static/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func (h *eventHandlerImpl) HandleEventBatch(ctx context.Context, batch events.Ev
}

var nginxReloadRes nginxReloadResult
err := h.updateNginx(ctx, dataplane.BuildConfiguration(ctx, graph, h.cfg.serviceResolver))
if err != nil {
if err := h.updateNginx(ctx, dataplane.BuildConfiguration(ctx, graph, h.cfg.serviceResolver)); err != nil {
h.cfg.logger.Error(err, "Failed to update NGINX configuration")
nginxReloadRes.error = err
} else {
Expand Down
9 changes: 7 additions & 2 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ func StartManager(cfg config.Config) error {
ctx := ctlr.SetupSignalHandler()

for _, regCfg := range controllerRegCfgs {
err := controller.Register(ctx, regCfg.objectType, mgr, eventCh, regCfg.options...)
if err != nil {
if err := controller.Register(
ctx,
regCfg.objectType,
mgr,
eventCh,
regCfg.options...,
); err != nil {
return fmt.Errorf("cannot register controller for %T: %w", regCfg.objectType, err)
}
}
Expand Down
12 changes: 9 additions & 3 deletions internal/mode/static/state/graph/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ func buildRoute(
ParentRefs: sectionNameRefs,
}

err := validateHostnames(ghr.Spec.Hostnames, field.NewPath("spec").Child("hostnames"))
if err != nil {
if err := validateHostnames(
ghr.Spec.Hostnames,
field.NewPath("spec").Child("hostnames"),
); err != nil {
r.Valid = false
r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(err.Error()))

Expand Down Expand Up @@ -550,7 +552,11 @@ func validateMatch(
allErrs = append(allErrs, validateQueryParamMatch(validator, q, queryParamPath)...)
}

if err := validateMethodMatch(validator, match.Method, matchPath.Child("method")); err != nil {
if err := validateMethodMatch(
validator,
match.Method,
matchPath.Child("method"),
); err != nil {
allErrs = append(allErrs, err)
}

Expand Down

0 comments on commit 8749d12

Please sign in to comment.