diff --git a/pkg/daemon/ceph/client/image.go b/pkg/daemon/ceph/client/image.go index 3a34c0da0..0b094acb3 100644 --- a/pkg/daemon/ceph/client/image.go +++ b/pkg/daemon/ceph/client/image.go @@ -18,13 +18,14 @@ package client import ( "encoding/json" "fmt" - "strings" + "syscall" "strconv" "regexp" "github.com/rook/rook/pkg/clusterd" + "github.com/rook/rook/pkg/util/exec" ) const ( @@ -85,9 +86,15 @@ func CreateImage(context *clusterd.Context, clusterName, name, poolName, dataPoo } buf, err := ExecuteRBDCommandNoFormat(context, clusterName, args) - if err != nil && !strings.Contains(string(buf), fmt.Sprintf("%s already exists", name)) { - return nil, fmt.Errorf("failed to create image %s in pool %s of size %d: %+v. output: %s", - name, poolName, size, err, string(buf)) + if err != nil { + cmdErr, ok := err.(*exec.CommandError) + if ok && cmdErr.ExitStatus() == int(syscall.EEXIST) { + // Image with the same name already exists in the given rbd pool. Continuing with the link to PV. + logger.Warningf("Requested image %s exists in pool %s. Continuing", name, poolName) + } else { + return nil, fmt.Errorf("failed to create image %s in pool %s of size %d: %+v. output: %s", + name, poolName, size, err, string(buf)) + } } // now that the image is created, retrieve it