blob: defcaf65b7a71055db32ed393706000833087200 [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',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040085 withMacLearning: false,
86 withFttb: false,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050087 extraHelmFlags : '',
88 localCharts: false, // Local or upstream (?) (for local we assume they are stored in $WORKSPACE/voltha-helm-charts)
89 dockerRegistry : '', // Different registry for images eg: "mirror.registry.opennetworking.org"
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040090 kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
91 withVolthaInfra: true,
92 withVolthaStack: true,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080093 ]
94
95 if (!config) {
96 config = [:]
97 }
98
99 def cfg = defaultConfig + config
100
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500101 if (cfg.dockerRegistry != '') {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400102 def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ "
103 registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} "
104 registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} "
105 registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} "
106 registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos "
107 registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix "
108 registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ "
Matteo Scandolo5244aaa2021-04-28 09:28:58 -0700109
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400110 // we want to always leave the user provided flags at the end, to override changes
111 cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags
Matteo Scandolo37f168b2021-04-15 16:20:46 -0700112 }
113
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500114 // ---------------------
115 banner("Updating helm repos")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200116
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400117 sh(label : 'Configure helm repo',
118 script : """
119helm repo add onf https://charts.opencord.org
120helm repo update
121""")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200122
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500123 // ---------------------
124 banner("Deploying VOLTHA with the following parameters: ${cfg}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800125
Hardik Windlass230fca62022-05-04 08:50:35 +0530126 if (cfg.withVolthaInfra) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400127 volthaInfraDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530128 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800129
Hardik Windlass230fca62022-05-04 08:50:35 +0530130 if (cfg.withVolthaStack) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400131 volthaStackDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530132 }
Joey Armstrong96158a92022-11-25 10:36:06 -0500133
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500134 return
135}
136
137// -----------------------------------------------------------------------
138// -----------------------------------------------------------------------
139def call(Map config=[:]) { // Function return type(?)
140 String iam = getIam('main')
141 Boolean ans = true
142
143 try {
144 enter('main')
145 process(config)
146 }
147 catch (Exception err) { // groovylint-disable-line CatchException
148 ans = false
149 println("** ${iam}: EXCEPTION ${err}")
150 throw err
151 }
152 finally {
153 leave('main')
154 }
155
156 return(ans)
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800157}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500158
159// [EOF]