Change:
What happened: When creating a block volume, the iSCSI storage plugin stores volume-related data in different directories: As a result, some data is not cleaned up once the volume is detached: How to reproduce it (as minimally and precisely as possible): These are the objects I used to reproduce this issue: pod- /sig storage CC
/assign

Discussion:
Portals       []string Iqn           string Lun           string <ins> InitIface     string </ins> Iface         string chapDiscovery bool chapSession   bool

return nil, err } <ins> initIface := iface if initiatorName != "" { iface = bkportal[0] + ":" + spec.Name() } </ins> return &iscsiDisk{ podUID:        podUID, VolName:       spec.Name(), Portals:       bkportal, Iqn:           iqn, Lun:           lun, <ins> InitIface:     initIface, </ins> Iface:         iface, chapDiscovery: chapDiscovery, chapSession:   chapSession,

var iscsiTransport string var lastErr error <del> out, err := b.exec.Run("iscsiadm", "-m", "iface", "-I", b.Iface, "-o", "show") </del> <ins> out, err := b.exec.Run("iscsiadm", "-m", "iface", "-I", b.InitIface, "-o", "show") </ins> if err != nil { <del> klog.Errorf("iscsi: could not read iface %s error: %s", b.Iface, string(out)) </del> <ins> klog.Errorf("iscsi: could not read iface %s error: %s", b.InitIface, string(out)) </ins> return "", err }

bkpPortal := b.Portals <del> // create new iface and copy parameters from pre-configured iface to the created iface </del> <ins> // If the initiator name was set, the iface isn't created yet, // so create it and copy parameters from the pre-configured one </ins> if b.InitiatorName != "" { <del> // new iface name is <target portal>:<volume name> newIface := bkpPortal[0] + ":" + b.VolName err = cloneIface(b, newIface) if err != nil { klog.Errorf("iscsi: failed to clone iface: %s error: %v", b.Iface, err) </del> <ins> if err = cloneIface(b); err != nil { klog.Errorf("iscsi: failed to clone iface: %s error: %v", b.InitIface, err) </ins> return "", err } <del> // update iface name b.Iface = newIface </del> } // Lock the target while we login to avoid races between 2 volumes that share the same

return params, nil } <del> func cloneIface(b iscsiDiskMounter, newIface string) error { </del> <ins> func cloneIface(b iscsiDiskMounter) error { </ins> var lastErr error <ins> if b.InitIface == b.Iface { return fmt.Errorf("iscsi: cannot clone iface with same name: %s", b.InitIface) } </ins> // get pre-configured iface records <del> out, err := b.exec.Run("iscsiadm", "-m", "iface", "-I", b.Iface, "-o", "show") </del> <ins> out, err := b.exec.Run("iscsiadm", "-m", "iface", "-I", b.InitIface, "-o", "show") </ins> if err != nil { lastErr = fmt.Errorf("iscsi: failed to show iface records: %s (%v)", string(out), err) return lastErr

// update initiatorname params["iface.initiatorname"] = b.InitiatorName // create new iface <del> out, err = b.exec.Run("iscsiadm", "-m", "iface", "-I", newIface, "-o", "new") </del> <ins> out, err = b.exec.Run("iscsiadm", "-m", "iface", "-I", b.Iface, "-o", "new") </ins> if err != nil { exit, ok := err.(utilexec.ExitError) if ok && exit.ExitStatus() == iscsiadmErrorSessExists { <del> klog.Infof("iscsi: there is a session already logged in with iface %s", newIface) </del> <ins> klog.Infof("iscsi: there is a session already logged in with iface %s", b.Iface) </ins> } else { lastErr = fmt.Errorf("iscsi: failed to create new iface: %s (%v)", string(out), err) return lastErr

} // update new iface records for key, val := range params { <del> _, err = b.exec.Run("iscsiadm", "-m", "iface", "-I", newIface, "-o", "update", "-n", key, "-v", val) </del> <ins> _, err = b.exec.Run("iscsiadm", "-m", "iface", "-I", b.Iface, "-o", "update", "-n", key, "-v", val) </ins> if err != nil { <del> b.exec.Run("iscsiadm", "-m", "iface", "-I", newIface, "-o", "delete") lastErr = fmt.Errorf("iscsi: failed to update iface records: %s (%v). iface(%s) will be used", string(out), err, b.Iface) </del> <ins> b.exec.Run("iscsiadm", "-m", "iface", "-I", b.Iface, "-o", "delete") lastErr = fmt.Errorf("iscsi: failed to update iface records: %s (%v). iface(%s) will be used", string(out), err, b.InitIface) </ins> break } }

plugin := plugins[0] fakeMounter := iscsiDiskMounter{ iscsiDisk: &iscsiDisk{ <ins> Iface:  "192.168.1.10:pv0001", </ins> plugin: plugin.(*iscsiPlugin)}, exec: fakeExec, } <del> newIface := "192.168.1.10:pv0001" cloneIface(fakeMounter, newIface) </del> <ins> cloneIface(fakeMounter) </ins> if cmdCount != 4 { t.Errorf("expected 4 CombinedOutput() calls, got %d", cmdCount) }

plugin := plugins[0] fakeMounter := iscsiDiskMounter{ iscsiDisk: &iscsiDisk{ <ins> Iface:  "192.168.1.10:pv0001", </ins> plugin: plugin.(*iscsiPlugin)}, exec: fakeExec, } <del> newIface := "192.168.1.10:pv0001" cloneIface(fakeMounter, newIface) </del> <ins> cloneIface(fakeMounter) </ins> if cmdCount != 1 { t.Errorf("expected 1 CombinedOutput() calls, got %d", cmdCount) }

plugin := plugins[0] fakeMounter := iscsiDiskMounter{ iscsiDisk: &iscsiDisk{ <ins> Iface:  "192.168.1.10:pv0001", </ins> plugin: plugin.(*iscsiPlugin)}, exec: fakeExec, } <del> newIface := "192.168.1.10:pv0001" cloneIface(fakeMounter, newIface) </del> <ins> cloneIface(fakeMounter) </ins> if cmdCount != 5 { t.Errorf("expected 5 CombinedOutput() calls, got %d", cmdCount) }