Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 17 | // usage |
| 18 | // |
| 19 | // stage('test stage') { |
| 20 | // steps { |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 21 | // volthaDeploy([onosReplica: 3]) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 22 | // } |
| 23 | // } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 24 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 25 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 26 | // ----------------------------------------------------------------------- |
| 27 | // ----------------------------------------------------------------------- |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 28 | String getIam(String func) { |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 29 | // Cannot rely on a stack trace due to jenkins manipulation |
| 30 | String src = 'vars/volthaInfraDeploy.groovy' |
| 31 | String iam = [src, func].join('::') |
| 32 | return iam |
| 33 | } |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 34 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 35 | // ----------------------------------------------------------------------- |
| 36 | // Intent: Log progress message |
| 37 | // ----------------------------------------------------------------------- |
| 38 | void enter(String name) { |
| 39 | // Announce ourselves for log usability |
| 40 | String iam = getIam(name) |
| 41 | println("${iam}: ENTER") |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | // ----------------------------------------------------------------------- |
| 46 | // Intent: Log progress message |
| 47 | // ----------------------------------------------------------------------- |
| 48 | void leave(String name) { |
| 49 | // Announce ourselves for log usability |
| 50 | String iam = getIam(name) |
| 51 | println("${iam}: LEAVE") |
| 52 | return |
| 53 | } |
| 54 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 55 | // ----------------------------------------------------------------------- |
| 56 | // Intent: Display and interact with kubernetes namespaces. |
| 57 | // ----------------------------------------------------------------------- |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 58 | void doKubeNamespaces() { |
| 59 | String iam = 'doKubeNamespaces' |
| 60 | enter(iam) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | [joey] - should pre-existing hint the env is tainted (?) |
| 64 | 05:24:57 + kubectl create namespace infra |
| 65 | 05:24:57 Error from server (AlreadyExists): namespaces "infra" already exists |
| 66 | 05:24:57 error: failed to create configmap: configmaps "kube-config" already exists |
| 67 | |
| 68 | [joey] Thinking we should: |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 69 | o A special case exists (create namespace) |
| 70 | o helm upgrade --install (inital update) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 71 | */ |
| 72 | |
Joey Armstrong | 1cf2530 | 2022-12-06 09:51:03 -0500 | [diff] [blame] | 73 | sh('kubectl get namespaces || true') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 74 | |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 75 | leave(iam) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 76 | return |
| 77 | } |
| 78 | |
| 79 | // ----------------------------------------------------------------------- |
| 80 | // ----------------------------------------------------------------------- |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 81 | void process(Map config) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 82 | enter('process') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 83 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 84 | // NOTE use params or directule extraHelmFlags?? |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 85 | Map defaultConfig = [ |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 86 | onosReplica: 1, |
| 87 | atomixReplica: 1, |
| 88 | kafkaReplica: 1, |
| 89 | etcdReplica: 1, |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 90 | infraNamespace: 'infra', |
| 91 | workflow: 'att', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 92 | withMacLearning: false, |
| 93 | withFttb: false, |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 94 | extraHelmFlags: '', |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 95 | localCharts: false, |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 96 | // location of the kubernetes config file, |
| 97 | // if null we assume it's stored in the $KUBECONFIG |
| 98 | kubeconfig: null, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 99 | ] |
| 100 | |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 101 | Map cfg = defaultConfig + config |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 102 | |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 103 | def volthaInfraChart = 'onf/voltha-infra' |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 104 | |
| 105 | if (cfg.localCharts) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 106 | volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 107 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 108 | sh(label : 'HELM: Update deps', |
| 109 | script : """ |
| 110 | pushd $WORKSPACE/voltha-helm-charts/voltha-infra |
| 111 | helm dep update |
| 112 | popd |
| 113 | """) |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 116 | println "Deploying VOLTHA Infra with the following parameters: ${cfg}." |
| 117 | |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 118 | def kubeconfig = cfg.kubeconfig |
| 119 | if (kubeconfig == null) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 120 | kubeconfig = env.KUBECONFIG |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 123 | doKubeNamespaces() // WIP: joey |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 124 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 125 | sh(label : 'KUBE: Create namespace', |
| 126 | script : """ |
| 127 | kubectl create namespace ${cfg.infraNamespace} || true |
| 128 | kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}" || true |
| 129 | """) |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 130 | |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 131 | String serviceConfigFile = cfg.workflow |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 132 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 133 | serviceConfigFile = 'tt-maclearner' |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 134 | } else if (cfg.withFttb && cfg.workflow == 'dt') { |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 135 | serviceConfigFile = 'dt-fttb' |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 138 | // bitnamic/etch has change the replica format between the currently used 5.4.2 and the latest 6.2.5 |
| 139 | // for now put both values in the extra helm chart flags |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 140 | sh(label : 'HELM: upgrade --install', |
| 141 | script : """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 142 | helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \ |
Matteo Scandolo | 660e4af | 2021-04-02 11:16:09 -0700 | [diff] [blame] | 143 | --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \ |
Matteo Scandolo | d43bb30 | 2021-04-20 10:19:29 -0700 | [diff] [blame] | 144 | --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \ |
| 145 | --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \ |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 146 | --set etcd.replicaCount=${cfg.etcdReplica} \ |
Roger Luethi | 2403ef0 | 2023-09-27 06:27:22 +0200 | [diff] [blame] | 147 | --set etcd.ingress.enabled=true \ |
| 148 | --set etcd.ingress.enableVirtualHosts=true \ |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 149 | -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags} |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 150 | """) |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 151 | |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 152 | leave('process') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 153 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 154 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 155 | |
| 156 | // ----------------------------------------------------------------------- |
| 157 | // ----------------------------------------------------------------------- |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 158 | def call(Map config=[:]) { |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 159 | enter('main') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 160 | |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 161 | try { |
| 162 | process(config) |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 163 | } |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 164 | catch (Exception err) { // groovylint-disable-line CatchException |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 165 | String iam = getIam(name) |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 166 | println("** ${iam}: EXCEPTION ${err}") |
| 167 | throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 168 | } |
Joey Armstrong | 6ee5c7b | 2023-09-27 15:23:50 -0400 | [diff] [blame] | 169 | finally { |
| 170 | leave('main') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 171 | } |
Joey Armstrong | c33a0bf | 2023-09-08 14:41:23 -0400 | [diff] [blame] | 172 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 173 | return |
| 174 | } |
| 175 | |
| 176 | // [EOF] |