blob: 773cbb090e1220da9c9885a910bdf15f75cb7460 [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrong7987c112022-12-05 12:42:43 -05002// -----------------------------------------------------------------------
Joey Armstrong518f3572024-02-11 07:56:25 -05003// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongaf679da2023-01-31 14:22:41 -05004//
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 Scandolo42f6e572021-01-25 15:11:34 -080017// usage
18//
19// stage('test stage') {
20// steps {
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040021// volthaDeploy([onosReplica: 3])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080022// }
23// }
Joey Armstrong7987c112022-12-05 12:42:43 -050024// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -080025
Joey Armstrong7987c112022-12-05 12:42:43 -050026// -----------------------------------------------------------------------
27// -----------------------------------------------------------------------
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040028String getIam(String func) {
Joey Armstrong7987c112022-12-05 12:42:43 -050029 // 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 Armstrong96158a92022-11-25 10:36:06 -050034
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040035// -----------------------------------------------------------------------
36// Intent: Log progress message
37// -----------------------------------------------------------------------
38void 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// -----------------------------------------------------------------------
48void leave(String name) {
49 // Announce ourselves for log usability
50 String iam = getIam(name)
51 println("${iam}: LEAVE")
52 return
53}
54
Joey Armstrong7987c112022-12-05 12:42:43 -050055// -----------------------------------------------------------------------
56// Intent: Display and interact with kubernetes namespaces.
57// -----------------------------------------------------------------------
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040058void doKubeNamespaces() {
59 String iam = 'doKubeNamespaces'
60 enter(iam)
Joey Armstrong7987c112022-12-05 12:42:43 -050061
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 Armstrongc33a0bf2023-09-08 14:41:23 -040069 o A special case exists (create namespace)
70 o helm upgrade --install (inital update)
Joey Armstrong7987c112022-12-05 12:42:43 -050071 */
72
Joey Armstrong1cf25302022-12-06 09:51:03 -050073 sh('kubectl get namespaces || true')
Joey Armstrong7987c112022-12-05 12:42:43 -050074
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040075 leave(iam)
Joey Armstrong7987c112022-12-05 12:42:43 -050076 return
77}
78
79// -----------------------------------------------------------------------
80// -----------------------------------------------------------------------
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040081void process(Map config) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040082 enter('process')
Joey Armstrong7987c112022-12-05 12:42:43 -050083
Matteo Scandolo42f6e572021-01-25 15:11:34 -080084 // NOTE use params or directule extraHelmFlags??
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040085 Map defaultConfig = [
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040086 onosReplica: 1,
87 atomixReplica: 1,
88 kafkaReplica: 1,
89 etcdReplica: 1,
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040090 infraNamespace: 'infra',
91 workflow: 'att',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040092 withMacLearning: false,
93 withFttb: false,
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040094 extraHelmFlags: '',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040095 localCharts: false,
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -040096 // location of the kubernetes config file,
97 // if null we assume it's stored in the $KUBECONFIG
98 kubeconfig: null,
Jan Klareb4789282024-11-15 13:19:10 +010099 cluster: 'local'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800100 ]
101
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400102 Map cfg = defaultConfig + config
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800103
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400104 def volthaInfraChart = 'onf/voltha-infra'
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800105
106 if (cfg.localCharts) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400107 volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800108
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400109 sh(label : 'HELM: Update deps',
110 script : """
111pushd $WORKSPACE/voltha-helm-charts/voltha-infra
112helm dep update
113popd
114""")
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800115 }
116
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800117 println "Deploying VOLTHA Infra with the following parameters: ${cfg}."
118
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700119 def kubeconfig = cfg.kubeconfig
120 if (kubeconfig == null) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400121 kubeconfig = env.KUBECONFIG
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700122 }
123
Joey Armstrong7987c112022-12-05 12:42:43 -0500124 doKubeNamespaces() // WIP: joey
Joey Armstrong96158a92022-11-25 10:36:06 -0500125
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400126 sh(label : 'KUBE: Create namespace',
127 script : """
128kubectl create namespace ${cfg.infraNamespace} || true
129kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}" || true
130""")
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700131
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400132 String serviceConfigFile = cfg.workflow
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000133 if (cfg.withMacLearning && cfg.workflow == 'tt') {
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400134 serviceConfigFile = 'tt-maclearner'
Hardik Windlassc97ceae2022-05-13 10:12:55 +0530135 } else if (cfg.withFttb && cfg.workflow == 'dt') {
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400136 serviceConfigFile = 'dt-fttb'
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000137 }
138
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700139 // bitnamic/etch has change the replica format between the currently used 5.4.2 and the latest 6.2.5
140 // for now put both values in the extra helm chart flags
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400141 sh(label : 'HELM: upgrade --install',
142 script : """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -0700143 helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \
Matteo Scandolo660e4af2021-04-02 11:16:09 -0700144 --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \
Matteo Scandolod43bb302021-04-20 10:19:29 -0700145 --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \
146 --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700147 --set etcd.replicaCount=${cfg.etcdReplica} \
Roger Luethi2403ef02023-09-27 06:27:22 +0200148 --set etcd.ingress.enabled=true \
Jan Klareb4789282024-11-15 13:19:10 +0100149 --set etcd.ingress.hosts[0].host=voltha-infra.${cfg.cluster} \
150 --set etcd.ingress.hosts[0].paths[0]='/etcdserverpb.KV/' \
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000151 -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags}
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400152""")
Joey Armstrong96158a92022-11-25 10:36:06 -0500153
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400154 leave('process')
Joey Armstrong7987c112022-12-05 12:42:43 -0500155 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800156}
Joey Armstrong7987c112022-12-05 12:42:43 -0500157
158// -----------------------------------------------------------------------
159// -----------------------------------------------------------------------
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400160def call(Map config=[:]) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400161 enter('main')
Joey Armstrong7987c112022-12-05 12:42:43 -0500162
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400163 try {
164 process(config)
Joey Armstrong7987c112022-12-05 12:42:43 -0500165 }
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400166 catch (Exception err) { // groovylint-disable-line CatchException
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400167 String iam = getIam(name)
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400168 println("** ${iam}: EXCEPTION ${err}")
169 throw err
Joey Armstrong7987c112022-12-05 12:42:43 -0500170 }
Joey Armstrong6ee5c7b2023-09-27 15:23:50 -0400171 finally {
172 leave('main')
Joey Armstrong7987c112022-12-05 12:42:43 -0500173 }
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400174
Joey Armstrong7987c112022-12-05 12:42:43 -0500175 return
176}
177
178// [EOF]