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 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 3 | // usage |
| 4 | // |
| 5 | // stage('test stage') { |
| 6 | // steps { |
| 7 | // volthaDeploy([ |
| 8 | // onosReplica: 3 |
| 9 | // ]) |
| 10 | // } |
| 11 | // } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 12 | // ----------------------------------------------------------------------- |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 13 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 14 | // ----------------------------------------------------------------------- |
| 15 | // ----------------------------------------------------------------------- |
| 16 | def 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 Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 23 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 24 | // ----------------------------------------------------------------------- |
| 25 | // Intent: Display and interact with kubernetes namespaces. |
| 26 | // ----------------------------------------------------------------------- |
| 27 | def doKubeNamespaces() |
| 28 | { |
| 29 | String iam = getIam('doKubeNamespaces') |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 30 | println("** ${iam}: ENTER") |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 31 | |
| 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 Armstrong | 1cf2530 | 2022-12-06 09:51:03 -0500 | [diff] [blame] | 43 | sh('kubectl get namespaces || true') |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 44 | |
| 45 | println("** ${iam}: LEAVE") |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // ----------------------------------------------------------------------- |
| 50 | // ----------------------------------------------------------------------- |
| 51 | def process(Map config) |
| 52 | { |
| 53 | String iam = getIam('process') |
| 54 | println("** ${iam}: ENTER") |
| 55 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 56 | // 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 Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 64 | withMacLearning: false, |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 65 | withFttb: false, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 66 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 67 | localCharts: false, |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 68 | 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] | 69 | ] |
| 70 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 71 | def cfg = defaultConfig + config |
| 72 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 73 | 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 85 | println "Deploying VOLTHA Infra with the following parameters: ${cfg}." |
| 86 | |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 87 | def kubeconfig = cfg.kubeconfig |
| 88 | if (kubeconfig == null) { |
| 89 | kubeconfig = env.KUBECONFIG |
| 90 | } |
| 91 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 92 | doKubeNamespaces() // WIP: joey |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 93 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 94 | sh """ |
| 95 | kubectl create namespace ${cfg.infraNamespace} || true |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 96 | 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] | 97 | """ |
Matteo Scandolo | d82d1de | 2021-04-06 14:55:58 -0700 | [diff] [blame] | 98 | |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 99 | def serviceConfigFile = cfg.workflow |
| 100 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 101 | serviceConfigFile = "tt-maclearner" |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 102 | } else if (cfg.withFttb && cfg.workflow == 'dt') { |
| 103 | serviceConfigFile = "dt-fttb" |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 106 | // 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 108 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 109 | helm upgrade --install --create-namespace -n ${cfg.infraNamespace} voltha-infra ${volthaInfraChart} \ |
Matteo Scandolo | 660e4af | 2021-04-02 11:16:09 -0700 | [diff] [blame] | 110 | --set onos-classic.replicas=${cfg.onosReplica},onos-classic.atomix.replicas=${cfg.atomixReplica} \ |
Matteo Scandolo | d43bb30 | 2021-04-20 10:19:29 -0700 | [diff] [blame] | 111 | --set kafka.replicaCount=${cfg.kafkaReplica},kafka.zookeeper.replicaCount=${cfg.kafkaReplica} \ |
| 112 | --set etcd.statefulset.replicaCount=${cfg.etcdReplica} \ |
Matteo Scandolo | a1b5d79 | 2021-06-01 12:19:31 -0700 | [diff] [blame] | 113 | --set etcd.replicaCount=${cfg.etcdReplica} \ |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 114 | -f $WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 115 | """ |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 116 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 117 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 118 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 119 | |
| 120 | // ----------------------------------------------------------------------- |
| 121 | // ----------------------------------------------------------------------- |
| 122 | def 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 Armstrong | 8a3c13b | 2022-12-06 09:27:44 -0500 | [diff] [blame] | 138 | // Cannot re-throw ATM: too many potential shell errors. |
| 139 | // throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 140 | } |
| 141 | finally |
| 142 | { |
| 143 | println("** ${iam}: LEAVE") |
| 144 | } |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | // [EOF] |