blob: 1d83306977bac365beb0222c11f06115d5c46ec7 [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) {
55 println("""
56
57** -----------------------------------------------------------------------
58** ${message}
59** -----------------------------------------------------------------------
60""")
61 return
62}
63
64// -----------------------------------------------------------------------
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040065// Intent: Perform volthaDeploy stuff
66// -----------------------------------------------------------------------
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050067void process(Map config)
68{
Matteo Scandolo42f6e572021-01-25 15:11:34 -080069 // 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 -050070 // [joey] A class method or library call can be used in place of globals, fqdn needed.
Matteo Scandolo42f6e572021-01-25 15:11:34 -080071 def defaultConfig = [
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040072 onosReplica: 1,
73 atomixReplica: 1,
74 kafkaReplica: 1,
75 etcdReplica: 1,
76 bbsimReplica: 1,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050077 infraNamespace : 'infra',
78 volthaNamespace : 'voltha',
79 stackName : 'voltha',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040080 stackId: 1,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050081 workflow : 'att',
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040082 withMacLearning: false,
83 withFttb: false,
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050084 extraHelmFlags : '',
85 localCharts: false, // Local or upstream (?) (for local we assume they are stored in $WORKSPACE/voltha-helm-charts)
86 dockerRegistry : '', // Different registry for images eg: "mirror.registry.opennetworking.org"
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040087 kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
88 withVolthaInfra: true,
89 withVolthaStack: true,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080090 ]
91
92 if (!config) {
93 config = [:]
94 }
95
96 def cfg = defaultConfig + config
97
Joey Armstrong7f6c2c02024-02-11 14:15:24 -050098 if (cfg.dockerRegistry != '') {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -040099 def registryFlags = " --set global.image_registry=${cfg.dockerRegistry}/ "
100 registryFlags += " --set etcd.image.registry=${cfg.dockerRegistry} "
101 registryFlags += " --set kafka.image.registry=${cfg.dockerRegistry} "
102 registryFlags += " --set kafka.zookeper.image.registry=${cfg.dockerRegistry} "
103 registryFlags += " --set onos-classic.image.repository=${cfg.dockerRegistry}/voltha/voltha-onos "
104 registryFlags += " --set onos-classic.atomix.image.repository=${cfg.dockerRegistry}/atomix/atomix "
105 registryFlags += " --set freeradius.images.radius.registry=${cfg.dockerRegistry}/ "
Matteo Scandolo5244aaa2021-04-28 09:28:58 -0700106
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400107 // we want to always leave the user provided flags at the end, to override changes
108 cfg.extraHelmFlags = registryFlags + " " + cfg.extraHelmFlags
Matteo Scandolo37f168b2021-04-15 16:20:46 -0700109 }
110
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500111 // ---------------------
112 banner("Updating helm repos")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200113
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400114 sh(label : 'Configure helm repo',
115 script : """
116helm repo add onf https://charts.opencord.org
117helm repo update
118""")
Andrea Campanellab29ca1e2021-05-06 17:45:27 +0200119
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500120 // ---------------------
121 banner("Deploying VOLTHA with the following parameters: ${cfg}")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800122
Hardik Windlass230fca62022-05-04 08:50:35 +0530123 if (cfg.withVolthaInfra) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400124 volthaInfraDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530125 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800126
Hardik Windlass230fca62022-05-04 08:50:35 +0530127 if (cfg.withVolthaStack) {
Joey Armstrongc33a0bf2023-09-08 14:41:23 -0400128 volthaStackDeploy(cfg)
Hardik Windlass230fca62022-05-04 08:50:35 +0530129 }
Joey Armstrong96158a92022-11-25 10:36:06 -0500130
Joey Armstrong7f6c2c02024-02-11 14:15:24 -0500131 return
132}
133
134// -----------------------------------------------------------------------
135// -----------------------------------------------------------------------
136def call(Map config=[:]) { // Function return type(?)
137 String iam = getIam('main')
138 Boolean ans = true
139
140 try {
141 enter('main')
142 process(config)
143 }
144 catch (Exception err) { // groovylint-disable-line CatchException
145 ans = false
146 println("** ${iam}: EXCEPTION ${err}")
147 throw err
148 }
149 finally {
150 leave('main')
151 }
152
153 return(ans)
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800154}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500155
156// [EOF]