Skip to content

Commit

Permalink
medatada: make namespaces' deletion error less cryptic
Browse files Browse the repository at this point in the history
The error message was unnecessary cryptic. `snapshot-[name]` notation
was only used here and hard to understand.

Instead it should say `snapshots on "..." snapshotter`.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed Dec 13, 2021
1 parent 6e9e759 commit 44b28b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion metadata/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package metadata

import (
"context"
"fmt"
"strings"

"github.com/containerd/containerd/errdefs"
Expand Down Expand Up @@ -184,7 +185,7 @@ func (s *namespaceStore) listNs(namespace string) ([]string, error) {
if err := snbkt.ForEach(func(k, v []byte) error {
if v == nil {
if !isBucketEmpty(snbkt.Bucket(k)) {
out = append(out, "snapshot-"+string(k))
out = append(out, fmt.Sprintf("snapshots on %q snapshotter", k))
}
}
return nil
Expand Down
14 changes: 13 additions & 1 deletion metadata/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,22 @@ func TestCreateDelete(t *testing.T) {
Spec: &types.Any{},
})
require.NoError(t, err)

db.Update(func(tx *bbolt.Tx) error {
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return err
}
bucket, err := createSnapshotterBucket(tx, ns, "testss")
if err != nil {
return err
}
return bucket.Put([]byte("key"), []byte("value"))
})
},
validate: func(t *testing.T, err error) {
require.Error(t, err)
assert.Contains(t, err.Error(), "still has containers")
assert.Contains(t, err.Error(), `still has containers, snapshots on "testss" snapshotter`)
},
},
}
Expand Down

0 comments on commit 44b28b6

Please sign in to comment.