dummy 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. # Copyright 2017 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This driver implements a tmpfs with a pre-populated file index.html.
  16. FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"}
  17. log() {
  18. printf "$*" >&1
  19. }
  20. debug() {
  21. echo "$(date) $*" >> "${FLEX_DUMMY_LOG}"
  22. }
  23. domount() {
  24. debug "domount $@"
  25. MNTPATH=$1
  26. mkdir -p ${MNTPATH} >/dev/null 2>&1
  27. mount -t tmpfs none ${MNTPATH} >/dev/null 2>&1
  28. echo "Hello from flexvolume!" >> "${MNTPATH}/index.html"
  29. log "{\"status\":\"Success\"}"
  30. exit 0
  31. }
  32. unmount() {
  33. debug "unmount $@"
  34. MNTPATH=$1
  35. rm ${MNTPATH}/index.html >/dev/null 2>&1
  36. umount ${MNTPATH} >/dev/null 2>&1
  37. log "{\"status\":\"Success\"}"
  38. exit 0
  39. }
  40. op=$1
  41. if [ "$op" = "init" ]; then
  42. debug "init $@"
  43. log "{\"status\":\"Success\",\"capabilities\":{\"attach\":false}}"
  44. exit 0
  45. fi
  46. shift
  47. case "$op" in
  48. mount)
  49. domount $*
  50. ;;
  51. unmount)
  52. unmount $*
  53. ;;
  54. *)
  55. log "{\"status\":\"Not supported\"}"
  56. exit 0
  57. esac
  58. exit 1