Kailash | 66c389c | 2019-04-24 14:56:11 -0700 | [diff] [blame^] | 1 | // Copyright 2017-present Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // chart-api-test-helm.groovy |
| 16 | // Checks functionality of the helm-chart, without overriding the version/tag used |
| 17 | |
| 18 | pipeline { |
| 19 | |
| 20 | /* no label, executor is determined by JJB */ |
| 21 | agent { |
| 22 | label "${params.executorNode}" |
| 23 | } |
| 24 | |
| 25 | stages { |
| 26 | |
| 27 | stage('repo') { |
| 28 | steps { |
| 29 | checkout(changelog: false, \ |
| 30 | poll: false, |
| 31 | scm: [$class: 'RepoScm', \ |
| 32 | manifestRepositoryUrl: "${params.manifestUrl}", \ |
| 33 | manifestBranch: "${params.manifestBranch}", \ |
| 34 | currentBranch: true, \ |
| 35 | destinationDir: 'cord', \ |
| 36 | forceSync: true, |
| 37 | resetFirst: true, \ |
| 38 | quiet: true, \ |
| 39 | jobs: 4, \ |
| 40 | showAllChanges: true] \ |
| 41 | ) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | stage('patch') { |
| 46 | steps { |
| 47 | sh ''' |
| 48 | pushd cord |
| 49 | PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml) |
| 50 | repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}" |
| 51 | popd |
| 52 | ''' |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | stage('minikube') { |
| 57 | steps { |
| 58 | /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */ |
| 59 | sh ''' |
| 60 | export MINIKUBE_WANTUPDATENOTIFICATION=false |
| 61 | export MINIKUBE_WANTREPORTERRORPROMPT=false |
| 62 | export CHANGE_MINIKUBE_NONE_USER=true |
| 63 | export MINIKUBE_HOME=$HOME |
| 64 | mkdir -p $HOME/.kube || true |
| 65 | touch $HOME/.kube/config |
| 66 | export KUBECONFIG=$HOME/.kube/config |
| 67 | sudo -E /usr/bin/minikube start --vm-driver=none |
| 68 | ''' |
| 69 | script { |
| 70 | timeout(3) { |
| 71 | waitUntil { |
| 72 | sleep 5 |
| 73 | def kc_ret = sh script: "kubectl get po", returnStatus: true |
| 74 | return (kc_ret == 0); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | stage('helm') { |
| 82 | steps { |
| 83 | sh ''' |
| 84 | helm init |
| 85 | sleep 60 |
| 86 | helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/ |
| 87 | ''' |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | stage('Install XOS w/Service') { |
| 92 | steps { |
| 93 | sh """ |
| 94 | #!/usr/bin/env bash |
| 95 | set -eu -o pipefail |
| 96 | |
| 97 | pushd cord/helm-charts |
| 98 | helm dep update xos-core |
| 99 | helm install xos-core -n xos-core |
| 100 | |
| 101 | git clone https://gerrit.opencord.org/helm-repo-tools |
| 102 | helm-repo-tools/wait_for_pods.sh |
| 103 | |
| 104 | #install service |
| 105 | helm dep update xos-services/${gerritProject} |
| 106 | helm install xos-services/${gerritProject} -n ${gerritProject} |
| 107 | popd |
| 108 | """ |
| 109 | } |
| 110 | } |
| 111 | stage('Verify') { |
| 112 | steps { |
| 113 | sh """ |
| 114 | #!/usr/bin/env bash |
| 115 | set -ex -o pipefail |
| 116 | export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION) |
| 117 | |
| 118 | #wait for xos-core and models to be loaded |
| 119 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 120 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 121 | http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq ".services[] | select(.name==\\"core\\").version"| grep -q \$DOCKER_TAG |
| 122 | |
| 123 | ## get pod logs |
| 124 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 125 | do |
| 126 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 127 | done |
| 128 | """ |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | stage('Build/Install New Service') { |
| 133 | steps { |
| 134 | sh """ |
| 135 | #!/usr/bin/env bash |
| 136 | set -eu -o pipefail |
| 137 | pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject} |
| 138 | export DOCKER_TAG=\$(cat VERSION)-test |
| 139 | export DOCKER_REPOSITORY=xosproject/ |
| 140 | export DOCKER_BUILD_ARGS=--no-cache |
| 141 | cd $WORKSPACE/cord/orchestration/xos-services/${gerritProject} |
| 142 | echo "\$(cat VERSION)-test" > VERSION |
| 143 | make docker-build |
| 144 | |
| 145 | #install newservice |
| 146 | cd $WORKSPACE/cord/helm-charts |
| 147 | helm upgrade --set image.tag=\$DOCKER_TAG \ |
| 148 | --set image.pullPolicy=Never \ |
| 149 | --recreate-pods ${gerritProject} xos-services/${gerritProject} |
| 150 | popd |
| 151 | """ |
| 152 | } |
| 153 | } |
| 154 | stage('Verify Service Upgrade') { |
| 155 | steps { |
| 156 | sh """ |
| 157 | #!/usr/bin/env bash |
| 158 | set -ex -o pipefail |
| 159 | DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION) |
| 160 | |
| 161 | #wait for xos-core and models to be loaded |
| 162 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done" |
| 163 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for New Service to be loaded'; sleep 5; done" |
| 164 | timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").version'| grep -q \$DOCKER_TAG; do echo 'Waiting for New Service Version Check'; sleep 5; done" |
| 165 | ## get pod logs |
| 166 | for pod in \$(kubectl get pods --no-headers | awk '{print \$1}'); |
| 167 | do |
| 168 | kubectl logs \$pod> $WORKSPACE/\$pod.log; |
| 169 | done || true |
| 170 | """ |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | post { |
| 175 | always { |
| 176 | sh """ |
| 177 | kubectl get pods --all-namespaces |
| 178 | kubectl describe pods |
| 179 | http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status |
| 180 | echo "# removing helm deployments" |
| 181 | kubectl get pods |
| 182 | helm list |
| 183 | |
| 184 | for hchart in \$(helm list -q); |
| 185 | do |
| 186 | echo "## Purging chart: \${hchart} ##" |
| 187 | helm delete --purge "\${hchart}" |
| 188 | done |
| 189 | |
| 190 | sudo minikube delete |
| 191 | """ |
| 192 | archiveArtifacts artifacts: '*.log' |
| 193 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "kailash@opennetworking.org, scottb@opennetworking.org", sendToIndividuals: false]) |
| 194 | |
| 195 | } |
| 196 | } |
| 197 | } |