Skip to content

Commit

Permalink
Merge pull request rexray#1133 from codenrhoden/docs/csi-nfs
Browse files Browse the repository at this point in the history
Use CentOS as base for csi-nfs docker plugin
  • Loading branch information
codenrhoden authored Dec 19, 2017
2 parents 76e7c6e + 7477234 commit e190be1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
8 changes: 3 additions & 5 deletions .docker/plugins/csi-nfs/.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM alpine:3.6
FROM centos:7.4.1708

RUN apk update
RUN apk add xfsprogs e2fsprogs ca-certificates nfs-utils
RUN yum install -y nfs-utils && yum clean all && rm -rf /var/cache/yum

RUN mkdir -p /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
RUN mkdir -p /etc/rexray /run/docker/plugins /var/lib/rexray/volumes
ADD rexray /usr/bin/rexray
ADD rexray.yml /etc/rexray/rexray.yml

ADD rexray.sh /rexray.sh
ADD .rexray.sh /rexray.sh
RUN chmod +x /rexray.sh

CMD [ "rexray", "start", "--nopid" ]
Expand Down
33 changes: 33 additions & 0 deletions .docker/plugins/csi-nfs/.rexray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# shellcheck shell=dash
set -e

# first arg is `--some-option`
if [ "$(echo "$1" | \
awk '{ string=substr($0, 1, 1); print string; }' )" = '-' ]; then
set -- rexray start --nopid "$@"
fi

#set default rexray options
REXRAY_FSTYPE="${REXRAY_FSTYPE:-ext4}"
REXRAY_LOGLEVEL="${REXRAY_LOGLEVEL:-warn}"
REXRAY_PREEMPT="${REXRAY_PREEMPT:-false}"

if [ "$1" = 'rexray' ]; then

for rexray_option in \
fsType \
loglevel \
preempt \
; do
val=$(eval echo "\$REXRAY_$(echo $rexray_option | \
awk '{print toupper($0)}')")
if [ "$val" ]; then
sed -ri 's/^([\ ]*'"$rexray_option"':).*/\1 '"$val"'/' \
/etc/rexray/rexray.yml
fi
done

fi

exec "$@"
51 changes: 51 additions & 0 deletions .docs/user-guide/schedulers/docker/plug-ins/csi-nfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,54 @@ The following environment variables can be used to configure the plug-in:
| Environment Variable | Description | Default | Required |
|---------------------|-------------|---------|---------|
| `X_CSI_NFS_VOLUMES` | A list of NFS volume mappings | | |

## Examples

To use the `csi-nfs` plug-in, you must first create a volume using the
`docker volume create` command (unless predefined using `X_CSI_NFS_VOLUMES`, see
`Limitations` below), specifying both the NFS server host and the
exported path:

```sh
$ docker volume create -d rexray/csi-nfs -o host=192.168.75.2 -o export=/data test
$ docker volume ls
DRIVER VOLUME NAME
rexray/csi-nfs test
```

With the volume created, you can then use it in your containers:

```sh
$ docker run -it -v test:/mnt alpine sh
/ # mount | grep nfs
192.168.75.2:/data on /mnt type nfs4 (rw,relatime,vers=4.1,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=10.0.2.15,local_lock=none,addr=192.168.75.2)
```

### Limitations

`csi-nfs` is an early proof of concept to demonstrate a Docker managed plug-in functioning with [CSI](https://github.com/container-storage-interface/spec). It is
not intended to replace Docker's
[native NFS](https://docs.docker.com/engine/reference/commandline/volume_create/#driver-specific-options)
functionality.

Currently, the plug-in only supports NFSv4, and does not allow for custom options
to be passed through to the mount command. In other words, the NFS mount command
will always be of the form `mount -t nfs {server}:{export} {mountpath}`.

When doing a `docker volume create` command, the `csi-nfs` plug-in merely creates
a reference to an existing NFS volume with the details you have provided. This
reference is only persisted across the lifetime of the plug-in, which means if the
plug-in is removed and recreated, or upgraded, the volumes previously seen in
`docker volume ls` will disappear. To circumvent this behavior, you can seed the
plug-in with the NFS volume definitions using the `X_CSI_NFS_VOLUMES` env var.
For example:

```sh
$ docker plugin set rexray/csi-nfs X_CSI_NFS_VOLUMES="vol1=192.168.75.2:/nfsshare vol2=192.168.75.2:/share2"
```

The env var can be set during plug-in installation, or the plug-in can be disabled,
the var set, and then enabled. However, currently only the env var or the persisted
volumes from `docker volume create` can be used, which means if
`docker volume create` is used to define an NFS volume, a later setting of
`X_CSI_NFS_VOLUMES` will be ignored.

0 comments on commit e190be1

Please sign in to comment.