Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import csi-lib-iscsi to this project #76

Merged
merged 4 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ replace k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.21.1
replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.21.1

replace k8s.io/sample-controller => k8s.io/sample-controller v0.21.1

replace github.com/kubernetes-csi/csi-lib-iscsi => ./pkg/lib/iscsi
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20211110090527-5c802c48a124 h1:cajnZqFO7WAGwKHNzS4RXKJOLiB6RbN5VMVB38FYxcc=
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20211110090527-5c802c48a124/go.mod h1:c/keGS6bErOzLrFyNgafdDWT6h72v2XQiA/p2R7yghU=
github.com/kubernetes-csi/csi-lib-utils v0.10.0 h1:Aqm8X81eCzzfH/bvIEqSWtcbK9HF9NbFk4d+le1snVA=
github.com/kubernetes-csi/csi-lib-utils v0.10.0/go.mod h1:BmGZZB16L18+9+Lgg9YWwBKfNEHIDdgGfAyuW6p2NV0=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
Expand Down
3 changes: 3 additions & 0 deletions pkg/lib/iscsi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.out
_output
example/example
21 changes: 21 additions & 0 deletions pkg/lib/iscsi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: all build clean install test coverage

all: clean build install

clean:
go clean -r -x
-rm -rf _output

build:
go build ./iscsi/
go build -o _output/example ./example/main.go

install:
go install ./iscsi/

test:
go test ./iscsi/

coverage:
go test ./iscsi -coverprofile=coverage.out
go tool cover -html=coverage.out
8 changes: 8 additions & 0 deletions pkg/lib/iscsi/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md

approvers:
- saad-ali
- j-griffith
reviews:
- saad-ali
- j-griffith
55 changes: 55 additions & 0 deletions pkg/lib/iscsi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# csi lib-iscsi

A simple go package intended to assist CSI plugin authors by providing a tool set to manage iscsi connections.

## Goals

Provide a basic, lightweight library for CSI Plugin Authors to leverage some of the common tasks like connecting
and disconnecting iscsi devices to a node. This library includes a high level abstraction for iscsi that exposes
simple Connect and Disconnect functions. These are built on top of exported iscsiadm calls, so if you need more
control you can access the iscsiadm calls directly.

## Design Philosophy

The idea is to keep this as lightweight and generic as possible. We intentionally avoid the use of any third party
libraries or packages in this project. We don't have a vendor directory, because we attempt to rely only on the std
golang libs. This may prove to not be ideal, and may be changed over time, but initially it's a worthwhile goal.

## Logging and Debug

By default the library does not provide any logging, but provides an error message that includes any messages from
iscsiadm as well as exit-codes. In the event that you need to debug the library, we provide a function:

```
func EnableDebugLogging(writer io.Writer)
```

This will turn on verbose logging directed to the provided io.Writer and include the response of every iscsiadm command
issued.

## Intended Usage

Currently, the intended usage of this library is simply to provide a golang
package to standardize how plugins are implementing
iscsi connect and disconnect. It's not intended to be a "service",
although that's a possible next step. It's currently been
used for plugins where iscsid is installed in containers only, as well as designs where it uses the nodes iscsid. Each of these
approaches has their own pros and cons. Currently, it's up to the plugin author to determine which model suits them best
and to deploy their node plugin appropriately.

## Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).

You can reach the maintainers of this project at:

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

### Code of conduct

Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).

[owners]: https://git.k8s.io/community/contributors/guide/owners.md
[Creative Commons 4.0]: https://git.k8s.io/website/LICENSE
9 changes: 9 additions & 0 deletions pkg/lib/iscsi/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release Process

The Kubernetes Template Project is released on an as-needed basis. The process is as follows:

1. An issue is proposing a new release with a changelog since the last release
1. All [OWNERS](OWNERS) must LGTM this release
1. An OWNER runs `git tag -s $VERSION` and inserts the changelog and pushes the tag with `git push $VERSION`
1. The release issue is closed
1. An announcement email is sent to `[email protected]` with the subject `[ANNOUNCE] kubernetes-template-project $VERSION is released`
14 changes: 14 additions & 0 deletions pkg/lib/iscsi/SECURITY_CONTACTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Defined below are the security contacts for this repo.
#
# They are the contact point for the Product Security Team to reach out
# to for triaging and handling of incoming issues.
#
# The below names agree to abide by the
# [Embargo Policy](https://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.md#embargo-policy)
# and will be removed and replaced if they violate that agreement.
#
# DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE
# INSTRUCTIONS AT https://kubernetes.io/security/

childsb
saad-ali
3 changes: 3 additions & 0 deletions pkg/lib/iscsi/code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kubernetes Community Code of Conduct

Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md)
71 changes: 71 additions & 0 deletions pkg/lib/iscsi/example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"flag"
"log"
"os"
"strings"
"time"

"github.com/kubernetes-csi/csi-lib-iscsi/iscsi"
)

var (
portals = flag.String("portals", "192.168.1.112:3260", "Comma delimited. Eg: 1.1.1.1,2.2.2.2")
iqn = flag.String("iqn", "iqn.2010-10.org.openstack:volume-95739000-1557-44f8-9f40-e9d29fe6ec47", "")
username = flag.String("username", "3aX7EEf3CEgvESQG75qh", "")
password = flag.String("password", "eJBDC7Bt7WE3XFDq", "")
lun = flag.Int("lun", 1, "")
debug = flag.Bool("debug", false, "enable logging")
)

func main() {
flag.Parse()
tgtps := strings.Split(*portals, ",")
if *debug {
iscsi.EnableDebugLogging(os.Stdout)
}

// You can utilize the iscsiadm calls directly if you wish, but by creating a Connector
// you can simplify interactions to simple calls like "Connect" and "Disconnect"
c := &iscsi.Connector{
// Our example uses chap
AuthType: "chap",
// List of targets must be >= 1 (>1 signals multipath/mpio)
TargetIqn: *iqn,
TargetPortals: tgtps,
// CHAP can be setup up for discovery as well as sessions, our example
// device only uses CHAP security for sessions, for those that use Discovery
// as well, we'd add a DiscoverySecrets entry the same way
SessionSecrets: iscsi.Secrets{
UserName: *username,
Password: *password,
SecretsType: "chap"},
// Lun is the lun number the devices uses for exports
Lun: int32(*lun),
// Number of times we check for device path, waiting for CheckInterval seconds in between each check (defaults to 10 if omitted)
RetryCount: 11,
// CheckInterval is the time in seconds to wait in between device path checks when logging in to a target
CheckInterval: 1,
}

// Now we can just issue a connection request using our Connector
// A successful connection will include the device path to access our iscsi volume
path, err := c.Connect()
if err != nil {
log.Printf("Error returned from c.Connect: %s", err.Error())
os.Exit(1)
}

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

// This will disconnect the volume
if err := c.DisconnectVolume(); err != nil {
log.Printf("Error returned from c.DisconnectVolume: %s", err.Error())
os.Exit(1)
}

// This will disconnect the session as well as clear out the iscsi DB entries associated with it
c.Disconnect()
}
8 changes: 8 additions & 0 deletions pkg/lib/iscsi/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/kubernetes-csi/csi-lib-iscsi
humblec marked this conversation as resolved.
Show resolved Hide resolved

go 1.15

require (
github.com/prashantv/gostub v1.0.0
github.com/stretchr/testify v1.7.0
)
13 changes: 13 additions & 0 deletions pkg/lib/iscsi/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.0.0 h1:wTzvgO04xSS3gHuz6Vhuo0/kvWelyJxwNS0IRBPAwGY=
github.com/prashantv/gostub v1.0.0/go.mod h1:dP1v6T1QzyGJJKFocwAU0lSZKpfjstjH8TlhkEU0on0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading