Skip to content

Commit

Permalink
Merge branch 'master' into errkit_migration_8_1_controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 29, 2024
2 parents 7084cf4 + eb54bea commit 1b70420
Show file tree
Hide file tree
Showing 31 changed files with 157 additions and 117 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
6 changes: 3 additions & 3 deletions pkg/kube/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package kube
import (
"bytes"
"context"
"errors"
"strings"
"time"

"github.com/kanisterio/errkit"
"gopkg.in/check.v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (s *ExecSuite) TestErrorInExecWithOptions(c *check.C) {
c.Assert(err1, check.Not(check.IsNil))

var ee1 *ExecError
ok := errors.As(err1, &ee1)
ok := errkit.As(err1, &ee1)
c.Assert(ok, check.Equals, true)
c.Assert(ee1.Stdout(), check.Not(check.Equals), testCase.expectedOut)
c.Assert(ee1.Stderr(), check.Not(check.Equals), testCase.expectedErr)
Expand All @@ -208,7 +208,7 @@ func (s *ExecSuite) TestErrorInExecWithOptions(c *check.C) {
c.Assert(err2, check.Not(check.IsNil))

var ee2 *ExecError
ok = errors.As(err2, &ee2)
ok = errkit.As(err2, &ee2)
c.Assert(ok, check.Equals, true)

// When error happens, stdout/stderr buffers should contain all lines produced by an app
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/log_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package kube
import (
"bytes"
"context"
"errors"
"io"

"github.com/kanisterio/errkit"
"gopkg.in/check.v1"
"k8s.io/client-go/rest"
)
Expand Down Expand Up @@ -39,7 +39,7 @@ func (frw *fakeResponseWrapper) Stream(context.Context) (io.ReadCloser, error) {
}

func (s *LogReaderSuite) TestLogReader(c *check.C) {
err := errors.New("TEST")
err := errkit.New("TEST")
for _, tc := range []struct {
rw *fakeResponseWrapper
err error
Expand Down
5 changes: 2 additions & 3 deletions pkg/kube/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/gofrs/uuid"
json "github.com/json-iterator/go"
"github.com/kanisterio/errkit"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -451,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
}
Expand All @@ -470,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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kube/pod_command_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package kube
import (
"bytes"
"context"
"errors"
"os"
"sync"
"time"

"github.com/kanisterio/errkit"
"gopkg.in/check.v1"
"k8s.io/client-go/kubernetes/fake"
)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *PodCommandExecutorTestSuite) TestPodRunnerExec(c *check.C) {
prp.execWithOptionsSyncEnd.Sync()

c.Assert(err, check.Not(check.IsNil))
c.Assert(errors.Is(err, context.DeadlineExceeded), check.Equals, true)
c.Assert(errkit.Is(err, context.DeadlineExceeded), check.Equals, true)
},
"Cancelled": func(ctx context.Context, pr PodCommandExecutor, prp *fakePodCommandExecutorProcessor) {
var err error
Expand All @@ -151,7 +151,7 @@ func (s *PodCommandExecutorTestSuite) TestPodRunnerExec(c *check.C) {
prp.execWithOptionsSyncEnd.Sync() // Release ExecWithOptions

c.Assert(err, check.Not(check.IsNil))
c.Assert(errors.Is(err, context.Canceled), check.Equals, true)
c.Assert(errkit.Is(err, context.Canceled), check.Equals, true)
},
"Successful execution": func(ctx context.Context, pr PodCommandExecutor, prp *fakePodCommandExecutorProcessor) {
var err error
Expand Down
Loading

0 comments on commit 1b70420

Please sign in to comment.