forked from Mirantis/mk-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk-k8s-simple-deploy-pipeline.groovy
129 lines (110 loc) · 5.13 KB
/
mk-k8s-simple-deploy-pipeline.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* DO NOT USE THIS OUTDATED PIPELINE - add your steps to lab-pipeline
*
* Launch heat stack with basic k8s
*
* Expected parameters:
* HEAT_TEMPLATE_URL URL to git repo with Heat templates
* HEAT_TEMPLATE_CREDENTIALS Credentials to the Heat templates repo
* HEAT_TEMPLATE_BRANCH Heat templates repo branch
* OPENSTACK_API_URL OpenStack API address
* OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API
* OPENSTACK_API_PROJECT OpenStack project to connect to
* OPENSTACK_API_CLIENT Versions of OpenStack python clients
* OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
* SALT_MASTER_CREDENTIALS Credentials to the Salt API
* HEAT_STACK_NAME Heat stack name
* HEAT_STACK_TEMPLATE Heat stack HOT template
* HEAT_STACK_ENVIRONMENT Heat stack environmental parameters
* HEAT_STACK_ZONE Heat stack availability zone
* HEAT_STACK_PUBLIC_NET Heat stack floating IP pool
* CONFORMANCE_IMAGE Path to docker image with conformance e2e tests
* K8S_API_SERVER Kubernetes API address
* RUN_TESTS Run test (0/1)
* HEAT_STACK_DELETE Delete Heat stack when finished (0/1)
*/
git = new com.mirantis.mk.Git()
openstack = new com.mirantis.mk.Openstack()
salt = new com.mirantis.mk.Salt()
orchestrate = new com.mirantis.mk.Orchestrate()
test = new com.mirantis.mk.Test()
def python = new com.mirantis.mk.Python()
artifacts_dir = "_artifacts"
timeout(time: 12, unit: 'HOURS') {
node {
// connection objects
def openstackCloud
// value defaults
def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
def workspace = common.getWorkspace()
def openstackEnv = "${workspace}/venv"
def pepperEnv = "${workspace}/pepperEnv"
if (HEAT_STACK_NAME == "") {
HEAT_STACK_NAME = BUILD_TAG
}
stage ('Download Heat templates') {
git.checkoutGitRepository('template', HEAT_TEMPLATE_URL, HEAT_TEMPLATE_BRANCH, HEAT_TEMPLATE_CREDENTIALS)
}
stage('Install OpenStack env') {
openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
}
stage('Connect to OpenStack cloud') {
openstackCloud = openstack.createOpenstackEnv(openstackEnv, OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT,
"", OPENSTACK_API_PROJECT_DOMAIN_ID, OPENSTACK_API_USER_DOMAIN_ID, OPENSTACK_API_VERSION)
openstack.getKeystoneToken(openstackCloud, openstackEnv)
}
stage('Launch new Heat stack') {
envParams = [
'instance_zone': HEAT_STACK_ZONE,
'public_net': HEAT_STACK_PUBLIC_NET
]
openstack.createHeatStack(openstackCloud, HEAT_STACK_NAME, HEAT_STACK_TEMPLATE, envParams, HEAT_STACK_ENVIRONMENT, openstackEnv)
}
stage("Connect to Salt master") {
saltMasterHost = openstack.getHeatStackOutputParam(openstackCloud, HEAT_STACK_NAME, 'salt_master_ip', openstackEnv)
saltMasterUrl = "http://${saltMasterHost}:8088"
python.setupPepperVirtualenv(pepperEnv, saltMasterUrl, SALT_MASTER_CREDENTIALS)
}
stage("Install core infra") {
orchestrate.installFoundationInfra(pepperEnv)
orchestrate.validateFoundationInfra(pepperEnv)
}
stage("Install Kubernetes infra") {
orchestrate.installOpenstackMcpInfra(pepperEnv)
}
stage("Install Kubernetes control") {
orchestrate.installOpenstackMcpControl(pepperEnv)
}
if (RUN_TESTS == "1") {
sleep(30)
stage('Run k8s bootstrap tests') {
test.runConformanceTests(pepperEnv, 'ctl01*', K8S_API_SERVER, 'tomkukral/k8s-scripts')
}
stage("Run k8s conformance e2e tests") {
test.runConformanceTests(pepperEnv, 'ctl01*', K8S_API_SERVER, CONFORMANCE_IMAGE)
}
stage("Copy k8s e2e test output to config node ") {
test.copyTestsOutput(pepperEnv,CONFORMANCE_IMAGE)
}
stage("Copy k8s e2e test output to host ") {
sh '''
mkdir ${env.WORKSPACE}/${artifacts_dir}
'''
try {
test.catTestsOutput(pepperEnv,CONFORMANCE_IMAGE) >> ${env.WORKSPACE}/${artifacts_dir}/$CONFORMANCE_IMAGE
} catch (InterruptedException x) {
echo "The job was aborted"
} finally {
archiveArtifacts allowEmptyArchive: true, artifacts: '_artifacts/*', excludes: null
junit keepLongStdio: true, testResults: '_artifacts/**.xml'
sh "sudo chown -R jenkins:jenkins ${env.WORKSPACE}"
}
}
}
if (HEAT_STACK_DELETE == "1") {
stage('Trigger cleanup job') {
build job: 'mk-k8s-cleanup', parameters: [[$class: 'StringParameterValue', name: 'HEAT_STACK_NAME', value: HEAT_STACK_NAME]]
}
}
}
}