From 05ea95fe04e4ec2fc11d50ae831be3023596496a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 23:29:02 +0000 Subject: [PATCH 1/4] deps(docker,pip): bump the common-pip group across 2 directories with 3 updates (#3254) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docker/postgres-kanister-tools/requirements.txt | 6 +++--- docker/postgresql/requirements.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/postgres-kanister-tools/requirements.txt b/docker/postgres-kanister-tools/requirements.txt index 9887c7d51b..e1e713f440 100644 --- a/docker/postgres-kanister-tools/requirements.txt +++ b/docker/postgres-kanister-tools/requirements.txt @@ -1,4 +1,4 @@ -awscli==1.35.20 +awscli==1.36.10 pip==24.3.1 -setuptools==75.3.0 -wheel==0.44.0 +setuptools==75.6.0 +wheel==0.45.1 diff --git a/docker/postgresql/requirements.txt b/docker/postgresql/requirements.txt index 5bfbb11d44..fdc1cfa954 100644 --- a/docker/postgresql/requirements.txt +++ b/docker/postgresql/requirements.txt @@ -1,5 +1,5 @@ -awscli==1.35.20 +awscli==1.36.10 wal-e==1.1.1 pip==24.3.1 -setuptools==75.3.0 -wheel==0.44.0 +setuptools==75.6.0 +wheel==0.45.1 From b41f1fbc9db247fe67c5e9d17510b0f917e40a77 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 27 Nov 2024 09:25:51 -0800 Subject: [PATCH 2/4] Clean up comments and variable names (#3262) Signed-off-by: Nick Wright --- pkg/blockstorage/azure/azuredisk.go | 4 ++-- pkg/blockstorage/tags/tags.go | 2 +- pkg/objectstore/directory.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/blockstorage/azure/azuredisk.go b/pkg/blockstorage/azure/azuredisk.go index 24ffe5cb09..e67d6ef07a 100644 --- a/pkg/blockstorage/azure/azuredisk.go +++ b/pkg/blockstorage/azure/azuredisk.go @@ -549,12 +549,12 @@ func (s *AdStorage) SnapshotsList(ctx context.Context, tags map[string]string) ( return nil, errkit.Wrap(err, "SnapshotsClient.List in SnapshotsList") } for _, snap := range page.Value { - k10Snap, err := s.SnapshotParse(ctx, *snap) + parsedSnap, err := s.SnapshotParse(ctx, *snap) if err != nil { log.WithError(err).Print("Incorrect Snaphost type", field.M{"SnapshotID": snap.ID}) continue } - snaps = append(snaps, k10Snap) + snaps = append(snaps, parsedSnap) } } snaps = blockstorage.FilterSnapshotsWithTags(snaps, blockstorage.SanitizeTags(tags)) diff --git a/pkg/blockstorage/tags/tags.go b/pkg/blockstorage/tags/tags.go index ae99e2eec0..95dbb3faea 100644 --- a/pkg/blockstorage/tags/tags.go +++ b/pkg/blockstorage/tags/tags.go @@ -27,7 +27,7 @@ import ( const ( // ClusterTagKey is used to tag resources with the cluster name ClusterTagKey = "kanister.io/clustername" - // VersionTagKey is used to tag resources with the K10 version + // VersionTagKey is used to tag resources with a version VersionTagKey = "kanister.io/version" // AppNameTag is used to tag volumes with the app they belong to AppNameTag = "kanister.io/appname" diff --git a/pkg/objectstore/directory.go b/pkg/objectstore/directory.go index f184c29449..d228230cc1 100644 --- a/pkg/objectstore/directory.go +++ b/pkg/objectstore/directory.go @@ -234,7 +234,7 @@ func (d *directory) Put(ctx context.Context, name string, r io.Reader, size int6 if d.path == "" { return errors.New("invalid entry") } - // K10 tags include '/'. Remove them, at least for S3 + // Replace any '/' in tags with '-'. sTags := sanitizeTags(tags) objName := d.absPathName(name) From ed51ff0eaaeb0f2bc0c4fb0d9d22477f45116470 Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Thu, 28 Nov 2024 15:43:46 -0500 Subject: [PATCH 3/4] fix: Quote profile json when passing to kando in go code (#3261) Signed-off-by: Daniil Fedotov Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/function/export_rds_snapshot_location.go | 7 +++-- pkg/function/rds_functions_test.go | 28 +++++++++++++++++--- pkg/function/restore_rds_snapshot.go | 7 +++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/pkg/function/export_rds_snapshot_location.go b/pkg/function/export_rds_snapshot_location.go index c2df143550..ca32c18251 100644 --- a/pkg/function/export_rds_snapshot_location.go +++ b/pkg/function/export_rds_snapshot_location.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "strconv" "strings" "time" @@ -435,6 +436,8 @@ func postgresBackupCommand(dbEndpoint, username, password string, dbList []strin return nil, errkit.New("No database found to backup") } + profileQuoted := strconv.Quote(string(profile)) + command := []string{ "bash", "-o", @@ -452,9 +455,9 @@ func postgresBackupCommand(dbEndpoint, username, password string, dbList []strin for db in "${dblist[@]}"; do echo "backing up $db db" && pg_dump $db -C --inserts > /backup/$db.sql; done - tar -zc backup | kando location push --profile '%s' --path "${BACKUP_PREFIX}/${BACKUP_ID}" - + tar -zc backup | kando location push --profile %s --path "${BACKUP_PREFIX}/${BACKUP_ID}" - kando output %s ${BACKUP_ID}`, - dbEndpoint, backupPrefix, backupID, strings.Join(dbList, " "), profile, ExportRDSSnapshotToLocBackupID), + dbEndpoint, backupPrefix, backupID, strings.Join(dbList, " "), profileQuoted, ExportRDSSnapshotToLocBackupID), } return command, nil } diff --git a/pkg/function/rds_functions_test.go b/pkg/function/rds_functions_test.go index fc037e6749..f278369a05 100644 --- a/pkg/function/rds_functions_test.go +++ b/pkg/function/rds_functions_test.go @@ -60,10 +60,32 @@ func (s *RDSFunctionsTest) TestPrepareCommand(c *check.C) { command: []string{"bash", "-o", "errexit", "-o", "pipefail", "-c", fmt.Sprintf(` export PGHOST=%s - kando location pull --profile '%s' --path "%s" - | gunzip -c -f | sed 's/"LOCALE"/"LC_COLLATE"/' | psql -q -U "${PGUSER}" %s + kando location pull --profile "%s" --path "%s" - | gunzip -c -f | sed 's/"LOCALE"/"LC_COLLATE"/' | psql -q -U "${PGUSER}" %s `, "db-endpoint", "null", fmt.Sprintf("%s/%s", "/backup/postgres-backup", "backup-id"), postgres.DefaultConnectDatabase), }, }, + { + name: "PostgreS restore command with profile", + dbEngine: PostgrSQLEngine, + action: RestoreAction, + dbEndpoint: "db-endpoint", + username: "test-user", + password: "secret-pass", + backupPrefix: "/backup/postgres-backup", + backupID: "backup-id", + dbEngineVersion: "12.7", + errChecker: check.IsNil, + dbList: []string{"template1"}, + command: []string{"bash", "-o", "errexit", "-o", "pipefail", "-c", + fmt.Sprintf(` + export PGHOST=%s + kando location pull --profile "{\"Location\":{\"type\":\"\",\"bucket\":\"\",\"endpoint\":\"\",\"prefix\":\"\",\"region\":\"\"},\"Credential\":{\"Type\":\"\",\"KeyPair\":null,\"Secret\":null,\"KopiaServerSecret\":null},\"SkipSSLVerify\":false}" --path "%s" - | gunzip -c -f | sed 's/"LOCALE"/"LC_COLLATE"/' | psql -q -U "${PGUSER}" %s + `, "db-endpoint", fmt.Sprintf("%s/%s", "/backup/postgres-backup", "backup-id"), postgres.DefaultConnectDatabase), + }, + tp: param.TemplateParams{ + Profile: ¶m.Profile{}, + }, + }, { name: "PostgreS restore command", dbEngine: PostgrSQLEngine, @@ -79,7 +101,7 @@ func (s *RDSFunctionsTest) TestPrepareCommand(c *check.C) { command: []string{"bash", "-o", "errexit", "-o", "pipefail", "-c", fmt.Sprintf(` export PGHOST=%s - kando location pull --profile '%s' --path "%s" - | gunzip -c -f | psql -q -U "${PGUSER}" %s + kando location pull --profile "%s" --path "%s" - | gunzip -c -f | psql -q -U "${PGUSER}" %s `, "db-endpoint", "null", fmt.Sprintf("%s/%s", "/backup/postgres-backup", "backup-id"), postgres.DefaultConnectDatabase), }, }, @@ -106,7 +128,7 @@ func (s *RDSFunctionsTest) TestPrepareCommand(c *check.C) { for db in "${dblist[@]}"; do echo "backing up $db db" && pg_dump $db -C --inserts > /backup/$db.sql; done - tar -zc backup | kando location push --profile '%s' --path "${BACKUP_PREFIX}/${BACKUP_ID}" - + tar -zc backup | kando location push --profile "%s" --path "${BACKUP_PREFIX}/${BACKUP_ID}" - kando output %s ${BACKUP_ID}`, "db-endpoint", "/backup/postgres-backup", "backup-id", strings.Join([]string{"template1"}, " "), "null", ExportRDSSnapshotToLocBackupID), }, diff --git a/pkg/function/restore_rds_snapshot.go b/pkg/function/restore_rds_snapshot.go index df5dd16957..76f482bfdd 100644 --- a/pkg/function/restore_rds_snapshot.go +++ b/pkg/function/restore_rds_snapshot.go @@ -17,6 +17,7 @@ package function import ( "context" "fmt" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -335,6 +336,8 @@ func postgresRestoreCommand(pgHost, username, password string, backupArtifactPre replaceCommand = ` sed 's/"LOCALE"/"LC_COLLATE"/' |` } + profileQuoted := strconv.Quote(string(profile)) + return []string{ "bash", "-o", @@ -344,8 +347,8 @@ func postgresRestoreCommand(pgHost, username, password string, backupArtifactPre "-c", fmt.Sprintf(` export PGHOST=%s - kando location pull --profile '%s' --path "%s" - | gunzip -c -f |%s psql -q -U "${PGUSER}" %s - `, pgHost, profile, fmt.Sprintf("%s/%s", backupArtifactPrefix, backupID), replaceCommand, postgres.DefaultConnectDatabase), + kando location pull --profile %s --path "%s" - | gunzip -c -f |%s psql -q -U "${PGUSER}" %s + `, pgHost, profileQuoted, fmt.Sprintf("%s/%s", backupArtifactPrefix, backupID), replaceCommand, postgres.DefaultConnectDatabase), }, nil } From 6d144bbe4410c1d92e7a02919dbb86825128d4a0 Mon Sep 17 00:00:00 2001 From: Eugene Sumin <95425330+e-sumin@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:02:16 +0100 Subject: [PATCH 4/4] chore: Errkit migration 8.5 migrate multiple tests and validations to errkit. (#3258) Signed-off-by: Eugen Sumin Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../cr/v1alpha1/repositoryserver_types_test.go | 4 ++-- pkg/apis/cr/v1alpha1/types_test.go | 4 ++-- pkg/errorchecker/errorchecker_test.go | 7 +++---- pkg/log/fluentbit.go | 8 ++++---- pkg/log/log.go | 14 +++++++------- pkg/log/log_test.go | 6 +++--- pkg/metrics/metrics.go | 6 +++--- pkg/testing/e2e_test.go | 14 +++++++------- pkg/testing/integration_test.go | 7 ++++--- pkg/testutil/func.go | 4 ++-- pkg/testutil/mockblockstorage/mockblockstorage.go | 12 ++++++------ pkg/utils/utils.go | 10 +++++----- pkg/validate/error.go | 12 +++++------- pkg/validate/error_test.go | 12 ++++++------ pkg/validatingwebhook/repositoryserver_handler.go | 6 +++--- 15 files changed, 62 insertions(+), 64 deletions(-) diff --git a/pkg/apis/cr/v1alpha1/repositoryserver_types_test.go b/pkg/apis/cr/v1alpha1/repositoryserver_types_test.go index 0e051742f1..524d8328c5 100644 --- a/pkg/apis/cr/v1alpha1/repositoryserver_types_test.go +++ b/pkg/apis/cr/v1alpha1/repositoryserver_types_test.go @@ -17,7 +17,7 @@ package v1alpha1 import ( "testing" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -86,7 +86,7 @@ func getRepositoryServerFromSpec(spec []byte) (*RepositoryServer, error) { repositoryServer := &RepositoryServer{} d := serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer() if _, _, err := d.Decode([]byte(spec), nil, repositoryServer); err != nil { - return nil, errors.Wrap(err, "Failed to decode RepositoryServer") + return nil, errkit.Wrap(err, "Failed to decode RepositoryServer") } return repositoryServer, nil } diff --git a/pkg/apis/cr/v1alpha1/types_test.go b/pkg/apis/cr/v1alpha1/types_test.go index 6da1bc3d7d..6518183101 100644 --- a/pkg/apis/cr/v1alpha1/types_test.go +++ b/pkg/apis/cr/v1alpha1/types_test.go @@ -18,7 +18,7 @@ import ( "reflect" "testing" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -73,7 +73,7 @@ func getBlueprintFromSpec(spec []byte) (*Blueprint, error) { blueprint := &Blueprint{} d := serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer() if _, _, err := d.Decode([]byte(spec), nil, blueprint); err != nil { - return nil, errors.Wrap(err, "Failed to decode spec into object") + return nil, errkit.Wrap(err, "Failed to decode spec into object") } return blueprint, nil } diff --git a/pkg/errorchecker/errorchecker_test.go b/pkg/errorchecker/errorchecker_test.go index 3a12e5a5ef..f8466a3c14 100644 --- a/pkg/errorchecker/errorchecker_test.go +++ b/pkg/errorchecker/errorchecker_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/kanisterio/errkit" - "github.com/pkg/errors" "gopkg.in/check.v1" ) @@ -18,11 +17,11 @@ var _ = check.Suite(&ErrorsTestSuite{}) func (ts *ErrorsTestSuite) TestWrappingAndMatching(c *check.C) { errkitErr := errkit.New("Errkit error") errkitWrappedErr := errkit.Wrap(errkitErr, "errkit wrapped") - errorsWrappedErr := errors.Wrap(errkitWrappedErr, "errors wrapped") - errorsWrappedErr1 := errors.Wrap(errorsWrappedErr, "errors wrapped 1") + errorsWrappedErr := errkit.Wrap(errkitWrappedErr, "errors wrapped") + errorsWrappedErr1 := errkit.Wrap(errorsWrappedErr, "errors wrapped 1") // Ensure that errors from 'errkit' wrapped by the older 'errors' package remain matchable. - c.Assert(errors.Is(errorsWrappedErr, errkitErr), check.Equals, true) + c.Assert(errkit.Is(errorsWrappedErr, errkitErr), check.Equals, true) // Ensure that transformation to string still works c.Assert(errorsWrappedErr1.Error(), check.Equals, "errors wrapped 1: errors wrapped: errkit wrapped: Errkit error") // Ensure that error message matching does work as expected diff --git a/pkg/log/fluentbit.go b/pkg/log/fluentbit.go index 36a03397a3..2c2d11cf22 100644 --- a/pkg/log/fluentbit.go +++ b/pkg/log/fluentbit.go @@ -7,7 +7,7 @@ import ( "os" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/sirupsen/logrus" ) @@ -64,7 +64,7 @@ func NewFluentbitHook(endpoint string) *FluentbitHook { func dial(endpoint string) (net.Conn, error) { conn, err := net.DialTimeout("tcp", endpoint, defaultConnTimeout) if err != nil { - return nil, errors.Wrap(err, "Fluentbit connection problem") + return nil, errkit.Wrap(err, "Fluentbit connection problem") } return conn, nil } @@ -73,12 +73,12 @@ func dial(endpoint string) (net.Conn, error) { func handle(msgs []byte, endpoint string) error { conn, err := dial(endpoint) if err != nil { - return errors.Wrap(err, "Fluentbit connection error") + return errkit.Wrap(err, "Fluentbit connection error") } defer conn.Close() //nolint:errcheck _, err = conn.Write(msgs) if err != nil { - return errors.Wrap(err, "Fluentbit write error") + return errkit.Wrap(err, "Fluentbit write error") } return nil } diff --git a/pkg/log/log.go b/pkg/log/log.go index fcd1932cb0..a5363fbc16 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/sirupsen/logrus" "github.com/kanisterio/kanister/pkg/caller" @@ -34,9 +34,9 @@ const ( ) var ( - ErrEndpointNotSet = errors.New("fluentbit endpoint not set") - ErrNonTCPEndpoint = errors.New("fluentbit endpoint scheme must be tcp") - ErrPathSet = errors.New("fluentbit endpoint path is set") + ErrEndpointNotSet = errkit.NewSentinelErr("fluentbit endpoint not set") + ErrNonTCPEndpoint = errkit.NewSentinelErr("fluentbit endpoint scheme must be tcp") + ErrPathSet = errkit.NewSentinelErr("fluentbit endpoint path is set") ) // OutputSink describes the current output sink. @@ -72,17 +72,17 @@ func SetOutput(sink OutputSink) error { case FluentbitSink: fbitAddr, ok := os.LookupEnv(LoggingServiceHostEnv) if !ok { - return errors.New("Unable to find Fluentbit host address") + return errkit.New("Unable to find Fluentbit host address") } fbitPort, ok := os.LookupEnv(LoggingServicePortEnv) if !ok { - return errors.New("Unable to find Fluentbit logging port") + return errkit.New("Unable to find Fluentbit logging port") } hook := NewFluentbitHook(fbitAddr + ":" + fbitPort) log.AddHook(hook) return nil default: - return errors.New("not implemented") + return errkit.New("not implemented") } } diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index 838942d7eb..2cb20b1e76 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "net/url" "os" @@ -12,6 +11,7 @@ import ( "testing" "time" + "github.com/kanisterio/errkit" "github.com/sirupsen/logrus" "gopkg.in/check.v1" @@ -59,7 +59,7 @@ func (s *LogSuite) TestLogWithFields(c *check.C) { func (s *LogSuite) TestLogWithError(c *check.C) { const text = "My error message" - err := errors.New("test error") + err := errkit.New("test error") entry := testLogMessage(c, text, WithError(err).Print) c.Assert(entry["error"], check.Equals, err.Error()) c.Assert(entry["level"], check.Equals, infoLevelStr) @@ -88,7 +88,7 @@ func (s *LogSuite) TestLogWithContextFields(c *check.C) { func (s *LogSuite) TestLogWithContextFieldsAndError(c *check.C) { const text = "My error message" ctx := field.Context(context.Background(), "key", "value") - err := errors.New("test error") + err := errkit.New("test error") entry := testLogMessage(c, text, WithError(err).WithContext(ctx).Print) c.Assert(entry["level"], check.Equals, infoLevelStr) // Error should be included in the log entry diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 7831683a47..011d1debf3 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -15,9 +15,9 @@ package metrics import ( - "errors" "fmt" + "github.com/kanisterio/errkit" "github.com/prometheus/client_golang/prometheus" "gonum.org/v1/gonum/stat/combin" @@ -73,7 +73,7 @@ func getLabelCombinations(bl []BoundedLabel) ([]prometheus.Labels, error) { {"operation_type": "restore", "action_set_resolution": "failure"}] */ if !verifyBoundedLabels(bl) { - return nil, errors.New("invalid BoundedLabel list") + return nil, errkit.New("invalid BoundedLabel list") } labelLens := make([]int, len(bl)) for idx, l := range bl { @@ -241,7 +241,7 @@ func registerGauge(r prometheus.Registerer, g prometheus.Gauge) prometheus.Gauge func registerMetricOrDie(r prometheus.Registerer, c prometheus.Collector) prometheus.Collector { if err := r.Register(c); err != nil { are := prometheus.AlreadyRegisteredError{} - if !errors.As(err, &are) { + if !errkit.As(err, &are) { panic(fmt.Sprintf("failed to register metric. error: %v", err)) } // Use already registered metric diff --git a/pkg/testing/e2e_test.go b/pkg/testing/e2e_test.go index 17ef519cd3..3e3ffd41e0 100644 --- a/pkg/testing/e2e_test.go +++ b/pkg/testing/e2e_test.go @@ -23,7 +23,7 @@ import ( "log" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -166,7 +166,7 @@ func (s *E2ESuite) TestKubeExec(c *check.C) { case err != nil, as.Status == nil: return false, err case as.Status.State == crv1alpha1.StateFailed: - return true, errors.Errorf("Actionset failed: %#v", as.Status) + return true, errkit.New(fmt.Sprintf("Actionset failed: %#v", as.Status)) case as.Status.State == crv1alpha1.StateComplete: return true, nil } @@ -290,7 +290,7 @@ func (s *E2ESuite) TestKubeTask(c *check.C) { case err != nil, as.Status == nil: return false, err case as.Status.State == crv1alpha1.StateFailed: - return true, errors.Errorf("Actionset failed: %#v", as.Status) + return true, errkit.New(fmt.Sprintf("Actionset failed: %#v", as.Status)) case as.Status.State == crv1alpha1.StateComplete: return true, nil } @@ -524,7 +524,7 @@ func (s *E2ESuite) waitForActionSetComplete(asName string) error { case err != nil, as.Status == nil: return false, err case as.Status.State == crv1alpha1.StateFailed: - return true, errors.Errorf("Actionset failed: %#v", as.Status) + return true, errkit.New(fmt.Sprintf("Actionset failed: %#v", as.Status)) case as.Status.State == crv1alpha1.StateComplete: return true, nil } @@ -553,7 +553,7 @@ func (s *E2ESuite) waitForFunctionPodReady() error { } if len(pods.Items) > 1 { - return false, errors.New("more than one kanister-job pod found") + return false, errkit.New("more than one kanister-job pod found") } return true, nil @@ -564,7 +564,7 @@ func verifyAnnotationsInFunctionPod(funcPodAnnotations, expectedAnnotations map[ for k, v := range expectedAnnotations { val, ok := funcPodAnnotations[k] if !ok || v != val { - return errors.New(fmt.Sprintf("Either key %s, is not found in pod annotations or, its values (%s and %s) don't match", k, v, val)) + return errkit.New(fmt.Sprintf("Either key %s, is not found in pod annotations or, its values (%s and %s) don't match", k, v, val)) } } return nil @@ -574,7 +574,7 @@ func verifyLabelsInFunctionPod(funcPodLabels, expectedLabels map[string]string) for k, v := range expectedLabels { val, ok := funcPodLabels[k] if !ok || v != val { - return errors.New(fmt.Sprintf("Either key %s, is not found in pod labels or, its values (%s and %s) don't match", k, v, val)) + return errkit.New(fmt.Sprintf("Either key %s, is not found in pod labels or, its values (%s and %s) don't match", k, v, val)) } } return nil diff --git a/pkg/testing/integration_test.go b/pkg/testing/integration_test.go index 80bce4d248..baf3ca8fc7 100644 --- a/pkg/testing/integration_test.go +++ b/pkg/testing/integration_test.go @@ -18,12 +18,13 @@ package testing import ( - context "context" + "context" + "fmt" "os" test "testing" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -425,7 +426,7 @@ func (s *IntegrationSuite) createActionset(ctx context.Context, c *check.C, as * case err != nil, as.Status == nil: return false, err case as.Status.State == crv1alpha1.StateFailed: - return true, errors.Errorf("Actionset failed: %#v", as.Status) + return true, errkit.New(fmt.Sprintf("Actionset failed: %#v", as.Status)) case as.Status.State == crv1alpha1.StateComplete: return true, nil } diff --git a/pkg/testutil/func.go b/pkg/testutil/func.go index 8e5beabdf6..bb45370478 100644 --- a/pkg/testutil/func.go +++ b/pkg/testutil/func.go @@ -18,7 +18,7 @@ import ( "context" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kanister "github.com/kanisterio/kanister/pkg" @@ -48,7 +48,7 @@ var ( ) func failFunc(context.Context, param.TemplateParams, map[string]interface{}) (map[string]interface{}, error) { - err := errors.New("Kanister function failed") + err := errkit.New("Kanister function failed") failFuncCh <- err return nil, err } diff --git a/pkg/testutil/mockblockstorage/mockblockstorage.go b/pkg/testutil/mockblockstorage/mockblockstorage.go index d36e38e565..9275cf4a60 100644 --- a/pkg/testutil/mockblockstorage/mockblockstorage.go +++ b/pkg/testutil/mockblockstorage/mockblockstorage.go @@ -20,7 +20,7 @@ import ( "time" uuid "github.com/gofrs/uuid" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/kanisterio/kanister/pkg/blockstorage" "github.com/kanisterio/kanister/pkg/blockstorage/getter" @@ -57,7 +57,7 @@ func (*mockGetter) Get(storageType blockstorage.Type, config map[string]string) case blockstorage.TypeGPD: return Get(storageType) default: - return nil, errors.New("Get failed") + return nil, errkit.New("Get failed") } } @@ -65,7 +65,7 @@ func (*mockGetter) Get(storageType blockstorage.Type, config map[string]string) func Get(storageType blockstorage.Type) (*Provider, error) { volumeUUID, err := uuid.NewV1() if err != nil { - return nil, errors.Wrap(err, "Failed to create UUID") + return nil, errkit.Wrap(err, "Failed to create UUID") } volume := blockstorage.Volume{ Type: storageType, @@ -84,7 +84,7 @@ func Get(storageType blockstorage.Type) (*Provider, error) { snapVol := volume snapUUID, err := uuid.NewV1() if err != nil { - return nil, errors.Wrap(err, "Failed to create UUID") + return nil, errkit.Wrap(err, "Failed to create UUID") } snapshot := blockstorage.Snapshot{ Type: storageType, @@ -122,7 +122,7 @@ func (p *Provider) VolumeCreate(context.Context, blockstorage.Volume) (*blocksto func (p *Provider) VolumeCreateFromSnapshot(ctx context.Context, snapshot blockstorage.Snapshot, tags map[string]string) (*blockstorage.Volume, error) { volUUID, err := uuid.NewV1() if err != nil { - return nil, errors.Wrap(err, "Failed to create UUID") + return nil, errkit.Wrap(err, "Failed to create UUID") } vol := blockstorage.Volume{ Type: snapshot.Type, @@ -197,7 +197,7 @@ func (p *Provider) SetTags(ctx context.Context, resource interface{}, tags map[s case *blockstorage.Snapshot: return nil default: - return errors.Errorf("Unsupported resource type %v(%T)", res, res) + return errkit.New(fmt.Sprintf("Unsupported resource type %v(%T)", res, res)) } } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 55aff0c8dc..396472f324 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -23,7 +23,7 @@ import ( "strings" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -56,7 +56,7 @@ func PrintStage(description string, i indicator) { func GetNamespaceUID(ctx context.Context, cli kubernetes.Interface, namespace string) (string, error) { ns, err := cli.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{}) if err != nil { - return "", errors.Wrapf(err, "Failed to get namespace %s", namespace) + return "", errkit.Wrap(err, "Failed to get namespace", "namespace", namespace) } return string(ns.GetUID()), nil } @@ -85,7 +85,7 @@ func GetIntOrDefault(value string, defaultValue int) (int, error) { v, err := strconv.Atoi(value) if err != nil { v = defaultValue - return v, errors.New("conversion to integer failed, using default value for the field") + return v, errkit.New("conversion to integer failed, using default value for the field") } return v, nil } @@ -121,7 +121,7 @@ func RoundUpDuration(t time.Duration) time.Duration { func CheckRequiredArgs(reqArgs []string, args map[string]interface{}) error { for _, a := range reqArgs { if _, ok := args[a]; !ok { - return errors.Errorf("Required arg missing: %s", a) + return errkit.New(fmt.Sprintf("Required arg missing: %s", a)) } } return nil @@ -132,7 +132,7 @@ func CheckRequiredArgs(reqArgs []string, args map[string]interface{}) error { func CheckSupportedArgs(supportedArgs []string, args map[string]interface{}) error { for a := range args { if !slices.Contains(supportedArgs, a) { - return errors.Errorf("argument %s is not supported", a) + return errkit.New(fmt.Sprintf("argument %s is not supported", a)) } } return nil diff --git a/pkg/validate/error.go b/pkg/validate/error.go index 5011e94a25..50c4c591a4 100644 --- a/pkg/validate/error.go +++ b/pkg/validate/error.go @@ -15,18 +15,16 @@ package validate import ( - "fmt" - - "github.com/pkg/errors" + "github.com/kanisterio/errkit" ) -var errValidate = fmt.Errorf("Validation Failed") +var errValidate = errkit.NewSentinelErr("Validation Failed") func errorf(err error, format string, args ...interface{}) error { - return errors.Wrapf(err, format, args...) + return errkit.Wrap(err, format, args...) } -// IsError returns true iff the underlying cause was a validation error. +// IsError returns true if the underlying cause was a validation error. func IsError(err error) bool { - return errors.Cause(err) == errValidate + return errkit.Is(err, errValidate) } diff --git a/pkg/validate/error_test.go b/pkg/validate/error_test.go index 05b9cba995..cf86806870 100644 --- a/pkg/validate/error_test.go +++ b/pkg/validate/error_test.go @@ -17,7 +17,7 @@ package validate import ( "fmt" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" ) @@ -43,23 +43,23 @@ func (s *ErrorSuite) TestIsError(c *check.C) { is: true, }, { - err: errors.Wrap(nil, "test"), + err: errkit.Wrap(nil, "test"), is: false, }, { - err: errors.WithStack(nil), + err: errkit.WithStack(nil), is: false, }, { - err: errors.Wrap(errValidate, "test"), + err: errkit.Wrap(errValidate, "test"), is: true, }, { - err: errors.WithStack(errValidate), + err: errkit.WithStack(errValidate), is: true, }, { - err: errors.New("test"), + err: errkit.New("test"), is: false, }, } { diff --git a/pkg/validatingwebhook/repositoryserver_handler.go b/pkg/validatingwebhook/repositoryserver_handler.go index b3b9c3509e..b401050c99 100644 --- a/pkg/validatingwebhook/repositoryserver_handler.go +++ b/pkg/validatingwebhook/repositoryserver_handler.go @@ -18,7 +18,7 @@ import ( "context" "fmt" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" @@ -43,11 +43,11 @@ func (r *RepositoryServerValidator) ValidateUpdate(ctx context.Context, old runt oldrs, ook := old.(*crv1alpha1.RepositoryServer) newrs, nok := new.(*crv1alpha1.RepositoryServer) if !ook || !nok { - return nil, errors.New("Either updated object or the old object is not of type RepositoryServer.cr.kanister.io") + return nil, errkit.New("Either updated object or the old object is not of type RepositoryServer.cr.kanister.io") } errMsg := fmt.Sprintf("RepositoryServer.cr.kanister.io \"%s\" is invalid: spec.repository.rootPath: Invalid value, Value is immutable", newrs.Name) if oldrs.Spec.Repository.RootPath != newrs.Spec.Repository.RootPath { - return nil, errors.New(errMsg) + return nil, errkit.New(errMsg) } return nil, nil }