blob: 7073e875cdb1e6d620b6a00cc4b05bf94abaca1d [file] [log] [blame]
Joey Armstrong96158a92022-11-25 10:36:06 -05001#!/usr/bin/env groovy
Joey Armstrong7987c112022-12-05 12:42:43 -05002// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -08003// usage
4//
5// stage('test stage') {
6// steps {
7// volthaDeploy([
8// onosReplica: 3
9// ])
10// }
11// }
Joey Armstrong7987c112022-12-05 12:42:43 -050012// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -080013
Joey Armstrong7987c112022-12-05 12:42:43 -050014// -----------------------------------------------------------------------
15// -----------------------------------------------------------------------
16def getIam(String func)
17{
18 // Cannot rely on a stack trace due to jenkins manipulation
19 String src = 'vars/volthaInfraDeploy.groovy'
20 String iam = [src, func].join('::')
21 return iam
22}
Joey Armstrong96158a92022-11-25 10:36:06 -050023
Joey Armstrong7987c112022-12-05 12:42:43 -050024// -----------------------------------------------------------------------
25// Intent: Display and interact with kubernetes namespaces.
26// -----------------------------------------------------------------------
27def doKubeNamespaces()
28{
29 String iam = getIam('doKubeNamespaces')
Joey Armstrong96158a92022-11-25 10:36:06 -050030 println("** ${iam}: ENTER")
Joey Armstrong7987c112022-12-05 12:42:43 -050031
32 /*
33 [joey] - should pre-existing hint the env is tainted (?)
34 05:24:57 + kubectl create namespace infra
35 05:24:57 Error from server (AlreadyExists): namespaces "infra" already exists
36 05:24:57 error: failed to create configmap: configmaps "kube-config" already exists
37
38 [joey] Thinking we should:
39 o A special case exists (create namespace)
40 o helm upgrade --install (inital update)
41 */
42
Joey Armstrong1cf25302022-12-06 09:51:03 -050043 sh('kubectl get namespaces || true')
Joey Armstrong7987c112022-12-05 12:42:43 -050044
45 println("** ${iam}: LEAVE")
46 return
47}
48
49// -----------------------------------------------------------------------
50// -----------------------------------------------------------------------
51def process(Map config)
52{
53 String iam = getIam('process')
54 println("** ${iam}: ENTER")
55
Matteo Scandolo42f6e572021-01-25 15:11:34 -080056 // NOTE use params or directule extraHelmFlags??
57 def defaultConfig = [
58 onosReplica: 1,
59 atomixReplica: 1,
60 kafkaReplica: 1,
61 etcdReplica: 1,
62 infraNamespace: "infra",
63 workflow: "att",
Hardik Windlass810b6cf2022-02-24 09:21:18 +000064 withMacLearning: false,
Hardik Windlassc97ceae2022-05-13 10:12:55 +053065 withFttb: false,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080066 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080067 localCharts: false,
Matteo Scandolod82d1de2021-04-06 14:55:58 -070068 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 -080069 ]
70
Matteo Scandolo42f6e572021-01-25 15:11:34 -080071 def cfg = defaultConfig + config
72
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080073 def volthaInfraChart = "onf/voltha-infra"
74
75 if (cfg.localCharts) {
76 volthaInfraChart = "$WORKSPACE/voltha-helm-charts/voltha-infra"
77
78 sh """
79 pushd $WORKSPACE/voltha-helm-charts/voltha-infra
80 helm dep update
81 popd
82 """
83 }
84
Matteo Scandolo42f6e572021-01-25 15:11:34 -080085 println "Deploying VOLTHA Infra with the following parameters: ${cfg}."
86
Matteo Scandolod82d1de2021-04-06 14:55:58 -070087 def kubeconfig = cfg.kubeconfig
88 if (kubeconfig == null) {
89 kubeconfig = env.KUBECONFIG
90 }
91
Joey Armstrong7987c112022-12-05 12:42:43 -050092 doKubeNamespaces() // WIP: joey
Joey Armstrong96158a92022-11-25 10:36:06 -050093
Matteo Scandolo42f6e572021-01-25 15:11:34 -080094 sh """
95 kubectl create namespace ${cfg.infraNamespace} || true
Matteo Scandolod82d1de2021-04-06 14:55:58 -070096 kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}" || true
Matteo Scandolo42f6e572021-01-25 15:11:34 -080097 """
Matteo Scandolod82d1de2021-04-06 14:55:58 -070098
Hardik Windlass810b6cf2022-02-24 09:21:18 +000099 def serviceConfigFile = cfg.workflow
100 if (cfg.withMacLearning && cfg.workflow == 'tt') {
101 serviceConfigFile = "tt-maclearner"
Hardik Windlassc97ceae2022-05-13 10:12:55 +0530102 } else if (cfg.withFttb && cfg.workflow == 'dt') {
103 serviceConfigFile = "dt-fttb"
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000104 }
105
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700106 // bitnamic/etch has change the replica format between the currently used 5.4.2 and the latest 6.2.5
107 // for now put both values in the extra helm chart flags
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800108 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -0700109 helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \
Matteo Scandolo660e4af2021-04-02 11:16:09 -0700110 --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \
Matteo Scandolod43bb302021-04-20 10:19:29 -0700111 --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \
112 --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \
Matteo Scandoloa1b5d792021-06-01 12:19:31 -0700113 --set etcd.replicaCount=${cfg.etcdReplica} \
Hardik Windlass810b6cf2022-02-24 09:21:18 +0000114 -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800115 """
Joey Armstrong96158a92022-11-25 10:36:06 -0500116
Joey Armstrong7987c112022-12-05 12:42:43 -0500117 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800118}
Joey Armstrong7987c112022-12-05 12:42:43 -0500119
120// -----------------------------------------------------------------------
121// -----------------------------------------------------------------------
122def call(Map config)
123{
124 String iam = getIam('main')
125 println("** ${iam}: ENTER")
126
127 if (!config) {
128 config = [:]
129 }
130
131 try
132 {
133 process(config)
134 }
135 catch (Exception err)
136 {
137 println("** ${iam}: EXCEPTION ${err}")
Joey Armstrong8a3c13b2022-12-06 09:27:44 -0500138 // Cannot re-throw ATM: too many potential shell errors.
139 // throw err
Joey Armstrong7987c112022-12-05 12:42:43 -0500140 }
141 finally
142 {
143 println("** ${iam}: LEAVE")
144 }
145 return
146}
147
148// [EOF]