diff --git a/examples/volumes/flexvolume/deploy/Dockerfile b/examples/volumes/flexvolume/deploy/Dockerfile new file mode 100644 index 0000000000..55ef6011a4 --- /dev/null +++ b/examples/volumes/flexvolume/deploy/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM busybox +WORKDIR . + +# TODO Change to your desired driver. +COPY ./drivers/dummy /dummy + +COPY deploy.sh /deploy.sh +CMD /bin/sh /deploy.sh diff --git a/examples/volumes/flexvolume/deploy/README.md b/examples/volumes/flexvolume/deploy/README.md new file mode 100644 index 0000000000..f9b0480a37 --- /dev/null +++ b/examples/volumes/flexvolume/deploy/README.md @@ -0,0 +1,7 @@ +This directory contains an example of the DaemonSet Flexvolume driver deployment method. See documentation [here](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/flexvolume-deployment.md#recommended-driver-deployment-method). + +Steps to use the DaemonSet deployment method: +1. Copy the Flexvolume driver to `drivers` directory. To get a basic example running, copy the `dummy` driver from the parent directory. +1. If you'd like to just get a basic example running, you could skip this step. Otherwise, change the places marked with `TODO` in all files. +1. Build the deployment Docker image and upload to your container registry. +1. Create the DaemonSet. diff --git a/examples/volumes/flexvolume/deploy/deploy.sh b/examples/volumes/flexvolume/deploy/deploy.sh new file mode 100755 index 0000000000..ee8ae0ee2a --- /dev/null +++ b/examples/volumes/flexvolume/deploy/deploy.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o pipefail + +# TODO change to your desired driver. +VENDOR=${VENDOR:-k8s} +DRIVER=${DRIVER:-dummy} + +# Assuming the single driver file is located at /$DRIVER inside the DaemonSet image. + +driver_dir=$VENDOR${VENDOR:+"~"}${DRIVER} +if [ ! -d "/flexmnt/$driver_dir" ]; then + mkdir "/flexmnt/$driver_dir" +fi + +tmp_driver=.tmp_$DRIVER +cp "/$DRIVER" "/flexmnt/$driver_dir/$tmp_driver" +mv -f "/flexmnt/$driver_dir/$tmp_driver" "/flexmnt/$driver_dir/$DRIVER" + +while : ; do + sleep 3600 +done diff --git a/examples/volumes/flexvolume/deploy/ds.yaml b/examples/volumes/flexvolume/deploy/ds.yaml new file mode 100644 index 0000000000..9089bd19fc --- /dev/null +++ b/examples/volumes/flexvolume/deploy/ds.yaml @@ -0,0 +1,25 @@ +apiVersion: extensions/v1beta1 +kind: DaemonSet +metadata: + name: flex-ds +spec: + template: + metadata: + name: flex-deploy + labels: + app: flex-deploy + spec: + containers: + # TODO Change to your container registry. + - image: "" + name: flex-deploy + securityContext: + privileged: true + volumeMounts: + - mountPath: /flexmnt + name: flexvolume-mount + volumes: + - name: flexvolume-mount + hostPath: + # TODO Change to the Flexvolume plugin directory of your cluster. + path: /usr/libexec/kubernetes/kubelet-plugins/volume/exec/ diff --git a/examples/volumes/flexvolume/dummy b/examples/volumes/flexvolume/dummy new file mode 100755 index 0000000000..4b4012ceda --- /dev/null +++ b/examples/volumes/flexvolume/dummy @@ -0,0 +1,70 @@ +#!/bin/sh + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This driver implements a tmpfs with a pre-populated file index.html. + +FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"} + +log() { + printf "$*" >&1 +} + +debug() { + echo "$(date) $*" >> "${FLEX_DUMMY_LOG}" +} + +domount() { + debug "domount $@" + MNTPATH=$1 + mkdir -p ${MNTPATH} >/dev/null 2>&1 + mount -t tmpfs none ${MNTPATH} >/dev/null 2>&1 + echo "Hello from flexvolume!" >> "${MNTPATH}/index.html" + log "{\"status\":\"Success\"}" + exit 0 +} + +unmount() { + debug "unmount $@" + MNTPATH=$1 + rm ${MNTPATH}/index.html >/dev/null 2>&1 + umount ${MNTPATH} >/dev/null 2>&1 + log "{\"status\":\"Success\"}" + exit 0 +} + +op=$1 + +if [ "$op" = "init" ]; then + debug "init $@" + log "{\"status\":\"Success\",\"capabilities\":{\"attach\":false}}" + exit 0 +fi + +shift + +case "$op" in + mount) + domount $* + ;; + unmount) + unmount $* + ;; + *) + log "{\"status\":\"Not supported\"}" + exit 0 +esac + +exit 1 diff --git a/examples/volumes/flexvolume/dummy-attachable b/examples/volumes/flexvolume/dummy-attachable new file mode 100755 index 0000000000..8afd6b4bfa --- /dev/null +++ b/examples/volumes/flexvolume/dummy-attachable @@ -0,0 +1,126 @@ +#!/bin/sh + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This driver implements a tmpfs with a pre-populated file index.html. +# Attach is required, but it is a no-op that always returns success. + +FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"} + +VALID_MNTDEVICE=foo + +# attach always returns one valid mount device so a different device +# showing up in a subsequent driver call implies a bug +validateMountDeviceOrDie() { + MNTDEVICE=$1 + CALL=$2 + if [ "$MNTDEVICE" != "$VALID_MNTDEVICE" ]; then + log "{\"status\":\"Failure\",\"message\":\"call "${CALL}" expected device "${VALID_MNTDEVICE}", got device "${MNTDEVICE}"\"}" + exit 0 + fi +} + +log() { + printf "$*" >&1 +} + +debug() { + echo "$(date) $*" >> "${FLEX_DUMMY_LOG}" +} + +attach() { + debug "attach $@" + log "{\"status\":\"Success\",\"device\":\""${VALID_MNTDEVICE}"\"}" + exit 0 +} + +detach() { + debug "detach $@" + log "{\"status\":\"Success\"}" + exit 0 +} + +waitforattach() { + debug "waitforattach $@" + MNTDEVICE=$1 + validateMountDeviceOrDie "$MNTDEVICE" "waitforattach" + log "{\"status\":\"Success\",\"device\":\""${MNTDEVICE}"\"}" + exit 0 +} + +isattached() { + debug "isattached $@" + log "{\"status\":\"Success\",\"attached\":true}" + exit 0 +} + +domountdevice() { + debug "domountdevice $@" + MNTDEVICE=$2 + validateMountDeviceOrDie "$MNTDEVICE" "domountdevice" + MNTPATH=$1 + mkdir -p ${MNTPATH} >/dev/null 2>&1 + mount -t tmpfs none ${MNTPATH} >/dev/null 2>&1 + echo "Hello from flexvolume!" >> "${MNTPATH}/index.html" + log "{\"status\":\"Success\"}" + exit 0 +} + +unmountdevice() { + debug "unmountdevice $@" + MNTDEVICE=$2 + validateMountDeviceOrDie "$MNTDEVICE" "unmountdevice" + MNTPATH=$1 + rm "${MNTPATH}/index.html" >/dev/null 2>&1 + umount ${MNTPATH} >/dev/null 2>&1 + log "{\"status\":\"Success\"}" + exit 0 +} + +op=$1 + +if [ "$op" = "init" ]; then + debug "init $@" + log "{\"status\":\"Success\",\"capabilities\":{\"attach\":true}}" + exit 0 +fi + +shift + +case "$op" in + attach) + attach $* + ;; + detach) + detach $* + ;; + waitforattach) + waitforattach $* + ;; + isattached) + isattached $* + ;; + mountdevice) + domountdevice $* + ;; + unmountdevice) + unmountdevice $* + ;; + *) + log "{\"status\":\"Not supported\"}" + exit 0 +esac + +exit 1 diff --git a/examples/volumes/flexvolume/nginx-dummy-attachable.yaml b/examples/volumes/flexvolume/nginx-dummy-attachable.yaml new file mode 100644 index 0000000000..80b322c986 --- /dev/null +++ b/examples/volumes/flexvolume/nginx-dummy-attachable.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx-dummy-attachable + namespace: default +spec: + containers: + - name: nginx-dummy-attachable + image: nginx + volumeMounts: + - name: dummy-attachable + mountPath: /data + ports: + - containerPort: 80 + volumes: + - name: dummy-attachable + flexVolume: + driver: "k8s/dummy-attachable" diff --git a/examples/volumes/flexvolume/nginx-dummy.yaml b/examples/volumes/flexvolume/nginx-dummy.yaml new file mode 100644 index 0000000000..33ee34251a --- /dev/null +++ b/examples/volumes/flexvolume/nginx-dummy.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: nginx-dummy + namespace: default +spec: + containers: + - name: nginx-dummy + image: nginx + volumeMounts: + - name: dummy + mountPath: /data + ports: + - containerPort: 80 + volumes: + - name: dummy + flexVolume: + driver: "k8s/dummy" diff --git a/examples/volumes/flexvolume/nginx.yaml b/examples/volumes/flexvolume/nginx-lvm.yaml similarity index 100% rename from examples/volumes/flexvolume/nginx.yaml rename to examples/volumes/flexvolume/nginx-lvm.yaml diff --git a/test/e2e/testing-manifests/flexvolume/dummy b/test/e2e/testing-manifests/flexvolume/dummy index f9abaa5c72..4b4012ceda 100755 --- a/test/e2e/testing-manifests/flexvolume/dummy +++ b/test/e2e/testing-manifests/flexvolume/dummy @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# This driver implements a tmpfs with a pre-populated file index.html. + FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"} log() { diff --git a/test/e2e/testing-manifests/flexvolume/dummy-attachable b/test/e2e/testing-manifests/flexvolume/dummy-attachable index 49d42cc8e6..07cb995db2 100755 --- a/test/e2e/testing-manifests/flexvolume/dummy-attachable +++ b/test/e2e/testing-manifests/flexvolume/dummy-attachable @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# This driver implements a tmpfs with a pre-populated file index.html. +# Attach is required, but it is a no-op that always returns success. + FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"} VALID_MNTDEVICE=foo