DeployTest.groovy 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. pipeline {
  2. options {
  3. timestamps()
  4. }
  5. agent {
  6. kubernetes {
  7. label "milvus-test"
  8. defaultContainer 'main'
  9. yamlFile "build/ci/jenkins/pod/chaos-test.yaml"
  10. customWorkspace '/home/jenkins/agent/workspace'
  11. // idle 5 minutes to wait clean up tasks
  12. idleMinutes 5
  13. }
  14. }
  15. parameters{
  16. choice(
  17. description: 'Choose tools to deploy Milvus',
  18. name: 'deploy_tool',
  19. choices: ['helm']
  20. )
  21. choice(
  22. description: 'Milvus Mode',
  23. name: 'milvus_mode',
  24. choices: ["standalone", "cluster"]
  25. )
  26. choice(
  27. description: 'Deploy Test Task',
  28. name: 'deploy_task',
  29. choices: ['reinstall', 'upgrade']
  30. )
  31. string(
  32. description: 'Old Image Repository',
  33. name: 'old_image_repository',
  34. defaultValue: 'milvusdb/milvus'
  35. )
  36. string(
  37. description: 'Old Version Image Tag',
  38. name: 'old_image_tag',
  39. defaultValue: 'latest'
  40. )
  41. string(
  42. description: 'New Image Repository',
  43. name: 'new_image_repository',
  44. defaultValue: 'harbor.milvus.io/dockerhub/milvusdb/milvus'
  45. )
  46. string(
  47. description: 'New Version Image Tag',
  48. name: 'new_image_tag',
  49. defaultValue: 'master-latest'
  50. )
  51. string(
  52. description: 'Etcd Image Repository',
  53. name: 'etcd_image_repository',
  54. defaultValue: "milvusdb/etcd"
  55. )
  56. string(
  57. description: 'Etcd Image Tag',
  58. name: 'etcd_image_tag',
  59. defaultValue: "3.5.0-r6"
  60. )
  61. string(
  62. description: 'Querynode Nums',
  63. name: 'querynode_nums',
  64. defaultValue: '3'
  65. )
  66. string(
  67. description: 'DataNode Nums',
  68. name: 'datanode_nums',
  69. defaultValue: '2'
  70. )
  71. string(
  72. description: 'IndexNode Nums',
  73. name: 'indexnode_nums',
  74. defaultValue: '1'
  75. )
  76. string(
  77. description: 'Proxy Nums',
  78. name: 'proxy_nums',
  79. defaultValue: '1'
  80. )
  81. string(
  82. description: 'Data Size',
  83. name: 'data_size',
  84. defaultValue: '3000'
  85. )
  86. string(
  87. description: 'Idle Time in Minutes',
  88. name: 'idel_time',
  89. defaultValue: '1'
  90. )
  91. booleanParam(
  92. description: 'Keep Env',
  93. name: 'keep_env',
  94. defaultValue: 'false'
  95. )
  96. }
  97. environment {
  98. ARTIFACTS = "${env.WORKSPACE}/_artifacts"
  99. RELEASE_NAME = "${params.milvus_mode}-${params.deploy_task}-${env.BUILD_ID}"
  100. NAMESPACE = "chaos-testing"
  101. new_image_tag_modified = ""
  102. }
  103. stages {
  104. stage ('Install Dependency') {
  105. steps {
  106. container('main') {
  107. dir ('tests/python_client') {
  108. script {
  109. sh "pip install -r requirements.txt --trusted-host https://test.pypi.org"
  110. }
  111. }
  112. }
  113. }
  114. }
  115. stage ('Modify Milvus chart values') {
  116. steps {
  117. container('main') {
  118. dir ('tests/python_client/deploy') {
  119. script {
  120. sh """
  121. yq -i '.queryNode.replicas = "${params.querynode_nums}"' cluster-values.yaml
  122. yq -i '.dataNode.replicas = "${params.datanode_nums}"' cluster-values.yaml
  123. yq -i '.indexNode.replicas = "${params.indexnode_nums}"' cluster-values.yaml
  124. yq -i '.proxy.replicas = "${params.proxy_nums}"' cluster-values.yaml
  125. yq -i '.etcd.image.repository = "${params.etcd_image_repository}"' cluster-values.yaml
  126. yq -i '.etcd.image.tag = "${params.etcd_image_tag}"' cluster-values.yaml
  127. yq -i '.etcd.image.repository = "${params.etcd_image_repository}"' standalone-values.yaml
  128. yq -i '.etcd.image.tag = "${params.etcd_image_tag}"' standalone-values.yaml
  129. cat cluster-values.yaml
  130. """
  131. }
  132. }
  133. }
  134. }
  135. }
  136. stage ('First Milvus Deployment') {
  137. options {
  138. timeout(time: 15, unit: 'MINUTES') // timeout on this stage
  139. }
  140. steps {
  141. container('main') {
  142. dir ('tests/python_client/deploy') {
  143. script {
  144. def old_image_tag_modified = ""
  145. def new_image_tag_modified = ""
  146. def old_image_repository_modified = ""
  147. def new_image_repository_modified = ""
  148. if ("${params.old_image_tag}" == "master-latest") {
  149. old_image_tag_modified = sh(returnStdout: true, script: 'bash ../../../scripts/docker_image_find_tag.sh -n milvusdb/milvus -t master-latest -f master- -F -L -q').trim()
  150. }
  151. else if ("${params.old_image_tag}" == "latest") {
  152. old_image_tag_modified = sh(returnStdout: true, script: 'bash ../../../scripts/docker_image_find_tag.sh -n milvusdb/milvus -t latest -F -L -q').trim()
  153. }
  154. else {
  155. old_image_tag_modified = "${params.old_image_tag}"
  156. }
  157. if ("${params.new_image_tag}" == "master-latest") {
  158. new_image_tag_modified = sh(returnStdout: true, script: 'bash ../../../scripts/docker_image_find_tag.sh -n milvusdb/milvus -t master-latest -f master- -F -L -q').trim()
  159. }
  160. else {
  161. new_image_tag_modified = "${params.new_image_tag}"
  162. }
  163. sh "echo ${old_image_tag_modified}"
  164. sh "echo ${new_image_tag_modified}"
  165. sh "echo ${new_image_tag_modified} > new_image_tag_modified.txt"
  166. stash includes: 'new_image_tag_modified.txt', name: 'new_image_tag_modified'
  167. env.new_image_tag_modified = new_image_tag_modified
  168. if ("${params.deploy_task}" == "reinstall"){
  169. echo "reinstall Milvus with new image tag"
  170. old_image_tag_modified = new_image_tag_modified
  171. }
  172. if ("${params.deploy_task}" == "reinstall"){
  173. echo "reinstall Milvus with new image repository"
  174. old_image_repository_modified = "${params.new_image_repository}"
  175. }
  176. else {
  177. old_image_repository_modified = "${params.old_image_repository}"
  178. }
  179. sh "helm repo add milvus https://zilliztech.github.io/milvus-helm"
  180. sh "helm repo update"
  181. if ("${params.deploy_task}" == "upgrade"){
  182. if ("${params.milvus_mode}" == "standalone") {
  183. sh "helm install --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${old_image_repository_modified} --set image.all.tag=${old_image_tag_modified} --set etcd.image.repository=bitnami/etcd --set etcd.image.tag=3.5.0-debian-10-r24 -f standalone-values.yaml;"
  184. }
  185. if ("${params.milvus_mode}" == "cluster") {
  186. sh "helm install --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${old_image_repository_modified} --set image.all.tag=${old_image_tag_modified} --set etcd.image.repository=bitnami/etcd --set etcd.image.tag=3.5.0-debian-10-r24 -f cluster-values.yaml;"
  187. }
  188. }
  189. if ("${params.deploy_task}" == "reinstall"){
  190. if ("${params.milvus_mode}" == "standalone") {
  191. sh "helm install --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${old_image_repository_modified} --set image.all.tag=${old_image_tag_modified} -f standalone-values.yaml;"
  192. }
  193. if ("${params.milvus_mode}" == "cluster") {
  194. sh "helm install --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${old_image_repository_modified} --set image.all.tag=${old_image_tag_modified} -f cluster-values.yaml;"
  195. }
  196. }
  197. sh "kubectl wait --for=condition=Ready pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  198. sh "kubectl wait --for=condition=Ready pod -l release=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  199. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME}"
  200. }
  201. }
  202. }
  203. }
  204. }
  205. stage ('Run first test') {
  206. options {
  207. timeout(time: 30, unit: 'MINUTES') // timeout on this stage
  208. }
  209. steps {
  210. container('main') {
  211. dir ('tests/python_client/deploy') {
  212. script {
  213. def host = sh(returnStdout: true, script: "kubectl get svc/${env.RELEASE_NAME}-milvus -o jsonpath=\"{.spec.clusterIP}\"").trim()
  214. if ("${params.deploy_task}" == "reinstall") {
  215. sh "python3 scripts/action_before_reinstall.py --host ${host} --data_size ${params.data_size}"
  216. }
  217. if ("${params.deploy_task}" == "upgrade") {
  218. sh "python3 scripts/action_before_upgrade.py --host ${host} --data_size ${params.data_size}"
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. stage ('Milvus Idle Time') {
  226. steps {
  227. container('main') {
  228. dir ('tests/python_client/deploy') {
  229. script {
  230. echo "sleep ${params.idel_time}m"
  231. sh "sleep ${params.idel_time}m"
  232. }
  233. }
  234. }
  235. }
  236. }
  237. stage ('Export log for first deployment') {
  238. steps {
  239. container('main') {
  240. dir ('tests/python_client/deploy') {
  241. script {
  242. echo "get pod status"
  243. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME} || true"
  244. echo "collecte logs"
  245. sh "bash ../../scripts/export_log_k8s.sh ${env.NAMESPACE} ${env.RELEASE_NAME} k8s_log/${env.RELEASE_NAME}/first_deployment || echo 'export log failed'"
  246. }
  247. }
  248. }
  249. }
  250. }
  251. stage ('Uninstall Milvus') {
  252. options {
  253. timeout(time: 15, unit: 'MINUTES') // timeout on this stage
  254. }
  255. steps {
  256. container('main') {
  257. dir ('tests/python_client/deploy') {
  258. script {
  259. if ("${params.milvus_mode}" == "standalone") {
  260. sh "kubectl delete pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} --grace-period=0 --force"
  261. sh "kubectl delete pod -l release=${env.RELEASE_NAME} --grace-period=0 --force"
  262. sh "kubectl wait --for=condition=Ready pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  263. sh "kubectl wait --for=condition=Ready pod -l release=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  264. }
  265. if ("${params.milvus_mode}" == "cluster") {
  266. sh "helm uninstall ${env.RELEASE_NAME}"
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. stage ('Second Milvus Deployment') {
  274. options {
  275. timeout(time: 20, unit: 'MINUTES') // timeout on this stage
  276. }
  277. steps {
  278. container('main') {
  279. dir ('tests/python_client/deploy') {
  280. script {
  281. // in case of master-latest is different in two stages, we need use the new_image_tag_modified.txt to store the new_image_tag in first stage
  282. def new_image_tag_modified = ""
  283. dir ("new_image_tag_modified"){
  284. try{
  285. unstash 'new_image_tag_modified'
  286. new_image_tag_modified=sh(returnStdout: true, script: 'cat new_image_tag_modified.txt | tr -d \'\n\r\'')
  287. }catch(e){
  288. print "No image tag info remained"
  289. exit 1
  290. }
  291. }
  292. if ("${params.milvus_mode}" == "standalone") {
  293. sh "helm upgrade --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${params.new_image_repository} --set image.all.tag=${new_image_tag_modified} -f standalone-values.yaml"
  294. }
  295. if ("${params.milvus_mode}" == "cluster") {
  296. sh "helm install --wait --timeout 720s ${env.RELEASE_NAME} milvus/milvus --set image.all.repository=${params.new_image_repository} --set image.all.tag=${new_image_tag_modified} -f cluster-values.yaml"
  297. }
  298. sh "sleep 60s"
  299. // sh "kubectl wait --for=condition=Ready pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  300. // sh "kubectl wait --for=condition=Ready pod -l release=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  301. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME}"
  302. }
  303. }
  304. }
  305. }
  306. }
  307. stage ('Run Second Test') {
  308. options {
  309. timeout(time: 30, unit: 'MINUTES') // timeout on this stage
  310. }
  311. steps {
  312. container('main') {
  313. dir ('tests/python_client/deploy') {
  314. script {
  315. sh "sleep 60s" // wait loading data for the second deployment to be ready
  316. def host = sh(returnStdout: true, script: "kubectl get svc/${env.RELEASE_NAME}-milvus -o jsonpath=\"{.spec.clusterIP}\"").trim()
  317. if ("${params.deploy_task}" == "reinstall") {
  318. sh "python3 scripts/action_after_reinstall.py --host ${host} --data_size ${params.data_size}"
  319. }
  320. if ("${params.deploy_task}" == "upgrade") {
  321. sh "python3 scripts/action_after_upgrade.py --host ${host} --data_size ${params.data_size}"
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. post {
  330. always {
  331. echo 'upload logs'
  332. container('main') {
  333. dir ('tests/python_client/deploy') {
  334. script {
  335. echo "get pod status"
  336. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME} || true"
  337. echo "collecte logs"
  338. sh "bash ../../scripts/export_log_k8s.sh ${env.NAMESPACE} ${env.RELEASE_NAME} k8s_log/${env.RELEASE_NAME}/second_deployment || echo 'export log failed'"
  339. echo "upload logs"
  340. sh "tar -zcvf artifacts-${env.RELEASE_NAME}-logs.tar.gz k8s_log/ --remove-files || true"
  341. archiveArtifacts artifacts: "artifacts-${env.RELEASE_NAME}-logs.tar.gz", allowEmptyArchive: true
  342. if ("${params.keep_env}" == "false"){
  343. sh "bash ../chaos/scripts/uninstall_milvus.sh ${env.RELEASE_NAME}"
  344. }
  345. }
  346. }
  347. }
  348. }
  349. success {
  350. echo 'I succeeeded!'
  351. container('main') {
  352. dir ('tests/python_client/chaos/scripts') {
  353. script {
  354. sh "bash uninstall_milvus.sh ${env.RELEASE_NAME} || true"
  355. }
  356. }
  357. }
  358. }
  359. unstable {
  360. echo 'I am unstable :/'
  361. }
  362. failure {
  363. echo 'I failed :('
  364. }
  365. changed {
  366. echo 'Things were different before...'
  367. }
  368. }
  369. }