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