Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Remove Ceph node from existing cluster |
| 4 | * |
| 5 | * Requred parameters: |
| 6 | * SALT_MASTER_URL URL of Salt master |
| 7 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API |
| 8 | * HOST Host (minion id) to be removed |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 9 | * WAIT_FOR_HEALTHY Wait for cluster rebalance after a osd was removed |
| 10 | * CLUSTER_FLAGS Expected flags on the cluster during job run |
| 11 | * FAST_WIPE Clean only partition table insted of full wipe |
| 12 | * CLEAN_ORPHANS Clean ceph partition which are no longer part of the cluster |
| 13 | * OSD Coma separated list of OSDs to remove while keep the rest intact |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 14 | * OSD_NODE_IS_DOWN Remove unavailable (offline) osd node from cluster, provided in HOST parameter |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 15 | * GENERATE_CRUSHMAP Generate new crush map. Excludes OSD |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 19 | def common = new com.mirantis.mk.Common() |
| 20 | def salt = new com.mirantis.mk.Salt() |
| 21 | def ceph = new com.mirantis.mk.Ceph() |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 22 | def python = new com.mirantis.mk.Python() |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 23 | |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 24 | def pepperEnv = "pepperEnv" |
| 25 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 26 | def osds = OSD.tokenize(',').toSet() |
| 27 | def flags = CLUSTER_FLAGS.tokenize(',').toSet() |
| 28 | def cleanOrphans = CLEAN_ORPHANS.toBoolean() |
| 29 | def fullWipe = !FAST_WIPE.toBoolean() |
| 30 | def safeRemove = WAIT_FOR_HEALTHY.toBoolean() |
| 31 | |
| 32 | def osdOnly = OSD.trim() as Boolean |
| 33 | def generateCrushmap = osdOnly ? false : GENERATE_CRUSHMAP.toBoolean() |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 34 | def osdNodeUnavailable = OSD_NODE_IS_DOWN.toBoolean() |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 35 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 36 | timeout(time: 12, unit: 'HOURS') { |
| 37 | node("python") { |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame] | 38 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 39 | // create connection to salt master |
| 40 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 41 | |
Denis Egorenko | 970233f | 2021-05-17 18:37:54 +0400 | [diff] [blame] | 42 | def target = salt.getMinions(pepperEnv, HOST) |
| 43 | if(target.isEmpty()) { |
| 44 | common.errorMsg("Host not found") |
| 45 | throw new InterruptedException() |
| 46 | } |
| 47 | else if(target.size() > 1) { |
| 48 | common.errorMsg("$HOST targeted more than one minion") |
| 49 | throw new InterruptedException() |
| 50 | } |
| 51 | |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 52 | if (osdNodeUnavailable) { |
| 53 | stage('Remove unavailable OSD node') { |
Denis Egorenko | 970233f | 2021-05-17 18:37:54 +0400 | [diff] [blame] | 54 | osdHostName = salt.stripDomainName("${target[0]}") |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 55 | osdTreeString = ceph.cmdRun(pepperEnv, "ceph osd tree --format json-pretty") |
| 56 | osdTree = common.parseJSON(osdTreeString) |
| 57 | osdIDs = [] |
| 58 | for(osd in osdTree["nodes"]) { |
| 59 | if (osd["type"] == "host" && osd["name"] == osdHostName) { |
| 60 | osdIDs = osd["children"] |
| 61 | break |
| 62 | } |
| 63 | } |
| 64 | if (osdIDs.size() == 0) { |
| 65 | common.warningMsg("Can't find any OSDs placed on host ${HOST} (${osdHostName}). Is it correct name?") |
| 66 | currentBuild.result = "UNSTABLE" |
| 67 | } else { |
| 68 | common.infoMsg("Found next OSDs for host ${HOST} (${osdHostName}): ${osdIDs}") |
| 69 | input message: "Do you want to continue node remove?" |
| 70 | for (osdId in osdIDs) { |
Denis Egorenko | 970233f | 2021-05-17 18:37:54 +0400 | [diff] [blame] | 71 | ceph.cmdRun(pepperEnv, "ceph osd purge ${osdId} --yes-i-really-mean-it", true, true) |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 72 | } |
| 73 | salt.cmdRun(pepperEnv, "I@salt:master", "salt-key -d ${HOST} --include-all -y") |
Denis Egorenko | 970233f | 2021-05-17 18:37:54 +0400 | [diff] [blame] | 74 | |
| 75 | if(safeRemove) { |
| 76 | ceph.waitForHealthy(pepperEnv, flags) |
| 77 | } |
Denis Egorenko | fe8d7af | 2021-03-18 15:13:59 +0400 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | return |
| 81 | } |
| 82 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 83 | salt.fullRefresh(pepperEnv, HOST) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 84 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 85 | stage('Set flags') { |
| 86 | ceph.setFlags(pepperEnv, flags) |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 89 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 90 | stage('Remove OSDs') { |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 91 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 92 | // get list of osd disks of the host |
| 93 | def cephGrain = ceph.getGrain(pepperEnv, HOST, 'ceph') |
| 94 | def cephDisks = cephGrain.get('ceph_disk',[:]).keySet() |
| 95 | if (cephGrain.isEmpty()) { |
| 96 | throw new Exception("Ceph salt grains cannot be found on $HOST") |
| 97 | } |
| 98 | |
Tomek Jaroszyk | 1f9a0c5 | 2021-02-17 15:25:06 +0100 | [diff] [blame] | 99 | // glob for OSD input or whole node is going to be removed |
| 100 | if(OSD == '*' || !osdOnly) { |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 101 | osds = cephDisks |
| 102 | } |
| 103 | |
| 104 | // discard all osds which aren't deployed on target HOST |
| 105 | osds = osds.intersect(cephDisks) |
| 106 | |
| 107 | if(!osds.isEmpty()) { |
| 108 | common.infoMsg("The following osds will be removed: ${osds.join(', ')}") |
| 109 | } |
| 110 | if(osds != cephDisks) { |
Tomek Jaroszyk | 4c13ce7 | 2022-02-01 15:10:40 +0100 | [diff] [blame] | 111 | cephDisks.removeAll(osds) |
| 112 | common.infoMsg("The following osds will be skiped: ${cephDisks.join(', ')}") |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | ceph.removeOsd(pepperEnv, HOST, osds, flags, safeRemove, fullWipe) |
| 116 | |
| 117 | if(cleanOrphans) { |
| 118 | ceph.removeOrphans(pepperEnv, HOST, fullWipe) |
| 119 | } |
| 120 | } |
| 121 | else { |
| 122 | common.infoMsg('Stage skipped.') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 126 | stage('Remove keyring') { |
| 127 | // only non-osd nodes as keyrings for osds was removed already in previous step |
| 128 | if(salt.testTarget(pepperEnv, "$HOST and not I@ceph:osd")) { |
| 129 | ceph.deleteKeyrings(pepperEnv, HOST) |
| 130 | } |
| 131 | else { |
| 132 | common.infoMsg('Stage skipped.') |
| 133 | } |
| 134 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 135 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 136 | stage('Update monmap') { |
| 137 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 138 | def hostname = ceph.getGrain(pepperEnv, HOST, 'host') |
| 139 | ceph.cmdRun(pepperEnv, 'ceph mon getmap -o monmap.backup') |
| 140 | ceph.cmdRun(pepperEnv, "ceph mon remove $hostname") |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 141 | } |
| 142 | else { |
| 143 | common.infoMsg('Stage skipped.') |
| 144 | } |
| 145 | } |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 146 | |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 147 | stage('Update Ceph configs/crushmap') { |
| 148 | //TODO: it won't remove removed mon from config |
| 149 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 150 | salt.enforceState(pepperEnv, 'I@ceph:common', 'ceph.common', true) |
| 151 | } |
| 152 | else if (salt.testTarget(pepperEnv, "$HOST and I@ceph:osd") && salt.testTarget(pepperEnv, "I@ceph:setup:crush and not $HOST") && generateCrushmap) { |
| 153 | salt.enforceState(pepperEnv, 'I@ceph:setup:crush', 'ceph.setup.crush', true) |
| 154 | } |
| 155 | else { |
| 156 | common.infoMsg('Stage skipped.') |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | stage('Purge Ceph components') { |
| 161 | Set pkgs = ['ceph-base','ceph-common'] |
| 162 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 163 | pkgs.addAll(['ceph-osd','ceph-fuse','ceph-mds','python-cephfs','librados2','python-rados','python-rbd','python-rgw']) |
| 164 | } |
| 165 | //TODO: why removed pkgs on vm which will be remved as whole in next stage |
| 166 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:radosgw")) { |
| 167 | ceph.removeRgw(pepperEnv, HOST) |
| 168 | pkgs.addAll(['radosgw','libcephfs2','python-cephfs','python-rados','python-rbd','python-rgw']) |
| 169 | } |
| 170 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 171 | pkgs.addAll(['ceph-mon','ceph-mgr','libcephfs2','python-cephfs','python-rbd','python-rgw']) |
| 172 | } |
| 173 | |
| 174 | if(!osdOnly) { |
Tomek Jaroszyk | 6a4bf64 | 2021-03-09 12:22:37 +0100 | [diff] [blame] | 175 | salt.runSaltProcessStep(pepperEnv, HOST, 'pkg.purge', "pkgs='$pkgs'") |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 176 | } |
| 177 | else { |
| 178 | common.infoMsg('Stage skipped.') |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | stage('Remove salt minion and destroy VM') { |
| 183 | if(!osdOnly) { |
| 184 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 185 | ceph.removeSalt(pepperEnv, HOST) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 186 | } |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 187 | else { |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 188 | ceph.removeVm(pepperEnv, HOST) |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 189 | } |
| 190 | } |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 191 | else { |
| 192 | common.infoMsg('Stage skipped.') |
Mateusz Los | 8b64b81 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 193 | } |
Jiri Broulik | 3485b2c | 2017-11-28 15:06:12 +0100 | [diff] [blame] | 194 | } |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 195 | } |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 196 | finally { |
| 197 | stage('Unset cluster flags') { |
| 198 | ceph.unsetFlags(pepperEnv, flags) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 199 | } |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } |