blob: c476fd5fff527965a47d3d3a0510ba823af0a4c3 [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrong7987c112022-12-05 12:42:43 -05002// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// 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 Scandolo42f6e572021-01-25 15:11:34 -080017// usage
18//
19// stage('test stage') {
20// steps {
21// volthaDeploy([
22// onosReplica: 3
23// ])
24// }
25// }
Joey Armstrong7987c112022-12-05 12:42:43 -050026// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -080027
Joey Armstrong7987c112022-12-05 12:42:43 -050028// -----------------------------------------------------------------------
29// -----------------------------------------------------------------------
30def 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 Armstrong96158a92022-11-25 10:36:06 -050037
Joey Armstrong7987c112022-12-05 12:42:43 -050038// -----------------------------------------------------------------------
39// Intent: Display and interact with kubernetes namespaces.
40// -----------------------------------------------------------------------
41def doKubeNamespaces()
42{
43 String iam = getIam('doKubeNamespaces')
Joey Armstrong96158a92022-11-25 10:36:06 -050044 println("** ${iam}: ENTER")
Joey Armstrong7987c112022-12-05 12:42:43 -050045
46 /*
47 [joey] - should pre-existing hint the env is tainted (?)
48 05:24:57 + kubectl create namespace infra
49 05:24:57 Error from server (AlreadyExists): namespaces "infra" already exists
50 05:24:57 error: failed to create configmap: configmaps "kube-config" already exists
51
52 [joey] Thinking we should:
53 o A special case exists (create namespace)
54 o helm upgrade --install (inital update)
55 */
56
Joey Armstrong1cf25302022-12-06 09:51:03 -050057 sh('kubectl get namespaces || true')
Joey Armstrong7987c112022-12-05 12:42:43 -050058
59 println("** ${iam}: LEAVE")
60 return
61}
62
63// -----------------------------------------------------------------------
64// -----------------------------------------------------------------------
65def process(Map config)
66{
67 String iam = getIam('process')
68 println("** ${iam}: ENTER")
69
Matteo Scandolo42f6e572021-01-25 15:11:34 -080070 // NOTE use params or directule extraHelmFlags??
71 def defaultConfig = [
72 onosReplica: 1,
73 atomixReplica: 1,
74 kafkaReplica: 1,
75 etcdReplica: 1,
76 infraNamespace: "infra",
77 workflow: "att",
Hardik Windlass810b6cf2022-02-24 09:21:18 +000078 withMacLearning: false,
Hardik Windlassc97ceae2022-05-13 10:12:55 +053079 withFttb: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080080 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080081 localCharts: false,
Matteo Scandolod82d1de2021-04-06 14:55:58 -070082 kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable
Matteo Scandolo42f6e572021-01-25 15:11:34 -080083 ]
84
Matteo Scandolo42f6e572021-01-25 15:11:34 -080085 def cfg = defaultConfig + config
86
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080087 def volthaInfraChart = "onf/voltha-infra"
88
89 if (cfg.localCharts) {
90 volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra"
91
92 sh """
93 pushd $WORKSPACE/voltha-helm-charts/voltha-infra
94 helm dep update
95 popd
96 """
97 }
98
Matteo Scandolo42f6e572021-01-25 15:11:34 -080099 println "Deploying VOLTHA Infra with the following parameters: ${cfg}."
100
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700101 def kubeconfig = cfg.kubeconfig
102 if (kubeconfig == null) {
103 kubeconfig = env.KUBECONFIG
104 }
105
Joey Armstrong7987c112022-12-05 12:42:43 -0500106 doKubeNamespaces() // WIP: joey
Joey Armstrong96158a92022-11-25 10:36:06 -0500107
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800108 sh """
109 kubectl create namespace ${cfg.infraNamespace} || true
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700110 kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}" || true
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800111 """
Matteo Scandolod82d1de2021-04-06 14:55:58 -0700112
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000113 def serviceConfigFile = cfg.workflow
114 if (cfg.withMacLearning && cfg.workflow == 'tt') {
115 serviceConfigFile = "tt-maclearner"
Hardik Windlassc97ceae2022-05-13 10:12:55 +0530116 } else if (cfg.withFttb && cfg.workflow == 'dt') {
117 serviceConfigFile = "dt-fttb"
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000118 }
119
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700120 // bitnamic/etch has change the replica format between the currently used 5.4.2 and the latest 6.2.5
121 // for now put both values in the extra helm chart flags
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800122 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -0700123 helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \
Matteo Scandolo660e4af2021-04-02 11:16:09 -0700124 --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \
Matteo Scandolod43bb302021-04-20 10:19:29 -0700125 --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \
126 --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700127 --set etcd.replicaCount=${cfg.etcdReplica} \
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000128 -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800129 """
Joey Armstrong96158a92022-11-25 10:36:06 -0500130
Joey Armstrong7987c112022-12-05 12:42:43 -0500131 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800132}
Joey Armstrong7987c112022-12-05 12:42:43 -0500133
134// -----------------------------------------------------------------------
135// -----------------------------------------------------------------------
136def call(Map config)
137{
138 String iam = getIam('main')
139 println("** ${iam}: ENTER")
140
141 if (!config) {
142 config = [:]
143 }
144
145 try
146 {
147 process(config)
148 }
149 catch (Exception err)
150 {
151 println("** ${iam}: EXCEPTION ${err}")
Joey Armstrong8a3c13b2022-12-06 09:27:44 -0500152 // Cannot re-throw ATM: too many potential shell errors.
153 // throw err
Joey Armstrong7987c112022-12-05 12:42:43 -0500154 }
155 finally
156 {
157 println("** ${iam}: LEAVE")
158 }
159 return
160}
161
162// [EOF]