Skip to content

Commit

Permalink
chore(deps): remove github.com/pkg/errors dep
Browse files Browse the repository at this point in the history
Replace the `github.com/pkg/errors` dependency with the `errors` module
part of the Go std library

Signed-off-by: Flavio Castelli <[email protected]>
  • Loading branch information
flavio committed Sep 13, 2023
1 parent 0225723 commit f696f88
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions controllers/admissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package controllers

import (
"context"
"errors"
"fmt"

"github.com/go-logr/logr"
"github.com/kubewarden/kubewarden-controller/internal/pkg/admission"
"github.com/kubewarden/kubewarden-controller/internal/pkg/constants"
"github.com/kubewarden/kubewarden-controller/internal/pkg/naming"
policiesv1 "github.com/kubewarden/kubewarden-controller/pkg/apis/policies/v1"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -91,7 +91,7 @@ func (r *AdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
).
Complete(r)

return errors.Wrap(err, "failed enrolling controller with manager")
return errors.Join(errors.New("failed enrolling controller with manager"), err)
}

func (r *AdmissionPolicyReconciler) findAdmissionPoliciesForConfigMap(object client.Object) []reconcile.Request {
Expand Down
4 changes: 2 additions & 2 deletions controllers/clusteradmissionpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package controllers

import (
"context"
"errors"
"fmt"

"github.com/go-logr/logr"
"github.com/kubewarden/kubewarden-controller/internal/pkg/admission"
"github.com/kubewarden/kubewarden-controller/internal/pkg/constants"
"github.com/kubewarden/kubewarden-controller/internal/pkg/naming"
policiesv1 "github.com/kubewarden/kubewarden-controller/pkg/apis/policies/v1"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -91,7 +91,7 @@ func (r *ClusterAdmissionPolicyReconciler) SetupWithManager(mgr ctrl.Manager) er
).
Complete(r)

return errors.Wrap(err, "failed enrolling controller with manager")
return errors.Join(errors.New("failed enrolling controller with manager"), err)
}

func (r *ClusterAdmissionPolicyReconciler) findClusterAdmissionPoliciesForConfigMap(object client.Object) []reconcile.Request {
Expand Down
16 changes: 8 additions & 8 deletions controllers/policy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -26,7 +27,6 @@ import (
"github.com/kubewarden/kubewarden-controller/internal/pkg/metrics"
"github.com/kubewarden/kubewarden-controller/internal/pkg/naming"
policiesv1 "github.com/kubewarden/kubewarden-controller/pkg/apis/policies/v1"
"github.com/pkg/errors"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -42,12 +42,12 @@ import (
func setPolicyStatus(ctx context.Context, deploymentsNamespace string, apiReader client.Reader, policy policiesv1.Policy) error {
policyServerDeployment := appsv1.Deployment{}
if err := apiReader.Get(ctx, types.NamespacedName{Namespace: deploymentsNamespace, Name: naming.PolicyServerDeploymentNameForPolicyServerName(policy.GetPolicyServer())}, &policyServerDeployment); err != nil {
return errors.Wrap(err, "could not get policy server deployment")
return errors.Join(errors.New("could not get policy server deployment"), err)
}

policyServerConfigMap := corev1.ConfigMap{}
if err := apiReader.Get(ctx, types.NamespacedName{Namespace: deploymentsNamespace, Name: naming.PolicyServerDeploymentNameForPolicyServerName(policy.GetPolicyServer())}, &policyServerConfigMap); err != nil {
return errors.Wrap(err, "could not get configmap")
return errors.Join(errors.New("could not get configmap"), err)
}

policyMap, err := getPolicyMapFromConfigMap(&policyServerConfigMap)
Expand Down Expand Up @@ -117,7 +117,7 @@ func reconcilePolicy(ctx context.Context, client client.Client, reconciler admis
if apierrors.IsNotFound(err) {
return ctrl.Result{Requeue: true}, nil
}
return ctrl.Result{}, errors.Wrap(err, "could not read policy server Deployment")
return ctrl.Result{}, errors.Join(errors.New("could not read policy server Deployment"), err)
}

if !isPolicyUniquelyReachable(ctx, client, &policyServerDeployment, policy.GetUniqueName()) {
Expand Down Expand Up @@ -145,16 +145,16 @@ func reconcilePolicy(ctx context.Context, client client.Client, reconciler admis

secret := corev1.Secret{}
if err := client.Get(ctx, types.NamespacedName{Namespace: reconciler.DeploymentsNamespace, Name: constants.PolicyServerCARootSecretName}, &secret); err != nil {
return ctrl.Result{}, errors.Wrap(err, "cannot find policy server secret")
return ctrl.Result{}, errors.Join(errors.New("cannot find policy server secret"), err)
}

if policy.IsMutating() {
if err := reconciler.ReconcileMutatingWebhookConfiguration(ctx, policy, &secret, policyServer.NameWithPrefix()); err != nil {
return ctrl.Result{}, errors.Wrap(err, "error reconciling mutating webhook")
return ctrl.Result{}, errors.Join(errors.New("error reconciling mutating webhook"), err)
}
} else {
if err := reconciler.ReconcileValidatingWebhookConfiguration(ctx, policy, &secret, policyServer.NameWithPrefix()); err != nil {
return ctrl.Result{}, errors.Wrap(err, "error reconciling validating webhook")
return ctrl.Result{}, errors.Join(errors.New("error reconciling validating webhook"), err)
}
}
setPolicyAsActive(policy)
Expand All @@ -178,7 +178,7 @@ func setPolicyAsActive(policy policiesv1.Policy) {
func getPolicyServer(ctx context.Context, client client.Client, policy policiesv1.Policy) (*policiesv1.PolicyServer, error) {
policyServer := policiesv1.PolicyServer{}
if err := client.Get(ctx, types.NamespacedName{Name: policy.GetPolicyServer()}, &policyServer); err != nil {
return nil, errors.Wrap(err, "could not get policy server")
return nil, errors.Join(errors.New("could not get policy server"), err)
}
return &policyServer, nil
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/policyserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package controllers

import (
"context"
"errors"
"fmt"
"time"

"github.com/go-logr/logr"
"github.com/kubewarden/kubewarden-controller/internal/pkg/admission"
"github.com/kubewarden/kubewarden-controller/internal/pkg/constants"
policiesv1 "github.com/kubewarden/kubewarden-controller/pkg/apis/policies/v1"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (r *PolicyServerReconciler) Reconcile(ctx context.Context, req ctrl.Request

policies, err := r.Reconciler.GetPolicies(ctx, &policyServer, admission.SkipDeleted)
if err != nil {
return ctrl.Result{}, errors.Wrap(err, "could not get policies")
return ctrl.Result{}, errors.Join(errors.New("could not get policies"), err)
}

if policyServer.ObjectMeta.DeletionTimestamp != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (r *PolicyServerReconciler) reconcileDeletion(ctx context.Context, policySe
}
if len(policies) == 0 {
if err := r.Reconciler.ReconcileDeletion(ctx, policyServer); err != nil {
return ctrl.Result{}, errors.Wrap(err, "could not reconcile policy server deletion")
return ctrl.Result{}, errors.Join(errors.New("could not reconcile policy server deletion"), err)
}
controllerutil.RemoveFinalizer(policyServer, constants.KubewardenFinalizer)
if err := r.Update(ctx, policyServer); err != nil {
Expand Down Expand Up @@ -193,5 +193,5 @@ func (r *PolicyServerReconciler) SetupWithManager(mgr ctrl.Manager) error {
})).
Complete(r)

return errors.Wrap(err, "failed enrolling controller with manager")
return errors.Join(errors.New("failed enrolling controller with manager"), err)
}
4 changes: 2 additions & 2 deletions controllers/policystatus_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package controllers
import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/kubewarden/kubewarden-controller/internal/pkg/admission"
"github.com/kubewarden/kubewarden-controller/internal/pkg/constants"
policiesv1 "github.com/kubewarden/kubewarden-controller/pkg/apis/policies/v1"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apimeta "k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -36,7 +36,7 @@ func getPolicyMapFromConfigMap(configMap *corev1.ConfigMap) (admission.PolicyCon
policyMap := admission.PolicyConfigEntryMap{}
if policies, ok := configMap.Data[constants.PolicyServerConfigPoliciesEntry]; ok {
if err := json.Unmarshal([]byte(policies), &policyMap); err != nil {
return policyMap, errors.Wrap(err, "failed to unmarshal policy mapping")
return policyMap, errors.Join(errors.New("failed to unmarshal policy mapping"), err)
}
} else {
return policyMap, nil
Expand Down

0 comments on commit f696f88

Please sign in to comment.