DeployTestKafkaMQ.groovy 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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: 'Milvus Mode',
  18. name: 'milvus_mode',
  19. choices: ["standalone", "cluster"]
  20. )
  21. choice(
  22. description: 'MQ Type',
  23. name: 'mq_type',
  24. choices: ["kafka"]
  25. )
  26. choice(
  27. description: 'Deploy Test Task',
  28. name: 'deploy_task',
  29. choices: ['reinstall']
  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. // disable all mq
  121. sh "yq -i '.kafka.enabled = false' cluster-values.yaml"
  122. sh "yq -i '.pulsar.enabled = false' cluster-values.yaml"
  123. // enable mq_type
  124. if ("${params.mq_type}" == "pulsar") {
  125. sh "yq -i '.pulsar.enabled = true' cluster-values.yaml"
  126. } else if ("${params.mq_type}" == "kafka") {
  127. sh "yq -i '.kafka.enabled = true' cluster-values.yaml"
  128. sh "yq -i '.kafka.enabled = true' standalone-values.yaml"
  129. }
  130. sh"""
  131. yq -i '.queryNode.replicas = "${params.querynode_nums}"' cluster-values.yaml
  132. yq -i '.dataNode.replicas = "${params.datanode_nums}"' cluster-values.yaml
  133. yq -i '.indexNode.replicas = "${params.indexnode_nums}"' cluster-values.yaml
  134. yq -i '.proxy.replicas = "${params.proxy_nums}"' cluster-values.yaml
  135. """
  136. if ("${params.milvus_mode}" == "cluster"){
  137. sh "cat cluster-values.yaml"
  138. }
  139. if ("${params.mq_type}" == "standalone"){
  140. sh "cat standalone-values.yaml"
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. stage ('First Milvus Deployment') {
  148. options {
  149. timeout(time: 10, unit: 'MINUTES') // timeout on this stage
  150. }
  151. steps {
  152. container('main') {
  153. dir ('tests/python_client/deploy') {
  154. script {
  155. def old_image_tag_modified = ""
  156. def new_image_tag_modified = ""
  157. def old_image_repository_modified = ""
  158. def new_image_repository_modified = ""
  159. if ("${params.old_image_tag}" == "master-latest") {
  160. 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()
  161. }
  162. else if ("${params.old_image_tag}" == "latest") {
  163. old_image_tag_modified = sh(returnStdout: true, script: 'bash ../../../scripts/docker_image_find_tag.sh -n milvusdb/milvus -t latest -F -L -q').trim()
  164. }
  165. else {
  166. old_image_tag_modified = "${params.old_image_tag}"
  167. }
  168. if ("${params.new_image_tag}" == "master-latest") {
  169. 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()
  170. }
  171. else {
  172. new_image_tag_modified = "${params.new_image_tag}"
  173. }
  174. sh "echo ${old_image_tag_modified}"
  175. sh "echo ${new_image_tag_modified}"
  176. sh "echo ${new_image_tag_modified} > new_image_tag_modified.txt"
  177. stash includes: 'new_image_tag_modified.txt', name: 'new_image_tag_modified'
  178. env.new_image_tag_modified = new_image_tag_modified
  179. if ("${params.deploy_task}" == "reinstall"){
  180. echo "reinstall Milvus with new image tag"
  181. old_image_tag_modified = new_image_tag_modified
  182. }
  183. if ("${params.deploy_task}" == "reinstall"){
  184. echo "reinstall Milvus with new image repository"
  185. old_image_repository_modified = "${params.new_image_repository}"
  186. }
  187. else {
  188. old_image_repository_modified = "${params.old_image_repository}"
  189. }
  190. sh "helm repo add milvus https://zilliztech.github.io/milvus-helm"
  191. sh "helm repo update"
  192. if ("${params.milvus_mode}" == "standalone") {
  193. 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;"
  194. }
  195. if ("${params.milvus_mode}" == "cluster") {
  196. 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;"
  197. }
  198. sh "kubectl wait --for=condition=Ready pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  199. sh "kubectl wait --for=condition=Ready pod -l release=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  200. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME}"
  201. }
  202. }
  203. }
  204. }
  205. }
  206. stage ('Run first test') {
  207. options {
  208. timeout(time: 20, unit: 'MINUTES') // timeout on this stage
  209. }
  210. steps {
  211. container('main') {
  212. dir ('tests/python_client/deploy') {
  213. script {
  214. def host = sh(returnStdout: true, script: "kubectl get svc/${env.RELEASE_NAME}-milvus -o jsonpath=\"{.spec.clusterIP}\"").trim()
  215. if ("${params.deploy_task}" == "reinstall") {
  216. sh "python3 scripts/action_before_reinstall.py --host ${host} --data_size ${params.data_size}"
  217. }
  218. if ("${params.deploy_task}" == "upgrade") {
  219. sh "python3 scripts/action_before_upgrade.py --host ${host} --data_size ${params.data_size}"
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. stage ('Milvus Idle Time') {
  227. steps {
  228. container('main') {
  229. dir ('tests/python_client/deploy') {
  230. script {
  231. echo "sleep ${params.idel_time}m"
  232. sh "sleep ${params.idel_time}m"
  233. }
  234. }
  235. }
  236. }
  237. }
  238. stage ('Export log for first deployment') {
  239. steps {
  240. container('main') {
  241. dir ('tests/python_client/deploy') {
  242. script {
  243. echo "get pod status"
  244. sh "kubectl get pods -o wide|grep ${env.RELEASE_NAME} || true"
  245. echo "collecte logs"
  246. sh "bash ../../scripts/export_log_k8s.sh ${env.NAMESPACE} ${env.RELEASE_NAME} k8s_log/${env.RELEASE_NAME}/first_deployment || echo 'export log failed'"
  247. }
  248. }
  249. }
  250. }
  251. }
  252. stage ('Uninstall Milvus') {
  253. options {
  254. timeout(time: 15, unit: 'MINUTES') // timeout on this stage
  255. }
  256. steps {
  257. container('main') {
  258. dir ('tests/python_client/deploy') {
  259. script {
  260. if ("${params.milvus_mode}" == "standalone") {
  261. sh "kubectl delete pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} --grace-period=0 --force"
  262. sh "kubectl delete pod -l release=${env.RELEASE_NAME} --grace-period=0 --force"
  263. sh "kubectl wait --for=condition=Ready pod -l app.kubernetes.io/instance=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  264. sh "kubectl wait --for=condition=Ready pod -l release=${env.RELEASE_NAME} -n ${env.NAMESPACE} --timeout=360s"
  265. }
  266. if ("${params.milvus_mode}" == "cluster") {
  267. sh "helm uninstall ${env.RELEASE_NAME}"
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. stage ('Second Milvus Deployment') {
  275. options {
  276. timeout(time: 15, unit: 'MINUTES') // timeout on this stage
  277. }
  278. steps {
  279. container('main') {
  280. dir ('tests/python_client/deploy') {
  281. script {
  282. // 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
  283. def new_image_tag_modified = ""
  284. dir ("new_image_tag_modified"){
  285. try{
  286. unstash 'new_image_tag_modified'
  287. new_image_tag_modified=sh(returnStdout: true, script: 'cat new_image_tag_modified.txt | tr -d \'\n\r\'')
  288. }catch(e){
  289. print "No image tag info remained"
  290. exit 1
  291. }
  292. }
  293. if ("${params.milvus_mode}" == "standalone") {
  294. 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"
  295. }
  296. if ("${params.milvus_mode}" == "cluster") {
  297. 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"
  298. }
  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: 20, 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/chaos') {
  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 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. }