Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace github.com/pkg/errors with standard library errors package #1688

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/onsi/ginkgo/v2 v2.20.2
github.com/onsi/gomega v1.34.2
github.com/operator-framework/api v0.17.6
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.4
github.com/ramendr/ramen/api v0.0.0-20240924121439-b7cba82de417
github.com/ramendr/recipe v0.0.0-20240918115450-667b9d79599f
Expand Down Expand Up @@ -76,6 +75,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/cel/cel_drclusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// corev1 "k8s.io/api/core/v1"
// validationErrors "k8s.io/kube-openapi/pkg/validation/errors"
// "sigs.k8s.io/controller-runtime/pkg/client"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ var _ = Describe("DRCluster-CEL", func() {
drclusterDelete := func(drcluster *ramen.DRCluster) {
Expect(k8sClient.Delete(context.TODO(), drcluster)).To(Succeed())
Eventually(func() bool {
return errors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{
return k8serrors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{
Name: drcluster.Name,
}, drcluster))
}, timeout, interval).Should(BeTrue())
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/cel/cel_drplacementcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// gomegaTypes "github.com/onsi/gomega/types"
ramen "github.com/ramendr/ramen/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
// validationErrors "k8s.io/kube-openapi/pkg/validation/errors"
Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("DRPC-CEL", func() {
deleteDRPC := func(drpc *ramen.DRPlacementControl) {
Expect(k8sClient.Delete(context.TODO(), drpc)).To(Succeed())
Eventually(func() bool {
return errors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{
return k8serrors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{
Name: drpc.Name, Namespace: drpc.Namespace,
}, drpc))
}, timeout, interval).Should(BeTrue())
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/cel/cel_drpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// gomegaTypes "github.com/onsi/gomega/types"
ramen "github.com/ramendr/ramen/api/v1alpha1"
// corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -56,7 +56,7 @@ var _ = Describe("DRPolicy-CEL", func() {
drpolicyDeleteAndConfirm := func(drpolicy *ramen.DRPolicy) {
Expect(k8sClient.Delete(context.TODO(), drpolicy)).To(Succeed())
Eventually(func() bool {
return errors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{Name: drpolicy.Name}, drpolicy))
return k8serrors.IsNotFound(k8sClient.Get(context.TODO(), types.NamespacedName{Name: drpolicy.Name}, drpolicy))
}, timeout, interval).Should(BeTrue())
}
drpolicyDelete := func(drpolicy *ramen.DRPolicy) {
Expand All @@ -76,10 +76,10 @@ var _ = Describe("DRPolicy-CEL", func() {
It("should fail to create drpolicy", func() {
drp := drpolicies[0].DeepCopy()
drp.Spec.DRClusters = nil
err := func() *errors.StatusError {
err := func() *k8serrors.StatusError {
path := field.NewPath("spec", "drClusters")

return errors.NewInvalid(
return k8serrors.NewInvalid(
schema.GroupKind{
Group: ramen.GroupVersion.Group,
Kind: "DRPolicy",
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ramendr/ramen/internal/controller/util"
"github.com/ramendr/ramen/internal/controller/volsync"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -349,7 +349,7 @@ func (c *cgHandler) DeleteLocalRDAndRS(rd *volsyncv1alpha1.ReplicationDestinatio
Namespace: lrs.GetNamespace(),
}, lrs)
if err != nil {
if errors.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
return c.VSHandler.DeleteLocalRD(
getLocalReplicationName(rd.Name),
rd.Namespace,
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/cephfscg/volumegroupsourcehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/ramendr/ramen/internal/controller/volsync"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -159,7 +159,7 @@ func (h *volumeGroupSourceHandler) CleanVolumeGroupSnapshot(
if err := h.Client.Get(ctx, types.NamespacedName{
Name: h.VolumeGroupSnapshotName, Namespace: h.VolumeGroupSnapshotNamespace,
}, volumeGroupSnapshot); err != nil {
if errors.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
logger.Info("Volume group snapshot was already deleted")

return nil
Expand Down Expand Up @@ -194,7 +194,7 @@ func (h *volumeGroupSourceHandler) CleanVolumeGroupSnapshot(
Name: restoredPVCName,
Namespace: restoredPVCNamespace,
},
}); err != nil && !errors.IsNotFound(err) {
}); err != nil && !k8serrors.IsNotFound(err) {
logger.Error(err, "Failed to delete restored PVC ",
"PVCName", restoredPVCName, "PVCNamespace", restoredPVCNamespace)

Expand All @@ -203,7 +203,7 @@ func (h *volumeGroupSourceHandler) CleanVolumeGroupSnapshot(
}
}

if err := h.Client.Delete(ctx, volumeGroupSnapshot); err != nil && !errors.IsNotFound(err) {
if err := h.Client.Delete(ctx, volumeGroupSnapshot); err != nil && !k8serrors.IsNotFound(err) {
logger.Error(err, "Failed to delete volume group snapshot")

return err
Expand Down Expand Up @@ -335,7 +335,7 @@ func (h *volumeGroupSourceHandler) RestoreVolumesFromSnapshot(
)
// If this pvc already exists and not pointing to our desired snapshot, we will need to
// delete it and re-create as we cannot update the datah.VolumeGroupSnapshotSource
if err := h.Client.Delete(ctx, restoredPVC); err != nil && !errors.IsNotFound(err) {
if err := h.Client.Delete(ctx, restoredPVC); err != nil && !k8serrors.IsNotFound(err) {
return fmt.Errorf("failed to delete PVC: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/cephfscg/volumegroupsourcehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -105,7 +105,7 @@ var _ = Describe("Volumegroupsourcehandler", func() {
Namespace: "default",
}, pvc)
if err != nil {
return !errors.IsNotFound(err)
return !k8serrors.IsNotFound(err)
}

return pvc.DeletionTimestamp.IsZero()
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/controllers_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
ramen "github.com/ramendr/ramen/api/v1alpha1"
controllers "github.com/ramendr/ramen/internal/controller"
"github.com/ramendr/ramen/internal/controller/util"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -378,7 +378,7 @@ func ensureDRClusterConfigMWNotFound(k8sClient client.Client, managedCluster str
mw,
)

return errors.IsNotFound(err)
return k8serrors.IsNotFound(err)
}

if always {
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/google/uuid"
viewv1beta1 "github.com/stolostron/multicloud-operators-foundation/pkg/apis/view/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -948,7 +948,7 @@ func (u *drclusterInstance) unfenceClusterOnCluster(peerCluster *ramen.DRCluster
nf, err := u.reconciler.MCVGetter.GetNFFromManagedCluster(u.object.Name,
u.object.Namespace, peerCluster.Name, annotations)
if err != nil {
if errors.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
return u.requeueIfNFMWExists(peerCluster)
}

Expand Down Expand Up @@ -979,7 +979,7 @@ func (u *drclusterInstance) unfenceClusterOnCluster(peerCluster *ramen.DRCluster
func (u *drclusterInstance) requeueIfNFMWExists(peerCluster *ramen.DRCluster) (bool, error) {
_, mwErr := u.mwUtil.FindManifestWorkByType(util.MWTypeNF, peerCluster.Name)
if mwErr != nil {
if errors.IsNotFound(mwErr) {
if k8serrors.IsNotFound(mwErr) {
u.log.Info("NetworkFence and MW for it not found. Cleaned")

return false, nil
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/drcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
controllers "github.com/ramendr/ramen/internal/controller"
"github.com/ramendr/ramen/internal/controller/util"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -88,13 +88,13 @@ var _ = Describe("DRClusterController", func() {
clusterName := drcluster.Name
Expect(k8sClient.Delete(context.TODO(), drcluster)).To(Succeed())
Eventually(func() bool {
return errors.IsNotFound(apiReader.Get(context.TODO(), types.NamespacedName{
return k8serrors.IsNotFound(apiReader.Get(context.TODO(), types.NamespacedName{
Namespace: drcluster.Namespace,
Name: drcluster.Name,
}, drcluster))
}, timeout, interval).Should(BeTrue())
manifestWork := &workv1.ManifestWork{}
Expect(errors.IsNotFound(apiReader.Get(
Expect(k8serrors.IsNotFound(apiReader.Get(
context.TODO(),
types.NamespacedName{
Name: util.DrClusterManifestWorkName,
Expand Down Expand Up @@ -180,7 +180,7 @@ var _ = Describe("DRClusterController", func() {
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{Name: namespace.Name}, namespace)
}, timeout, interval).Should(
MatchError(errors.NewNotFound(schema.GroupResource{Resource: "namespaces"}, namespace.Name)),
MatchError(k8serrors.NewNotFound(schema.GroupResource{Resource: "namespaces"}, namespace.Name)),
"%v", namespace,
)
}
Expand Down Expand Up @@ -226,7 +226,7 @@ var _ = Describe("DRClusterController", func() {
policy := drpolicy.DeepCopy()
Expect(k8sClient.Delete(context.TODO(), policy)).To(Succeed())
Eventually(func() bool {
return errors.IsNotFound(apiReader.Get(context.TODO(), types.NamespacedName{Name: policy.Name}, policy))
return k8serrors.IsNotFound(apiReader.Get(context.TODO(), types.NamespacedName{Name: policy.Name}, policy))
}, timeout, interval).Should(BeTrue())
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/drcluster_mmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package controllers
import (
"github.com/go-logr/logr"
viewv1beta1 "github.com/stolostron/multicloud-operators-foundation/pkg/apis/view/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ocmworkv1 "open-cluster-management.io/api/work/v1"

Expand Down Expand Up @@ -341,7 +341,7 @@ func (u *drclusterInstance) pruneMModeMCV(
}

// Other errors require us to try later
if !errors.IsNotFound(err) {
if !k8serrors.IsNotFound(err) {
u.log.Error(err, "Error fetching viewed resource")

u.requeue = true
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/drclusterconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -207,7 +207,7 @@ var _ = Describe("DRClusterConfig-ClusterClaimsTests", Ordered, func() {
Name: "local",
}, drCConfig)

return errors.IsNotFound(err)
return k8serrors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())

By("ensuring claim count is 0 post deletion")
Expand Down
Loading
Loading