From f05c8ed2a70d50a9efe3da3cbd8d0f31b9bf8725 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 6 Jul 2020 11:59:58 +0530 Subject: [PATCH] journal: remove unused rados CLI functions Removed unused rados CLI functions, as rados CLI is replaced with go-ceph bindings. Signed-off-by: Madhu Rajanna --- internal/journal/voljournal.go | 9 --- internal/util/cephcmds.go | 117 --------------------------------- 2 files changed, 126 deletions(-) diff --git a/internal/journal/voljournal.go b/internal/journal/voljournal.go index a6be14e97..302777c16 100644 --- a/internal/journal/voljournal.go +++ b/internal/journal/voljournal.go @@ -675,15 +675,6 @@ func (conn *Connection) StoreImageID(ctx context.Context, pool, reservedUUID, im return nil } -// GetStoredImageID retrives the stored image ID from the omap -func (conn *Connection) GetStoredImageID(ctx context.Context, pool, reservedUUID string, cr *util.Credentials) (string, error) { - imageID, err := util.GetOMapValue(ctx, conn.monitors, cr, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, conn.config.csiImageIDKey) - if err != nil { - return "", err - } - return imageID, nil -} - // Destroy frees any resources and invalidates the journal connection. func (conn *Connection) Destroy() { // invalidate cluster connection metadata diff --git a/internal/util/cephcmds.go b/internal/util/cephcmds.go index e5075b6e0..562d869a5 100644 --- a/internal/util/cephcmds.go +++ b/internal/util/cephcmds.go @@ -21,10 +21,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" - "os" "os/exec" - "strings" "github.com/ceph/go-ceph/rados" "k8s.io/klog" @@ -108,120 +105,6 @@ func GetPoolIDs(ctx context.Context, monitors, journalPool, imagePool string, cr return journalPoolID, imagePoolID, nil } -// SetOMapKeyValue sets the given key and value into the provided Ceph omap name -func SetOMapKeyValue(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey, keyValue string) error { - // Command: "rados setomapval oMapName oMapKey keyValue" - args := []string{ - "-m", monitors, - "--id", cr.ID, - "--keyfile=" + cr.KeyFile, - "-c", CephConfigPath, - "-p", poolName, - "setomapval", oMapName, oMapKey, keyValue, - } - - if namespace != "" { - args = append(args, "--namespace="+namespace) - } - - _, _, err := ExecCommand("rados", args[:]...) - if err != nil { - klog.Errorf(Log(ctx, "failed adding key (%s with value %s), to omap (%s) in "+ - "pool (%s): (%v)"), oMapKey, keyValue, oMapName, poolName, err) - return err - } - - return nil -} - -// GetOMapValue gets the value for the given key from the named omap -func GetOMapValue(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey string) (string, error) { - // Command: "rados getomapval oMapName oMapKey " - // No such key: replicapool/csi.volumes.directory.default/csi.volname - tmpFile, err := ioutil.TempFile("", "omap-get-") - if err != nil { - klog.Errorf(Log(ctx, "failed creating a temporary file for key contents")) - return "", err - } - defer func() { - ce := tmpFile.Close() - if ce != nil { - klog.Warningf(Log(ctx, "failed closing temporary file: %s"), ce) - } - }() - defer os.Remove(tmpFile.Name()) - - args := []string{ - "-m", monitors, - "--id", cr.ID, - "--keyfile=" + cr.KeyFile, - "-c", CephConfigPath, - "-p", poolName, - "getomapval", oMapName, oMapKey, tmpFile.Name(), - } - - if namespace != "" { - args = append(args, "--namespace="+namespace) - } - - stdout, stderr, err := ExecCommand("rados", args[:]...) - if err != nil { - // no logs, as attempting to check for non-existent key/value is done even on - // regular call sequences - stdoutanderr := strings.Join([]string{string(stdout), string(stderr)}, " ") - if strings.Contains(stdoutanderr, "No such key: "+poolName+"/"+oMapName+"/"+oMapKey) { - return "", ErrKeyNotFound{poolName + "/" + oMapName + "/" + oMapKey, err} - } - - if strings.Contains(stdoutanderr, "error getting omap value "+ - poolName+"/"+oMapName+"/"+oMapKey+": (2) No such file or directory") { - return "", ErrKeyNotFound{poolName + "/" + oMapName + "/" + oMapKey, err} - } - - if strings.Contains(stdoutanderr, "error opening pool "+ - poolName+": (2) No such file or directory") { - return "", ErrPoolNotFound{poolName, err} - } - - // log other errors for troubleshooting assistance - klog.Errorf(Log(ctx, "failed getting omap value for key (%s) from omap (%s) in pool (%s): (%v)"), - oMapKey, oMapName, poolName, err) - - return "", fmt.Errorf("error (%v) occurred, command output streams is (%s)", - err.Error(), stdoutanderr) - } - - keyValue, err := ioutil.ReadAll(tmpFile) - return string(keyValue), err -} - -// RemoveOMapKey removes the omap key from the given omap name -func RemoveOMapKey(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName, oMapKey string) error { - // Command: "rados rmomapkey oMapName oMapKey" - args := []string{ - "-m", monitors, - "--id", cr.ID, - "--keyfile=" + cr.KeyFile, - "-c", CephConfigPath, - "-p", poolName, - "rmomapkey", oMapName, oMapKey, - } - - if namespace != "" { - args = append(args, "--namespace="+namespace) - } - - _, _, err := ExecCommand("rados", args[:]...) - if err != nil { - // NOTE: Missing omap key removal does not return an error - klog.Errorf(Log(ctx, "failed removing key (%s), from omap (%s) in "+ - "pool (%s): (%v)"), oMapKey, oMapName, poolName, err) - return err - } - - return nil -} - // 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 {