Tomáš Kukrál | e8ebe79 | 2017-01-09 10:24:00 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Launch heat stack with basic k8s |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * HEAT_TEMPLATE_URL URL to git repo with Heat templates |
| 7 | * HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo |
| 8 | * HEAT_TEMPLATE_BRANCH Heat templates repo branch |
| 9 | * OPENSTACK_API_URL OpenStack API address |
| 10 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 11 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 12 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 13 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
| 14 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 15 | * HEAT_STACK_NAME Heat stack name |
| 16 | * HEAT_STACK_TEMPLATE Heat stack HOT template |
| 17 | * HEAT_STACK_ENVIRONMENT Heat stack environmental parameters |
| 18 | * HEAT_STACK_ZONE Heat stack availability zone |
| 19 | * HEAT_STACK_PUBLIC_NET Heat stack floating IP pool |
| 20 | */ |
| 21 | |
| 22 | git = new com.mirantis.mk.git() |
| 23 | openstack = new com.mirantis.mk.openstack() |
| 24 | salt = new com.mirantis.mk.salt() |
| 25 | |
| 26 | node { |
| 27 | |
| 28 | // connection objects |
| 29 | def openstackCloud |
| 30 | def saltMaster |
| 31 | |
| 32 | // value defaults |
| 33 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : "liberty" |
| 34 | def openstackEnv = "${env.WORKSPACE}/venv" |
| 35 | |
Tomáš Kukrál | 00c7bf4 | 2017-01-13 13:27:23 +0100 | [diff] [blame] | 36 | if (HEAT_STACK_NAME == "") { |
Tomáš Kukrál | 25b9e67 | 2017-01-13 13:47:50 +0100 | [diff] [blame] | 37 | HEAT_STACK_NAME = JOB_NAME + "-b" + BUILD_NUMBER |
Tomáš Kukrál | 00c7bf4 | 2017-01-13 13:27:23 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Tomáš Kukrál | e8ebe79 | 2017-01-09 10:24:00 +0100 | [diff] [blame] | 40 | stage ('Download Heat templates') { |
| 41 | git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS) |
| 42 | } |
| 43 | |
| 44 | stage('Install OpenStack env') { |
| 45 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
| 46 | } |
| 47 | |
| 48 | stage('Connect to OpenStack cloud') { |
| 49 | openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT) |
| 50 | openstack.getKeystoneToken(openstackCloud, openstackEnv) |
| 51 | } |
| 52 | |
| 53 | stage('Launch new Heat stack') { |
| 54 | envParams = [ |
| 55 | 'availability_zone': HEAT_STACK_ZONE, |
| 56 | 'public_net': HEAT_STACK_PUBLIC_NET |
| 57 | ] |
| 58 | openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv) |
| 59 | } |
| 60 | |
| 61 | stage("Connect to Salt master") { |
| 62 | saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv) |
| 63 | saltMasterUrl = "http://${saltMasterHost}:8000" |
| 64 | saltMaster = salt.createSaltConnection(saltMasterUrl, SALT_MASTER_CREDENTIALS) |
| 65 | } |
| 66 | |
| 67 | stage("Install core infra") { |
| 68 | salt.installFoundationInfra(saltMaster) |
| 69 | salt.validateFoundationInfra(saltMaster) |
| 70 | } |
| 71 | |
| 72 | stage("Install Kubernetes infra") { |
| 73 | salt.installOpenstackMcpInfra(saltMaster) |
| 74 | } |
| 75 | |
| 76 | stage("Install Kubernetes control") { |
| 77 | salt.installOpenstackMcpControl(saltMaster) |
| 78 | } |
| 79 | |
| 80 | //stage("Install Kubernetes compute") { |
| 81 | // salt.installOpenstackMcpCompute(saltMaster) |
| 82 | //} |
| 83 | |
Tomáš Kukrál | aba0a7d | 2017-01-13 14:05:12 +0100 | [diff] [blame^] | 84 | stage('Trigger cleanup job') { |
Tomáš Kukrál | e8ebe79 | 2017-01-09 10:24:00 +0100 | [diff] [blame] | 85 | // openstack.deleteHeatStack(openstackCloud, HEAT_STACK_NAME, openstackEnv) |
Tomáš Kukrál | aba0a7d | 2017-01-13 14:05:12 +0100 | [diff] [blame^] | 86 | build job: 'mk-k8s-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]] |
| 87 | } |
Tomáš Kukrál | e8ebe79 | 2017-01-09 10:24:00 +0100 | [diff] [blame] | 88 | |
| 89 | } |