loopDevicePV.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. # Copyright 2021 The Rook Authors. All rights reserved.
  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. set -ex
  16. #############
  17. # VARIABLES #
  18. #############
  19. osd_count=$1
  20. sudo lsblk
  21. #############
  22. # FUNCTIONS #
  23. #############
  24. function add_loop_dev_pvc() {
  25. local osd_count=$1
  26. local storage=6Gi
  27. for osd in $(seq 1 "$osd_count"); do
  28. path=/dev/loop${osd}
  29. cat <<eof | kubectl apply -f -
  30. ---
  31. apiVersion: v1
  32. kind: PersistentVolume
  33. metadata:
  34. name: local-vol-loop-dev$osd
  35. labels:
  36. type: local
  37. spec:
  38. storageClassName: manual
  39. capacity:
  40. storage: "$storage"
  41. accessModes:
  42. - ReadWriteOnce
  43. persistentVolumeReclaimPolicy: Retain
  44. volumeMode: Block
  45. local:
  46. path: "$path"
  47. nodeAffinity:
  48. required:
  49. nodeSelectorTerms:
  50. - matchExpressions:
  51. - key: rook.io/has-disk
  52. operator: In
  53. values:
  54. - "true"
  55. eof
  56. done
  57. }
  58. ########
  59. # MAIN #
  60. ########
  61. add_loop_dev_pvc "$osd_count"
  62. kubectl get pv -o wide