Skip to content

Commit 5c802c4

Browse files
authored
Merge pull request kubernetes-csi#29 from enix/fix/disconnect-volume
Fix/disconnect volume
2 parents fd47a25 + b0ce999 commit 5c802c4

File tree

10 files changed

+1515
-517
lines changed

10 files changed

+1515
-517
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all build clean install
1+
.PHONY: all build clean install test coverage
22

33
all: clean build install
44

@@ -16,3 +16,6 @@ install:
1616
test:
1717
go test ./iscsi/
1818

19+
coverage:
20+
go test ./iscsi -coverprofile=coverage.out
21+
go tool cover -html=coverage.out

example/main.go

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,29 @@ import (
1111
)
1212

1313
var (
14-
portals = flag.String("portals", "192.168.1.112:3260", "Comma delimited. Eg: 1.1.1.1,2.2.2.2")
15-
iqn = flag.String("iqn", "iqn.2010-10.org.openstack:volume-95739000-1557-44f8-9f40-e9d29fe6ec47", "")
16-
multipath = flag.Bool("multipath", false, "")
17-
username = flag.String("username", "3aX7EEf3CEgvESQG75qh", "")
18-
password = flag.String("password", "eJBDC7Bt7WE3XFDq", "")
19-
lun = flag.Int("lun", 1, "")
20-
debug = flag.Bool("debug", false, "enable logging")
14+
portals = flag.String("portals", "192.168.1.112:3260", "Comma delimited. Eg: 1.1.1.1,2.2.2.2")
15+
iqn = flag.String("iqn", "iqn.2010-10.org.openstack:volume-95739000-1557-44f8-9f40-e9d29fe6ec47", "")
16+
username = flag.String("username", "3aX7EEf3CEgvESQG75qh", "")
17+
password = flag.String("password", "eJBDC7Bt7WE3XFDq", "")
18+
lun = flag.Int("lun", 1, "")
19+
debug = flag.Bool("debug", false, "enable logging")
2120
)
2221

2322
func main() {
2423
flag.Parse()
25-
tgtp := strings.Split(*portals, ",")
24+
tgtps := strings.Split(*portals, ",")
2625
if *debug {
2726
iscsi.EnableDebugLogging(os.Stdout)
2827
}
2928

3029
// You can utilize the iscsiadm calls directly if you wish, but by creating a Connector
3130
// you can simplify interactions to simple calls like "Connect" and "Disconnect"
32-
c := iscsi.Connector{
31+
c := &iscsi.Connector{
3332
// Our example uses chap
3433
AuthType: "chap",
35-
// Specify the target iqn we're dealing with
36-
TargetIqn: *iqn,
37-
// List of portals must be >= 1 (>1 signals multipath/mpio)
38-
TargetPortals: tgtp,
34+
// List of targets must be >= 1 (>1 signals multipath/mpio)
35+
TargetIqn: *iqn,
36+
TargetPortals: tgtps,
3937
// CHAP can be setup up for discovery as well as sessions, our example
4038
// device only uses CHAP security for sessions, for those that use Discovery
4139
// as well, we'd add a DiscoverySecrets entry the same way
@@ -45,8 +43,6 @@ func main() {
4543
SecretsType: "chap"},
4644
// Lun is the lun number the devices uses for exports
4745
Lun: int32(*lun),
48-
// Multipath indicates that we want to configure this connection as a multipath device
49-
Multipath: *multipath,
5046
// Number of times we check for device path, waiting for CheckInterval seconds inbetween each check (defaults to 10 if omitted)
5147
RetryCount: 11,
5248
// CheckInterval is the time in seconds to wait inbetween device path checks when logging in to a target
@@ -55,21 +51,21 @@ func main() {
5551

5652
// Now we can just issue a connection request using our Connector
5753
// A succesful connection will include the device path to access our iscsi volume
58-
path, err := iscsi.Connect(c)
54+
path, err := c.Connect()
5955
if err != nil {
60-
log.Printf("Error returned from iscsi.Connect: %s", err.Error())
61-
os.Exit(1)
62-
}
63-
64-
if path == "" {
65-
log.Printf("Failed to connect, didn't receive a path, but also no error!")
56+
log.Printf("Error returned from c.Connect: %s", err.Error())
6657
os.Exit(1)
6758
}
6859

6960
log.Printf("Connected device at path: %s\n", path)
7061
time.Sleep(3 * time.Second)
7162

72-
// Disconnect is easy as well, we don't need the full Connector any more, just the Target IQN and the Portals
73-
/// this should disconnect the volume as well as clear out the iscsi DB entries associated with it
74-
iscsi.Disconnect(c.TargetIqn, c.TargetPortals)
63+
// This will disconnect the volume
64+
if err := c.DisconnectVolume(); err != nil {
65+
log.Printf("Error returned from c.DisconnectVolume: %s", err.Error())
66+
os.Exit(1)
67+
}
68+
69+
// This will disconnect the session as well as clear out the iscsi DB entries associated with it
70+
c.Disconnect()
7571
}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/kubernetes-csi/csi-lib-iscsi
2+
3+
go 1.15
4+
5+
require (
6+
github.com/prashantv/gostub v1.0.0
7+
github.com/stretchr/testify v1.7.0
8+
)

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/prashantv/gostub v1.0.0 h1:wTzvgO04xSS3gHuz6Vhuo0/kvWelyJxwNS0IRBPAwGY=
6+
github.com/prashantv/gostub v1.0.0/go.mod h1:dP1v6T1QzyGJJKFocwAU0lSZKpfjstjH8TlhkEU0on0=
7+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
9+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
11+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
13+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)