localPathPV.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. test_scratch_device=/dev/nvme0n1
  17. if [ $# -ge 1 ] ; then
  18. test_scratch_device=$1
  19. fi
  20. #############
  21. # VARIABLES #
  22. #############
  23. osd_count=2
  24. db_device=$2
  25. wal_device=$3
  26. sudo lsblk
  27. sudo test ! -b "${test_scratch_device}" && echo "invalid scratch device, not a block device: ${test_scratch_device}" >&2 && exit 1
  28. #############
  29. # FUNCTIONS #
  30. #############
  31. function prepare_node() {
  32. sudo rm -rf /var/lib/rook/rook-integration-test
  33. sudo mkdir -p /var/lib/rook/rook-integration-test/mon1 /var/lib/rook/rook-integration-test/mon2 /var/lib/rook/rook-integration-test/mon3
  34. node_name=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}')
  35. kubectl label nodes "${node_name}" rook.io/has-disk=true
  36. kubectl delete pv -l type=local
  37. }
  38. function create_mon_pvc() {
  39. cat <<eof | kubectl apply -f -
  40. apiVersion: v1
  41. kind: PersistentVolume
  42. metadata:
  43. name: local-vol1
  44. labels:
  45. type: local
  46. spec:
  47. storageClassName: manual
  48. capacity:
  49. storage: 5Gi
  50. accessModes:
  51. - ReadWriteOnce
  52. persistentVolumeReclaimPolicy: Retain
  53. volumeMode: Filesystem
  54. local:
  55. path: "/var/lib/rook/rook-integration-test/mon1"
  56. nodeAffinity:
  57. required:
  58. nodeSelectorTerms:
  59. - matchExpressions:
  60. - key: rook.io/has-disk
  61. operator: In
  62. values:
  63. - "true"
  64. ---
  65. apiVersion: v1
  66. kind: PersistentVolume
  67. metadata:
  68. name: local-vol2
  69. labels:
  70. type: local
  71. spec:
  72. storageClassName: manual
  73. capacity:
  74. storage: 5Gi
  75. accessModes:
  76. - ReadWriteOnce
  77. persistentVolumeReclaimPolicy: Retain
  78. volumeMode: Filesystem
  79. local:
  80. path: "/var/lib/rook/rook-integration-test/mon2"
  81. nodeAffinity:
  82. required:
  83. nodeSelectorTerms:
  84. - matchExpressions:
  85. - key: rook.io/has-disk
  86. operator: In
  87. values:
  88. - "true"
  89. ---
  90. apiVersion: v1
  91. kind: PersistentVolume
  92. metadata:
  93. name: local-vol3
  94. labels:
  95. type: local
  96. spec:
  97. storageClassName: manual
  98. capacity:
  99. storage: 5Gi
  100. accessModes:
  101. - ReadWriteOnce
  102. persistentVolumeReclaimPolicy: Retain
  103. volumeMode: Filesystem
  104. local:
  105. path: "/var/lib/rook/rook-integration-test/mon3"
  106. nodeAffinity:
  107. required:
  108. nodeSelectorTerms:
  109. - matchExpressions:
  110. - key: rook.io/has-disk
  111. operator: In
  112. values:
  113. - "true"
  114. eof
  115. }
  116. function create_osd_pvc() {
  117. local osd_count=$1
  118. local storage=6Gi
  119. for osd in $(seq 1 "$osd_count"); do
  120. path=${test_scratch_device}${osd}
  121. if [ "$osd_count" -eq 1 ]; then
  122. path=$test_scratch_device
  123. storage=10Gi
  124. fi
  125. cat <<eof | kubectl apply -f -
  126. ---
  127. apiVersion: v1
  128. kind: PersistentVolume
  129. metadata:
  130. name: local-vol$((4 + osd))
  131. labels:
  132. type: local
  133. spec:
  134. storageClassName: manual
  135. capacity:
  136. storage: "$storage"
  137. accessModes:
  138. - ReadWriteOnce
  139. persistentVolumeReclaimPolicy: Retain
  140. volumeMode: Block
  141. local:
  142. path: "$path"
  143. nodeAffinity:
  144. required:
  145. nodeSelectorTerms:
  146. - matchExpressions:
  147. - key: rook.io/has-disk
  148. operator: In
  149. values:
  150. - "true"
  151. eof
  152. done
  153. }
  154. function create_create_sc() {
  155. cat <<eof | kubectl apply -f -
  156. ---
  157. kind: StorageClass
  158. apiVersion: storage.k8s.io/v1
  159. metadata:
  160. name: manual
  161. provisioner: kubernetes.io/no-provisioner
  162. volumeBindingMode: WaitForFirstConsumer
  163. reclaimPolicy: Delete
  164. eof
  165. }
  166. function add_db_pvc {
  167. cat <<eof | kubectl apply -f -
  168. ---
  169. apiVersion: v1
  170. kind: PersistentVolume
  171. metadata:
  172. name: local-vol8
  173. labels:
  174. type: local
  175. spec:
  176. storageClassName: manual
  177. capacity:
  178. storage: 2Gi
  179. accessModes:
  180. - ReadWriteOnce
  181. persistentVolumeReclaimPolicy: Retain
  182. volumeMode: Block
  183. local:
  184. path: "${db_device}"
  185. nodeAffinity:
  186. required:
  187. nodeSelectorTerms:
  188. - matchExpressions:
  189. - key: rook.io/has-disk
  190. operator: In
  191. values:
  192. - "true"
  193. eof
  194. }
  195. function add_wal_pvc {
  196. cat <<eof | kubectl apply -f -
  197. ---
  198. apiVersion: v1
  199. kind: PersistentVolume
  200. metadata:
  201. name: local-vol9
  202. labels:
  203. type: local
  204. spec:
  205. storageClassName: manual
  206. capacity:
  207. storage: 2Gi
  208. accessModes:
  209. - ReadWriteOnce
  210. persistentVolumeReclaimPolicy: Retain
  211. volumeMode: Block
  212. local:
  213. path: "${wal_device}"
  214. nodeAffinity:
  215. required:
  216. nodeSelectorTerms:
  217. - matchExpressions:
  218. - key: rook.io/has-disk
  219. operator: In
  220. values:
  221. - "true"
  222. eof
  223. }
  224. ########
  225. # MAIN #
  226. ########
  227. prepare_node
  228. create_mon_pvc
  229. # Add a db device if needed
  230. if [ -n "$db_device" ]; then
  231. osd_count=1
  232. add_db_pvc
  233. fi
  234. # Add a wal device if needed
  235. if [ -n "$wal_device" ]; then
  236. osd_count=1
  237. add_wal_pvc
  238. fi
  239. # For the LVM scenario
  240. scratch_dev_type=$(lsblk --noheadings --output TYPE "$test_scratch_device")
  241. if [[ "$scratch_dev_type" == "lvm" ]]; then
  242. osd_count=1
  243. fi
  244. # For the ceph_integration suite
  245. # It's an env var set by the gitaction action when running TestCephMultiClusterDeploySuite not a misspell
  246. # shellcheck disable=SC2153
  247. if [[ -n "$TEST_SCRATCH_DEVICE" ]]; then
  248. osd_count=1
  249. fi
  250. create_osd_pvc "$osd_count"
  251. create_create_sc
  252. kubectl get pv -o wide