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 | d085e51 | 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 |
| 14 | * GENERATE_CRUSHMAP Generate new crush map. Excludes OSD |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 18 | def common = new com.mirantis.mk.Common() |
| 19 | def salt = new com.mirantis.mk.Salt() |
| 20 | def ceph = new com.mirantis.mk.Ceph() |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 21 | def python = new com.mirantis.mk.Python() |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 22 | |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 23 | def pepperEnv = "pepperEnv" |
| 24 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 25 | def osds = OSD.tokenize(',').toSet() |
| 26 | def flags = CLUSTER_FLAGS.tokenize(',').toSet() |
| 27 | def cleanOrphans = CLEAN_ORPHANS.toBoolean() |
| 28 | def fullWipe = !FAST_WIPE.toBoolean() |
| 29 | def safeRemove = WAIT_FOR_HEALTHY.toBoolean() |
| 30 | |
| 31 | def osdOnly = OSD.trim() as Boolean |
| 32 | def generateCrushmap = osdOnly ? false : GENERATE_CRUSHMAP.toBoolean() |
Mateusz Los | 1535aa2 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 33 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 34 | timeout(time: 12, unit: 'HOURS') { |
| 35 | node("python") { |
Jiri Broulik | 96c867a | 2017-11-07 16:14:10 +0100 | [diff] [blame] | 36 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 37 | // create connection to salt master |
| 38 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 39 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 40 | def target = salt.getMinions(pepperEnv, HOST) |
| 41 | if(target.isEmpty()) { |
Mateusz Los | b5663e6 | 2020-05-11 09:51:13 +0200 | [diff] [blame] | 42 | common.errorMsg("Host not found") |
| 43 | throw new InterruptedException() |
| 44 | } |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 45 | else if(target.size() > 1) { |
| 46 | common.errorMsg("$HOST targeted more than one minion") |
| 47 | throw new InterruptedException() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 50 | salt.fullRefresh(pepperEnv, HOST) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 51 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 52 | stage('Set flags') { |
| 53 | ceph.setFlags(pepperEnv, flags) |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 56 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 57 | stage('Remove OSDs') { |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 58 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 59 | // get list of osd disks of the host |
| 60 | def cephGrain = ceph.getGrain(pepperEnv, HOST, 'ceph') |
| 61 | def cephDisks = cephGrain.get('ceph_disk',[:]).keySet() |
| 62 | if (cephGrain.isEmpty()) { |
| 63 | throw new Exception("Ceph salt grains cannot be found on $HOST") |
| 64 | } |
| 65 | |
Tomek Jaroszyk | d0ddb56 | 2021-02-17 15:25:06 +0100 | [diff] [blame^] | 66 | // glob for OSD input or whole node is going to be removed |
| 67 | if(OSD == '*' || !osdOnly) { |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 68 | osds = cephDisks |
| 69 | } |
| 70 | |
| 71 | // discard all osds which aren't deployed on target HOST |
| 72 | osds = osds.intersect(cephDisks) |
| 73 | |
| 74 | if(!osds.isEmpty()) { |
| 75 | common.infoMsg("The following osds will be removed: ${osds.join(', ')}") |
| 76 | } |
| 77 | if(osds != cephDisks) { |
| 78 | common.infoMsg("The following osds will be skiped: ${cephDisks.removeAll(osds).join(', ')}") |
| 79 | } |
| 80 | |
| 81 | ceph.removeOsd(pepperEnv, HOST, osds, flags, safeRemove, fullWipe) |
| 82 | |
| 83 | if(cleanOrphans) { |
| 84 | ceph.removeOrphans(pepperEnv, HOST, fullWipe) |
| 85 | } |
| 86 | } |
| 87 | else { |
| 88 | common.infoMsg('Stage skipped.') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 92 | stage('Remove keyring') { |
| 93 | // only non-osd nodes as keyrings for osds was removed already in previous step |
| 94 | if(salt.testTarget(pepperEnv, "$HOST and not I@ceph:osd")) { |
| 95 | ceph.deleteKeyrings(pepperEnv, HOST) |
| 96 | } |
| 97 | else { |
| 98 | common.infoMsg('Stage skipped.') |
| 99 | } |
| 100 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 102 | stage('Update monmap') { |
| 103 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 104 | def hostname = ceph.getGrain(pepperEnv, HOST, 'host') |
| 105 | ceph.cmdRun(pepperEnv, 'ceph mon getmap -o monmap.backup') |
| 106 | ceph.cmdRun(pepperEnv, "ceph mon remove $hostname") |
| 107 | salt.cmdRun(pepperEnv, 'I@ceph:mon', "monmaptool /tmp/monmap --rm $hostname") |
| 108 | } |
| 109 | else { |
| 110 | common.infoMsg('Stage skipped.') |
| 111 | } |
| 112 | } |
Mateusz Los | 1535aa2 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 113 | |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 114 | stage('Update Ceph configs/crushmap') { |
| 115 | //TODO: it won't remove removed mon from config |
| 116 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 117 | salt.enforceState(pepperEnv, 'I@ceph:common', 'ceph.common', true) |
| 118 | } |
| 119 | else if (salt.testTarget(pepperEnv, "$HOST and I@ceph:osd") && salt.testTarget(pepperEnv, "I@ceph:setup:crush and not $HOST") && generateCrushmap) { |
| 120 | salt.enforceState(pepperEnv, 'I@ceph:setup:crush', 'ceph.setup.crush', true) |
| 121 | } |
| 122 | else { |
| 123 | common.infoMsg('Stage skipped.') |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | stage('Purge Ceph components') { |
| 128 | Set pkgs = ['ceph-base','ceph-common'] |
| 129 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 130 | pkgs.addAll(['ceph-osd','ceph-fuse','ceph-mds','python-cephfs','librados2','python-rados','python-rbd','python-rgw']) |
| 131 | } |
| 132 | //TODO: why removed pkgs on vm which will be remved as whole in next stage |
| 133 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:radosgw")) { |
| 134 | ceph.removeRgw(pepperEnv, HOST) |
| 135 | pkgs.addAll(['radosgw','libcephfs2','python-cephfs','python-rados','python-rbd','python-rgw']) |
| 136 | } |
| 137 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:mon")) { |
| 138 | pkgs.addAll(['ceph-mon','ceph-mgr','libcephfs2','python-cephfs','python-rbd','python-rgw']) |
| 139 | } |
| 140 | |
| 141 | if(!osdOnly) { |
| 142 | salt.runSaltProcessStep(pepperEnv, HOST, 'pkg.purge', pkgs) |
| 143 | } |
| 144 | else { |
| 145 | common.infoMsg('Stage skipped.') |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | stage('Remove salt minion and destroy VM') { |
| 150 | if(!osdOnly) { |
| 151 | if(salt.testTarget(pepperEnv, "$HOST and I@ceph:osd")) { |
| 152 | ceph.removeSalt(pepperEnv, HOST) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 153 | } |
Mateusz Los | 1535aa2 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 154 | else { |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 155 | ceph.removeVm(pepperEnv, HOST) |
Mateusz Los | 1535aa2 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 156 | } |
| 157 | } |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 158 | else { |
| 159 | common.infoMsg('Stage skipped.') |
Mateusz Los | 1535aa2 | 2020-05-11 10:33:58 +0200 | [diff] [blame] | 160 | } |
Jiri Broulik | 3485b2c | 2017-11-28 15:06:12 +0100 | [diff] [blame] | 161 | } |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 162 | } |
Tomek Jaroszyk | d085e51 | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 163 | finally { |
| 164 | stage('Unset cluster flags') { |
| 165 | ceph.unsetFlags(pepperEnv, flags) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 166 | } |
Jiri Broulik | 99887c8 | 2017-10-31 09:27:52 +0100 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |