Skip to content

Commit 7c37467

Browse files
authored
Merge pull request #1 from j-griffith/initial_code_add
Initial commit
2 parents 491ed59 + e0c1e04 commit 7c37467

File tree

7 files changed

+891
-11
lines changed

7 files changed

+891
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.out
2+
_output
3+
example/example

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.PHONY: all build clean install
2+
3+
all: clean build install
4+
5+
clean:
6+
go clean -r -x
7+
-rm -rf _output
8+
9+
build:
10+
go build ./iscsi/
11+
go build -o _output/example ./example/main.go
12+
13+
install:
14+
go install ./iscsi/
15+

README.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1-
# Kubernetes Template Project
1+
# csi lib-iscsi
22

3-
The Kubernetes Template Project is a template for starting new projects in the GitHub organizations owned by Kubernetes. All Kubernetes projects, at minimum, must have the following files:
3+
A simple go package intended to assist CSI plugin authors by providing a tool set to manage iscsi connections.
44

5-
- a `README.md` outlining the project goals, sponsoring sig, and community contact information
6-
- an `OWNERS` with the project leads listed as approvers ([docs on `OWNERS` files][owners])
7-
- a `CONTRIBUTING.md` outlining how to contribute to the project
8-
- an unmodified copy of `code-of-conduct.md` from this repo, which outlines community behavior and the consequences of breaking the code
9-
- a `LICENSE` which must be Apache 2.0 for code projects, or [Creative Commons 4.0] for documentation repositories, without any custom content
10-
- a `SECURITY_CONTACTS` with the contact points for the Product Security Team
11-
to reach out to for triaging and handling of incoming issues. They must agree to abide by the
12-
[Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy)
13-
and will be removed and replaced if they violate that agreement.
5+
## Goals
6+
7+
Provide a basic, lightweight library for CSI Plugin Authors to leverage some of the common tasks like connecting
8+
and disconnecting iscsi devices to a node. This library includes a high level abstraction for iscsi that exposes
9+
simple Connect and Disconnect functions. These are built on top of exported iscsiadm calls, so if you need more
10+
control you can access the iscsiadm calls directly.
11+
12+
## Design Philosophy
13+
14+
The idea is to keep this as lightweight and generic as possible. We intentionally avoid the use of any third party
15+
libraries or packages in this project. We don't have a vendor directory, because we attempt to rely only on the std
16+
golang libs. This may prove to not be ideal, and may be changed over time, but initially it's a worthwhile goal.
17+
18+
## Logging and Debug
19+
20+
By default the library does not provide any logging, but provides an error message that includes any messages from
21+
iscsiadm as well as exit-codes. In the event that you need to debug the library, we provide a function:
22+
23+
```
24+
func EnableDebugLogging(writer io.Writer)
25+
```
26+
27+
This will turn on verbose logging directed to the provided io.Writer and include the response of every iscsiadm command
28+
issued.
29+
30+
## Intended Usage
31+
32+
Curently the intended usage of this library is simply to provide a golang package to standardize how plugins are implementing
33+
iscsi connect and disconnect. It's not intended to be a "service", although that's a possible next step. It's currenty been
34+
used for plugins where iscsid is installed in containers only, as well as designs where it uses the nodes iscsid. Each of these
35+
approaches has their own pros and cons. Currently, it's up to the plugin author to determine which model suits them best
36+
and to deploy their node plugin appropriately.
1437

1538
## Community, discussion, contribution, and support
1639

@@ -19,6 +42,7 @@ Learn how to engage with the Kubernetes community on the [community page](http:/
1942
You can reach the maintainers of this project at:
2043

2144
- [Slack](http://slack.k8s.io/)
45+
* sig-storage
2246
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-dev)
2347

2448
### Code of conduct

example/main.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"log"
6+
"os"
7+
"strings"
8+
"time"
9+
10+
"github.com/kubernetes-csi/csi-lib-iscsi/iscsi"
11+
)
12+
13+
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")
21+
)
22+
23+
func main() {
24+
flag.Parse()
25+
tgtp := strings.Split(*portals, ",")
26+
if *debug {
27+
iscsi.EnableDebugLogging(os.Stdout)
28+
}
29+
30+
// You can utilize the iscsiadm calls directly if you wish, but by creating a Connector
31+
// you can simplify interactions to simple calls like "Connect" and "Disconnect"
32+
c := iscsi.Connector{
33+
// Our example uses chap
34+
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,
39+
// CHAP can be setup up for discovery as well as sessions, our example
40+
// device only uses CHAP security for sessions, for those that use Discovery
41+
// as well, we'd add a DiscoverySecrets entry the same way
42+
SessionSecrets: iscsi.Secrets{
43+
UserName: *username,
44+
Password: *password,
45+
SecretsType: "chap"},
46+
// Lun is the lun number the devices uses for exports
47+
Lun: int32(*lun),
48+
// Multipath indicates that we want to configure this connection as a multipath device
49+
Multipath: *multipath,
50+
// Number of times we check for device path, waiting for CheckInterval seconds inbetween each check (defaults to 10 if omitted)
51+
RetryCount: 11,
52+
// CheckInterval is the time in seconds to wait inbetween device path checks when logging in to a target
53+
CheckInterval: 1,
54+
}
55+
56+
// Now we can just issue a connection request using our Connector
57+
// A succesful connection will include the device path to access our iscsi volume
58+
path, err := iscsi.Connect(c)
59+
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!")
66+
os.Exit(1)
67+
}
68+
69+
log.Printf("Connected device at path: %s\n", path)
70+
time.Sleep(3 * time.Second)
71+
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)
75+
}

0 commit comments

Comments
 (0)