daemon/graphdriver/zfs: ignore non-existent dataset on removal#48520
daemon/graphdriver/zfs: ignore non-existent dataset on removal#48520thaJeztah merged 1 commit intomoby:masterfrom
Conversation
ffaaae8 to
2189e47
Compare
daemon/graphdriver/zfs/zfs.go
Outdated
| name := d.zfsPath(id) | ||
| dataset := zfs.Dataset{Name: name} | ||
| err := dataset.Destroy(zfs.DestroyRecursive) | ||
| if err != nil && strings.Contains(fmt.Sprint(err), "dataset does not exist") { |
There was a problem hiding this comment.
you may probably do a stricter check.
errZfs, ok := err.(zfs.Error)
if ok && errZfs.Stderr == "dataset does not exist" {
...
}or go with err.Error() instead of fmt.Sprint(err), see https://pkg.go.dev/[email protected]#error
Happy Go hacking mate!
There was a problem hiding this comment.
Done. Unfortunately, the stderr field contains the whole output of the zfs command
Stderr: "cannot open 'rpool/zzztest/doesnotexist': dataset does not exist\n",
daemon/graphdriver/zfs/zfs.go
Outdated
| errZfs, isZfsError := err.(*zfs.Error) | ||
| if isZfsError && strings.HasSuffix(errZfs.Stderr, "dataset does not exist\n") { | ||
| logger := log.G(context.TODO()).WithField("storage-driver", "zfs") | ||
| logger.Warnf("Tried to destroy inexistant dataset %s", name) |
There was a problem hiding this comment.
| logger.Warnf("Tried to destroy inexistant dataset %s", name) | |
| logger.WithError(err).Warnf("Tried to destroy inexistant dataset %q", name) |
b402bed to
12431a9
Compare
12431a9 to
446d648
Compare
446d648 to
543aa2e
Compare
| var errZfs *zfs.Error | ||
| isZfsError := errors.As(err, &errZfs) |
There was a problem hiding this comment.
Did a quick rebase, and changed this to use errors.As;
diff --git a/daemon/graphdriver/zfs/zfs.go b/daemon/graphdriver/zfs/zfs.go
index bd96463d60..63301629af 100644
--- a/daemon/graphdriver/zfs/zfs.go
+++ b/daemon/graphdriver/zfs/zfs.go
@@ -4,6 +4,7 @@ package zfs // import "github.com/docker/docker/daemon/graphdriver/zfs"
import (
"context"
+ "errors"
"fmt"
"os"
"os/exec"
@@ -362,7 +363,8 @@ func (d *Driver) Remove(id string) error {
dataset := zfs.Dataset{Name: name}
err := dataset.Destroy(zfs.DestroyRecursive)
if err != nil {
- errZfs, isZfsError := err.(*zfs.Error)
+ var errZfs *zfs.Error
+ isZfsError := errors.As(err, &errZfs)
if isZfsError && strings.HasSuffix(errZfs.Stderr, "dataset does not exist\n") {
logger := log.G(context.TODO()).WithField("storage-driver", "zfs")
logger.WithError(err).Warnf("Tried to destroy inexistant dataset %q", name)
daemon/graphdriver/zfs/zfs.go
Outdated
| logger := log.G(context.TODO()).WithField("storage-driver", "zfs") | ||
| logger.WithError(err).Warnf("Tried to destroy inexistant dataset %q", name) |
There was a problem hiding this comment.
Actually; let me change this to WithFields instead of chaining WithField and WithError
543aa2e to
e3fae0c
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM
I'll ask for a second review as I made the last changes now 🙈 😂
|
oh! I messed up an import, probably my IDE tried to be helpful; |
e3fae0c to
2a9dc0d
Compare
|
Should be good now 😅 🤞 |
daemon/graphdriver/zfs/zfs.go
Outdated
| if err != nil { | ||
| var errZfs *zfs.Error | ||
| isZfsError := errors.As(err, &errZfs) | ||
| if isZfsError && strings.HasSuffix(errZfs.Stderr, "dataset does not exist\n") { |
There was a problem hiding this comment.
I'm slightly on the fence if we should consider stripping the newline from Stderr. Perhaps we should; I just had a quick peek at the zfs code and it already does some manipulation of the output it got, so it may be a bit brittle if we depend on the newline to be present.
Let me add a quick strings.TrimSpace here to prevent formatting changes from breaking this.
Ignore "dataset does not exist" error in Remove function Signed-off-by: François Scala <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
2a9dc0d to
e7d15d4
Compare
Fixes #43080
- What I did
I updated the Remove function to ignore the "dataset does not exist" error
- How I did it
Doing a strings.Contains of "dataset does not exist" in err
- How to verify it
- Description for the changelog
Ignores "dataset does not exist" error when removing dataset on ZFS (#43080)