blob: a397a6dd43ad01622d1c6fa23a43a09ef6a45bc3 [file] [log] [blame]
Vladimir Khlyuneve03b04f2024-04-26 02:57:02 +04001@Library('tcp-qa')_
2
3import groovy.xml.XmlUtil
4
5common = new com.mirantis.mk.Common()
6shared = new com.mirantis.system_qa.SharedPipeline()
7
8NODE_LABEL = "sre-team-infra"
9ENV_NAME = "bm-mcc-mosk"
10ENV_NAME = "vkhlyunev-bm-mosk"
11MAINTENANCE_TEAM_SSH_ID = 'maintenance-team-ssh'
12IPMI_CREDS = 'lab_engineer' // base bm lab
13def seed_ext_ip = '172.16.180.2'
14def kubectl_openstack_cmd = ''
15ssh_params = "-o ConnectTimeout=20 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
16
17timeout(time: 3, unit: 'HOURS') {
18 timestamps {
19 node ("${NODE_LABEL}") {
20 checkout scm
21 shared.update_working_dir()
22 withCredentials(
23 [[$class : 'UsernamePasswordMultiBinding',
24 credentialsId : env.OS_CREDENTIALS,
25 passwordVariable: 'OS_PASSWORD',
26 usernameVariable: 'OS_USERNAME'
27 ]]) {
28 env.OS_IDENTITY_API_VERSION = 3
29 stage("Pre-cleanup: erase BM labs") {
30 // TODO: wipe all bm labs, including MCP1
31 println "Remove heat stack '${ENV_NAME}'"
32 shared.run_cmd("""\
33 openstack stack delete -y ${ENV_NAME} || true
34 timeout 20m /bin/bash -c "while openstack stack show ${ENV_NAME} -f value -c stack_status; do sleep 10; done"
35 """)
36 withCredentials([
37 [$class : 'UsernamePasswordMultiBinding',
38 credentialsId : "${IPMI_CREDS}",
39 passwordVariable: 'IPMI_PASS',
40 usernameVariable: 'IPMI_USER']
41 ]) {
42 env.IPMI_PASS = IPMI_PASS
43 env.IPMI_USER = IPMI_USER
44 shared.reboot_hardware_nodes("${IPMI_CREDS}")
45 } //withCredentials IPMI
46 } //stage
47 stage("Boot seed node's heat stack"){
48 println "Create stack '${ENV_NAME}'"
49 shared.run_cmd("pushd bm_mcc_mosk && openstack stack create --wait -t mcc_seed_2401.yaml --parameter env_name=${ENV_NAME} ${ENV_NAME}")
50 seed_ext_ip = shared.run_cmd_stdout("openstack stack output show ${ENV_NAME} seed_ext_ip -f value -c output_value").trim().split().last()
51 println "SEED IP: '${seed_ext_ip}'"
52 } //stage
53 } //withCredentials OS cloud
54 sshagent(credentials: ['maintenance-team-ssh']) {
55 withCredentials(
56 [[$class: 'SSHUserPrivateKeyBinding',
57 keyFileVariable: "MAINTENANCE_TEAM_SSH_KEY",
58 credentialsId: MAINTENANCE_TEAM_SSH_ID,
59 usernameVariable: "MAINTENANCE_TEAM_SSH_USERNAME"]]) {
60 stage("Bootstrap MCC+child"){
61 sh "scp ${ssh_params} ${MAINTENANCE_TEAM_SSH_KEY} root@${seed_ext_ip}:/root/.ssh/id_rsa "
62 sh "scp -r ${ssh_params} bm_mcc_mosk root@${seed_ext_ip}: "
63 sh "ssh ${ssh_params} root@${seed_ext_ip} bash do_deploy_mcc_mgmt.sh"
64 sh "ssh ${ssh_params} root@${seed_ext_ip} bash do_deploy_child.sh"
65 // TODO: unhardcode cluster names
66 check_child_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/kubeconfig -n mosk get cluster mosk -o jsonpath='{.status.providerStatus.ready}' 2>/dev/null || echo 'ssh error, ignoring'"
67 check_kcc_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/kubeconfig -n mosk get kcc mosk-ceph -o jsonpath='{.status.shortClusterInfo.state}' 2>/dev/null || echo 'ssh error, ignoring'"
68 child_ready = false
69 kcc_ready = false
70 println "Waiting child cluster to become ready..."
71 while(!child_ready){
72 sleep 60
73 status = sh(returnStdout: true, script: "${check_child_cmd}").trim()
74 if (status == "true"){
75 child_ready = true
76 } //if
77 } //while
78 println "Waiting child Ceph cluster to become ready..."
79 while(!kcc_ready){
80 sleep 60
81 status = sh(returnStdout: true, script: "${check_kcc_cmd}").trim()
82 if (status == "Ready"){
83 kcc_ready = true
84 } //if
85 } //while
86 } //stage MCC
87 stage("Prepare and deploy MOSK"){
88 sh "ssh ${ssh_params} root@${seed_ext_ip} '/bin/bash /root/get_child_kubeconfig.sh'"
89 sh "ssh ${ssh_params} root@${seed_ext_ip} '/bin/bash /root/bm_mcc_mosk/utils/tsl_gen.sh'"
90 kubectl_openstack_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n openstack "
91 sh "${kubectl_openstack_cmd} apply -f /root/bm_mcc_mosk/child/kaas_workloads/osdpl-ssl-secrets.yaml"
92 sh "${kubectl_openstack_cmd} apply -f /root/bm_mcc_mosk/child/kaas_workloads/osdpl.yaml"
93 mosk_check_cmd = "${kubectl_openstack_cmd} get osdplst osh-dev -o jsonpath='{.status.osdpl.state}'"
94 mosk_ready = false
95 while(!mosk_ready){
96 sleep 60
97 status = sh(returnStdout: true, script: "${mosk_check_cmd}").trim()
98 if (status == "APPLIED"){
99 mosk_ready = true
100 } //if
101 } //while
102 } //stage MOSK
103 stage("Configure DNS server") {
104 get_ingress_ip_cmd = "${kubectl_openstack_cmd} get service ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}'"
105 get_dns_internal_ip_cmd = "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n coredns get service coredns-coredns -o jsonpath='{.spec.clusterIP}'"
106 ingress_ip = sh(returnStdout: true, script: get_ingress_ip_cmd).trim()
107 sh "ssh ${ssh_params} root@${seed_ext_ip} sed -i 's/!!!EXT_DNS_IP/${ingress_ip}/g' /root/bm_mcc_mosk/child/kaas_workloads/coredns.yaml"
108 sh "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig apply -f /root/bm_mcc_mosk/child/kaas_workloads/coredns.yaml"
109 sleep 120
110 dns_internal_ip = sh(returnStdout: true, script: get_dns_internal_ip_cmd).trim()
111 sh "ssh ${ssh_params} root@${seed_ext_ip} \"/root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig -n kube-system get configmap coredns -oyaml > coredns.conf\""
112 sh "ssh ${ssh_params} root@${seed_ext_ip} /usr/bin/python3 /root/bm_mcc_mosk/utils/update_kube_dns_conf.py ${dns_internal_ip}"
113 sh "ssh ${ssh_params} root@${seed_ext_ip} /root/kaas-bootstrap/bin/kubectl --kubeconfig /root/child.kubeconfig apply -f coredns.patched.conf"
114
115 } // stage DNS
116 } //withCredentials
117 } //sshagent
118 } //node
119 } //timestamps
120} //timeout