diff --git a/internal/util/cephcmds.go b/internal/util/cephcmds.go index 0e9790994..7d921df0d 100644 --- a/internal/util/cephcmds.go +++ b/internal/util/cephcmds.go @@ -219,27 +219,31 @@ func RemoveOMapKey(ctx context.Context, monitors string, cr *Credentials, poolNa // CreateObject creates the object name passed in and returns ErrObjectExists if the provided object // is already present in rados func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, objectName string) error { - // Command: "rados create objectName" - args := []string{ - "-m", monitors, - "--id", cr.ID, - "--keyfile=" + cr.KeyFile, - "-c", CephConfigPath, - "-p", poolName, - "create", objectName, + conn := ClusterConnection{} + err := conn.Connect(monitors, cr) + if err != nil { + return err } + defer conn.Destroy() + + ioctx, err := conn.GetIoctx(poolName) + if err != nil { + if _, ok := err.(ErrPoolNotFound); ok { + err = ErrObjectNotFound{poolName, err} + } + return err + } + defer ioctx.Destroy() if namespace != "" { - args = append(args, "--namespace="+namespace) + ioctx.SetNamespace(namespace) } - _, stderr, err := ExecCommand("rados", args[:]...) - if err != nil { + err = ioctx.Create(objectName, rados.CreateExclusive) + if err == rados.ErrObjectExists { + return ErrObjectExists{objectName, err} + } else if err != nil { klog.Errorf(Log(ctx, "failed creating omap (%s) in pool (%s): (%v)"), objectName, poolName, err) - if strings.Contains(string(stderr), "error creating "+poolName+"/"+objectName+ - ": (17) File exists") { - return ErrObjectExists{objectName, err} - } return err }