Skip to content

Commit

Permalink
Merge branch 'master' into errkit_migration_8_3_kube
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 29, 2024
2 parents 672e66d + 6d144bb commit 5d5d61b
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 81 deletions.
6 changes: 3 additions & 3 deletions docker/postgres-kanister-tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions docker/postgresql/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pkg/apis/cr/v1alpha1/repositoryserver_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/apis/cr/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/blockstorage/azure/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/blockstorage/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions pkg/errorchecker/errorchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/kanisterio/errkit"
"github.com/pkg/errors"
"gopkg.in/check.v1"
)

Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/function/export_rds_snapshot_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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",
Expand All @@ -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
}
Expand Down
28 changes: 25 additions & 3 deletions pkg/function/rds_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &param.Profile{},
},
},
{
name: "PostgreS restore command",
dbEngine: PostgrSQLEngine,
Expand All @@ -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),
},
},
Expand All @@ -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),
},
Expand Down
7 changes: 5 additions & 2 deletions pkg/function/restore_rds_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package function
import (
"context"
"fmt"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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",
Expand All @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/log/fluentbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"time"

"github.com/pkg/errors"
"github.com/kanisterio/errkit"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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")
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
"sync"
"testing"
"time"

"github.com/kanisterio/errkit"
"github.com/sirupsen/logrus"
"gopkg.in/check.v1"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/objectstore/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 5d5d61b

Please sign in to comment.