Skip to content

Commit

Permalink
Fix erroneous errors.Join usage
Browse files Browse the repository at this point in the history
* properly leverage multierr feature via
  `errors.Join`
* side: removed undesired package from the
  direct dependencies

Fixes #258
  • Loading branch information
zerospiel committed Sep 4, 2024
1 parent d9cfcd3 commit b7d3c75
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/opencontainers/go-digest v1.0.1-0.20231025023718-d50d2fec9c98
github.com/pkg/errors v0.9.1
github.com/segmentio/analytics-go v3.1.0+incompatible
helm.sh/helm/v3 v3.15.4
k8s.io/api v0.31.0
Expand Down Expand Up @@ -115,6 +114,7 @@ require (
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/image-spec v1.1.0-rc6 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.20.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down
13 changes: 7 additions & 6 deletions internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag
if err != nil {
errMsg := fmt.Sprintf("Failed to get Template %s/%s: %s", hmc.TemplatesNamespace, component.Template, err)
updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg)
errs = errors.Join(errors.New(errMsg))
errs = errors.Join(errs, errors.New(errMsg))
continue
}
if !template.Status.Valid {
errMsg := fmt.Sprintf("Template %s/%s is not marked as valid", hmc.TemplatesNamespace, component.Template)
updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg)
errs = errors.Join(errors.New(errMsg))
errs = errors.Join(errs, errors.New(errMsg))
continue
}

Expand All @@ -122,7 +122,7 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag
if err != nil {
errMsg := fmt.Sprintf("error reconciling HelmRelease %s/%s: %s", management.Namespace, component.Template, err)
updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg)
errs = errors.Join(errors.New(errMsg))
errs = errors.Join(errs, errors.New(errMsg))
continue
}
updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, "")
Expand All @@ -132,7 +132,8 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag
management.Status.AvailableProviders = detectedProviders
management.Status.Components = detectedComponents
if err := r.Status().Update(ctx, management); err != nil {
errs = errors.Join(fmt.Errorf("failed to update status for Management %s/%s: %w", management.Namespace, management.Name, err))
errs = errors.Join(errs, fmt.Errorf("failed to update status for Management %s/%s: %w",
management.Namespace, management.Name, err))
}
if errs != nil {
l.Error(errs, "Multiple errors during Management reconciliation")
Expand Down Expand Up @@ -282,8 +283,8 @@ func updateComponentsStatus(
providers *hmc.Providers,
componentName string,
templateStatus hmc.TemplateStatus,
err string) {

err string,
) {
components[componentName] = hmc.ComponentStatus{
Error: err,
Success: err == "",
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/release_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package controller
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"

hcv2 "github.com/fluxcd/helm-controller/api/v2"
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/storage/driver"
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func EnsureDeleteAllOf(ctx context.Context, cl client.Client, gvk schema.GroupVe
for _, item := range itemsList.Items {
if item.DeletionTimestamp.IsZero() {
if err := cl.Delete(ctx, &item); err != nil && !apierrors.IsNotFound(err) {
errs = errors.Join(err)
errs = errors.Join(errs, err)
continue
}
}
errs = errors.Join(fmt.Errorf("waiting for %s %s/%s removal", gvk.Kind, item.Namespace, item.Name))
errs = errors.Join(errs, fmt.Errorf("waiting for %s %s/%s removal", gvk.Kind, item.Namespace, item.Name))
}
return errs
}
4 changes: 1 addition & 3 deletions internal/webhook/deployment_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ type DeploymentValidator struct {
client.Client
}

var (
InvalidDeploymentErr = errors.New("the deployment is invalid")
)
var InvalidDeploymentErr = errors.New("the deployment is invalid")

func (v *DeploymentValidator) SetupWebhookWithManager(mgr ctrl.Manager) error {
v.Client = mgr.GetClient()
Expand Down

0 comments on commit b7d3c75

Please sign in to comment.