blob: af013c773cd440d586a9fe11d96135ab5f0b67ba [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrongaf679da2023-01-31 14:22:41 -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// this keyword is dedicated to deploy a single VOLTHA stack with infra
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050018// If you need to deploy different configurations you can use the
19// volthaInfraDeploy and volthaStackDeploy DSL keywords
Joey Armstrongaf679da2023-01-31 14:22:41 -050020// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -080021
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040022// -----------------------------------------------------------------------
23// -----------------------------------------------------------------------
24String getIam(String func) {
25 // Cannot rely on a stack trace due to jenkins manipulation
26 String src = 'vars/volthaDeploy.groovy'
27 String iam = [src, func].join('::')
28 return iam
29}
30
31// -----------------------------------------------------------------------
32// Intent: Log progress message
33// -----------------------------------------------------------------------
34void enter(String name) {
35 // Announce ourselves for log usability
36 String iam = getIam(name)
37 println("${iam}: ENTER")
38 return
39}
40
41// -----------------------------------------------------------------------
42// Intent: Log progress message
43// -----------------------------------------------------------------------
44void leave(String name) {
45 // Announce ourselves for log usability
46 String iam = getIam(name)
47 println("${iam}: LEAVE")
48 return
49}
50
51// -----------------------------------------------------------------------
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050052// Intent: Display a message with visibility for logging
53// -----------------------------------------------------------------------
54String banner(String message) {
Joey Armstrongf0232762024-02-11 17:23:04 -050055 String iam = getIam('banner')
56
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050057 println("""
58
59** -----------------------------------------------------------------------
Joey Armstrongf0232762024-02-11 17:23:04 -050060** IAM: $iam
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050061** ${message}
62** -----------------------------------------------------------------------
63""")
64 return
65}
66
67// -----------------------------------------------------------------------
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040068// Intent: Perform volthaDeploy stuff
69// -----------------------------------------------------------------------
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050070void process(Map config)
71{
Matteo Scandolo42f6e572021-01-25 15:11:34 -080072 // note that I can't define this outside the function as there's no global scope in Groovy
Joey Armstrong96158a92022-11-25 10:36:06 -050073 // [joey] A class method or library call can be used in place of globals, fqdn needed.
Matteo Scandolo42f6e572021-01-25 15:11:34 -080074 def defaultConfig = [
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040075 onosReplica: 1,
76 atomixReplica: 1,
77 kafkaReplica: 1,
78 etcdReplica: 1,
79 bbsimReplica: 1,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050080 infraNamespace : 'infra',
81 volthaNamespace : 'voltha',
82 stackName : 'voltha',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040083 stackId: 1,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050084 workflow : 'att',
Guru4dc382f2025-01-10 18:14:58 +053085 vgcEnabled : false,
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040086 withMacLearning: false,
87 withFttb: false,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050088 extraHelmFlags : '',
89 localCharts: false, // Local or upstream (?) (for local we assume they are stored in $WORKSPACE/voltha-helm-charts)
90 dockerRegistry : '', // Different registry for images eg: "mirror.registry.opennetworking.org"
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040091 kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
92 withVolthaInfra: true,
93 withVolthaStack: true,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080094 ]
95
96 if (!config) {
97 config = [:]
98 }
99
100 def cfg = defaultConfig + config
101
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500102 if (cfg.dockerRegistry != '') {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400103 def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ "
104 registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} "
105 registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} "
106 registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} "
107 registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos "
108 registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix "
109 registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ "
Matteo Scandolo5244aaa2021-04-28 09:28:58 -0700110
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400111 // we want to always leave the user provided flags at the end, to override changes
112 cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags
Matteo Scandolo37f168b2021-04-15 16:20:46 -0700113 }
114
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500115 // ---------------------
116 banner("Updating helm repos")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200117
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400118 sh(label : 'Configure helm repo',
119 script : """
120helm repo add onf https://charts.opencord.org
121helm repo update
122""")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200123
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500124 // ---------------------
125 banner("Deploying VOLTHA with the following parameters: ${cfg}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800126
Hardik Windlass230fca62022-05-04 08:50:35 +0530127 if (cfg.withVolthaInfra) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400128 volthaInfraDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530129 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800130
Hardik Windlass230fca62022-05-04 08:50:35 +0530131 if (cfg.withVolthaStack) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400132 volthaStackDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530133 }
Joey Armstrong96158a92022-11-25 10:36:06 -0500134
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500135 return
136}
137
138// -----------------------------------------------------------------------
139// -----------------------------------------------------------------------
140def call(Map config=[:]) { // Function return type(?)
141 String iam = getIam('main')
142 Boolean ans = true
143
144 try {
145 enter('main')
146 process(config)
147 }
148 catch (Exception err) { // groovylint-disable-line CatchException
149 ans = false
150 println("** ${iam}: EXCEPTION ${err}")
151 throw err
152 }
153 finally {
154 leave('main')
155 }
156
157 return(ans)
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800158}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500159
160// [EOF]