Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 17 | // usage |
| 18 | // |
| 19 | // stage('test stage') { |
| 20 | // steps { |
| 21 | // volthaDeploy([ |
| 22 | // onosReplica: 3 |
| 23 | // ]) |
| 24 | // } |
| 25 | // } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 26 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 27 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 28 | // ----------------------------------------------------------------------- |
| 29 | // ----------------------------------------------------------------------- |
| 30 | def 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 Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 37 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 38 | // ----------------------------------------------------------------------- |
| 39 | // Intent: Display and interact with kubernetes namespaces. |
| 40 | // ----------------------------------------------------------------------- |
| 41 | def doKubeNamespaces() |
| 42 | { |
| 43 | String iam = getIam('doKubeNamespaces') |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 44 | println("** ${iam}: ENTER") |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 45 | |
| 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 Armstrong | 1cf2530 | 2022-12-06 09:51:03 -0500 | [diff] [blame] | 57 | sh('kubectl get namespaces || true') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 58 | |
| 59 | println("** ${iam}: LEAVE") |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | // ----------------------------------------------------------------------- |
| 64 | // ----------------------------------------------------------------------- |
| 65 | def process(Map config) |
| 66 | { |
| 67 | String iam = getIam('process') |
| 68 | println("** ${iam}: ENTER") |
| 69 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 70 | // 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 Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 78 | withMacLearning: false, |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 79 | withFttb: false, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 80 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 81 | localCharts: false, |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 82 | kubeconfig: null, // location of the kubernetes config file, if null we assume it's stored in the $KUBECONFIG environment variable |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 83 | ] |
| 84 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 85 | def cfg = defaultConfig + config |
| 86 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 87 | 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 99 | println "Deploying VOLTHA Infra with the following parameters: ${cfg}." |
| 100 | |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 101 | def kubeconfig = cfg.kubeconfig |
| 102 | if (kubeconfig == null) { |
| 103 | kubeconfig = env.KUBECONFIG |
| 104 | } |
| 105 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 106 | doKubeNamespaces() // WIP: joey |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 107 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 108 | sh """ |
| 109 | kubectl create namespace ${cfg.infraNamespace} || true |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 110 | kubectl create configmap -n ${cfg.infraNamespace} kube-config "--from-file=kube_config=${kubeconfig}" || true |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 111 | """ |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 112 | |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 113 | def serviceConfigFile = cfg.workflow |
| 114 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 115 | serviceConfigFile = "tt-maclearner" |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 116 | } else if (cfg.withFttb && cfg.workflow == 'dt') { |
| 117 | serviceConfigFile = "dt-fttb" |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 120 | // 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 122 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 123 | helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \ |
Matteo Scandolo | 660e4af | 2021-04-02 11:16:09 -0700 | [diff] [blame] | 124 | --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \ |
Matteo Scandolo | d43bb30 | 2021-04-20 10:19:29 -0700 | [diff] [blame] | 125 | --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \ |
| 126 | --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \ |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 127 | --set etcd.replicaCount=${cfg.etcdReplica} \ |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 128 | -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 129 | """ |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 130 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 131 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 132 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 133 | |
| 134 | // ----------------------------------------------------------------------- |
| 135 | // ----------------------------------------------------------------------- |
| 136 | def 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 Armstrong | 8a3c13b | 2022-12-06 09:27:44 -0500 | [diff] [blame] | 152 | // Cannot re-throw ATM: too many potential shell errors. |
| 153 | // throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 154 | } |
| 155 | finally |
| 156 | { |
| 157 | println("** ${iam}: LEAVE") |
| 158 | } |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | // [EOF] |