k8s.io/kubernetes@v1.29.3/test/e2e/testing-manifests/flexvolume/dummy-attachable (about) 1 #!/bin/sh 2 3 # Copyright 2017 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This driver implements a tmpfs with a pre-populated file index.html. 18 # Attach is required, but it is a no-op that always returns success. 19 20 FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"} 21 22 VALID_MNTDEVICE=foo 23 24 # attach always returns one valid mount device so a different device 25 # showing up in a subsequent driver call implies a bug 26 validateMountDeviceOrDie() { 27 MNTDEVICE=$1 28 CALL=$2 29 if [ "$MNTDEVICE" != "$VALID_MNTDEVICE" ]; then 30 log "{\"status\":\"Failure\",\"message\":\"call "${CALL}" expected device "${VALID_MNTDEVICE}", got device "${MNTDEVICE}"\"}" 31 exit 0 32 fi 33 } 34 35 log() { 36 printf "$*" >&1 37 } 38 39 debug() { 40 echo "$(date) $*" >> "${FLEX_DUMMY_LOG}" 41 } 42 43 attach() { 44 debug "attach $@" 45 log "{\"status\":\"Success\",\"device\":\""${VALID_MNTDEVICE}"\"}" 46 exit 0 47 } 48 49 detach() { 50 debug "detach $@" 51 # TODO issue 44737 detach is passed PV name, not mount device 52 log "{\"status\":\"Success\"}" 53 exit 0 54 } 55 56 waitforattach() { 57 debug "waitforattach $@" 58 MNTDEVICE=$1 59 validateMountDeviceOrDie "$MNTDEVICE" "waitforattach" 60 log "{\"status\":\"Success\",\"device\":\""${MNTDEVICE}"\"}" 61 exit 0 62 } 63 64 isattached() { 65 debug "isattached $@" 66 log "{\"status\":\"Success\",\"attached\":true}" 67 exit 0 68 } 69 70 domountdevice() { 71 debug "domountdevice $@" 72 MNTDEVICE=$2 73 validateMountDeviceOrDie "$MNTDEVICE" "domountdevice" 74 MNTPATH=$1 75 mkdir -p ${MNTPATH} >/dev/null 2>&1 76 mount -t tmpfs none ${MNTPATH} >/dev/null 2>&1 77 echo "Hello from flexvolume!" >> "${MNTPATH}/index.html" 78 log "{\"status\":\"Success\"}" 79 exit 0 80 } 81 82 unmountdevice() { 83 debug "unmountdevice $@" 84 MNTPATH=$1 85 rm "${MNTPATH}/index.html" >/dev/null 2>&1 86 umount ${MNTPATH} >/dev/null 2>&1 87 log "{\"status\":\"Success\"}" 88 exit 0 89 } 90 91 expandvolume() { 92 debug "expandvolume $@" 93 log "{\"status\":\"Success\"}" 94 exit 0 95 } 96 97 expandfs() { 98 debug "expandfs $@" 99 log "{\"status\":\"Success\"}" 100 exit 0 101 } 102 103 op=$1 104 105 if [ "$op" = "init" ]; then 106 debug "init $@" 107 log "{\"status\":\"Success\",\"capabilities\":{\"attach\":true, \"requiresFSResize\":true}}" 108 exit 0 109 fi 110 111 shift 112 113 case "$op" in 114 attach) 115 attach $* 116 ;; 117 detach) 118 detach $* 119 ;; 120 waitforattach) 121 waitforattach $* 122 ;; 123 isattached) 124 isattached $* 125 ;; 126 mountdevice) 127 domountdevice $* 128 ;; 129 unmountdevice) 130 unmountdevice $* 131 ;; 132 expandvolume) 133 expandvolume $* 134 ;; 135 expandfs) 136 expandfs $* 137 ;; 138 *) 139 log "{\"status\":\"Not supported\"}" 140 exit 0 141 esac 142 143 exit 1