diff --git a/go.mod b/go.mod index e1f59430b5..959c0a2b91 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/jpillora/backoff v1.0.0 github.com/json-iterator/go v1.1.12 github.com/kanisterio/errkit v0.0.2 - github.com/kanisterio/safecli v0.0.8 + github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad github.com/kopia/kopia v0.17.1-0.20240927044625-1bceb7155ede github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 github.com/lib/pq v1.10.9 diff --git a/go.sum b/go.sum index 7512c046b2..3481c940b8 100644 --- a/go.sum +++ b/go.sum @@ -377,6 +377,8 @@ github.com/kanisterio/errkit v0.0.2 h1:3v3HGz9lHIbZR6Jr9qIJpRjaqUX0rsJSLMEQGsMHi github.com/kanisterio/errkit v0.0.2/go.mod h1:ViQ6kPJ2gTJDEvRytmwde7pzG9/sndObF9BPZoEZixc= github.com/kanisterio/safecli v0.0.8 h1:flvTiGksy/a0+zvqjaBSJwxESu/nFcG65yttmR0XwiA= github.com/kanisterio/safecli v0.0.8/go.mod h1:KBraqj8mdv2cwAr9wecknGUb8jztTzUik0r7uE6yRA8= +github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad h1:JaC21jpch32i3hfUE3m1So06CvPoi+sdQ2KKIRCRKCo= +github.com/kanisterio/safecli v0.0.9-0.20241121134252-2ffd9801dcad/go.mod h1:y1oYVoT2eqsmySCIS5yOzrxaYVywlMSEdWEKfLhBjgs= github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734 h1:qulsCaCv+O2y9/sQ9nd5KChnAgFOWakTHQ9ZADjs6DQ= github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734/go.mod h1:rdqSnvOJuKCPFW/h2rVLuXOAkRnHHdp9PZcKx4HCoDM= github.com/kastenhq/stow v0.2.6-kasten.1.0.20231101232131-9321daa23aae h1:2cl4yuAJpdmLCx7G8eIsfNlQBLEfw0JDj6mTTyqc5qg= diff --git a/pkg/kanx/server.go b/pkg/kanx/server.go index 50883ff938..eab13e1f22 100644 --- a/pkg/kanx/server.go +++ b/pkg/kanx/server.go @@ -3,7 +3,6 @@ package kanx import ( "bytes" "context" - "fmt" "io" "net" "os" @@ -12,7 +11,7 @@ import ( "syscall" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "google.golang.org/grpc" "github.com/kanisterio/kanister/pkg/field" @@ -117,12 +116,12 @@ func (s *processServiceServer) ListProcesses(lpr *ListProcessesRequest, lps Proc return nil } -var errProcessNotFound = fmt.Errorf("Process not found") +var errProcessNotFound = errkit.NewSentinelErr("Process not found") func (s *processServiceServer) Stdout(por *ProcessOutputRequest, ss ProcessService_StdoutServer) error { p, ok := s.processes[por.Pid] if !ok { - return errors.WithStack(errProcessNotFound) + return errkit.WithStack(errProcessNotFound) } fh, err := os.Open(p.stdout.Name()) if err != nil { @@ -134,7 +133,7 @@ func (s *processServiceServer) Stdout(por *ProcessOutputRequest, ss ProcessServi func (s *processServiceServer) Stderr(por *ProcessOutputRequest, ss ProcessService_StderrServer) error { p, ok := s.processes[por.Pid] if !ok { - return errors.WithStack(errProcessNotFound) + return errkit.WithStack(errProcessNotFound) } fh, err := os.Open(p.stderr.Name()) if err != nil { diff --git a/pkg/kopia/cli/internal/test/command_suite.go b/pkg/kopia/cli/internal/test/command_suite.go index 57a8c2f96d..660909dc6d 100644 --- a/pkg/kopia/cli/internal/test/command_suite.go +++ b/pkg/kopia/cli/internal/test/command_suite.go @@ -15,9 +15,9 @@ package test import ( + "github.com/kanisterio/errkit" "github.com/kanisterio/safecli" "github.com/kanisterio/safecli/test" - "github.com/pkg/errors" "gopkg.in/check.v1" ) @@ -62,8 +62,7 @@ func (t *CommandTest) assertNoError(c *check.C, err error) { // assertError checks the error against ExpectedErr. func (t *CommandTest) assertError(c *check.C, err error) { - actualErr := errors.Cause(err) - c.Assert(actualErr, check.Equals, t.ExpectedErr) + c.Assert(errkit.Is(err, t.ExpectedErr), check.Equals, true) } // assertCLI asserts the builder's CLI output against ExpectedCLI. diff --git a/pkg/kube/pod.go b/pkg/kube/pod.go index 5fcb0bd162..09be10c94c 100644 --- a/pkg/kube/pod.go +++ b/pkg/kube/pod.go @@ -450,7 +450,7 @@ func checkPVCAndPVStatus(ctx context.Context, vol corev1.Volume, p *corev1.Pod, pvcName := vol.VolumeSource.PersistentVolumeClaim.ClaimName pvc, err := cli.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, pvcName, metav1.GetOptions{}) if err != nil { - if apierrors.IsNotFound(errors.Cause(err)) { + if apierrors.IsNotFound(err) { // Do not return err, wait for timeout, since sometimes in case of statefulsets, they trigger creation of a volume return nil } @@ -469,7 +469,7 @@ func checkPVCAndPVStatus(ctx context.Context, vol corev1.Volume, p *corev1.Pod, } pv, err := cli.CoreV1().PersistentVolumes().Get(ctx, pvName, metav1.GetOptions{}) if err != nil { - if apierrors.IsNotFound(errors.Cause(err)) { + if apierrors.IsNotFound(err) { // wait for timeout return nil } diff --git a/pkg/kube/pod_test.go b/pkg/kube/pod_test.go index 191e074b3a..e88467d780 100644 --- a/pkg/kube/pod_test.go +++ b/pkg/kube/pod_test.go @@ -19,14 +19,15 @@ package kube import ( "context" - "errors" "fmt" "os" "strings" "time" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -1244,3 +1245,18 @@ func (s *PodSuite) TestAddAnnotations(c *check.C) { c.Assert(tc.podOptions, check.DeepEquals, tc.expectedPodOptions) } } + +func (s *PodSuite) TestSomething(c *check.C) { + // Create the fake client + fakeClient := fake.NewSimpleClientset() + + // Add a reactor to simulate an error when trying to get a PVC + fakeClient.PrependReactor("get", "persistentvolumeclaims", func(action testing.Action) (handled bool, ret runtime.Object, err error) { + return true, nil, apierrors.NewNotFound(action.GetResource().GroupResource(), action.GetSubresource()) + }) + + _, err := fakeClient.CoreV1().PersistentVolumeClaims("abc").Get(context.TODO(), "def", metav1.GetOptions{}) + if err != nil { + c.Assert(apierrors.IsNotFound(err), check.Equals, true) + } +}