From 44b28b61ffa450d8e5956409f9a5386cff0fdd49 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Wed, 8 Dec 2021 10:00:59 -0800 Subject: [PATCH] medatada: make namespaces' deletion error less cryptic 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 --- metadata/namespaces.go | 3 ++- metadata/namespaces_test.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/metadata/namespaces.go b/metadata/namespaces.go index 165c09fca..540fb8359 100644 --- a/metadata/namespaces.go +++ b/metadata/namespaces.go @@ -18,6 +18,7 @@ package metadata import ( "context" + "fmt" "strings" "github.com/containerd/containerd/errdefs" @@ -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 diff --git a/metadata/namespaces_test.go b/metadata/namespaces_test.go index f434ddf1c..31c1bd81f 100644 --- a/metadata/namespaces_test.go +++ b/metadata/namespaces_test.go @@ -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`) }, }, }