|
| 1 | +# Allow downscaling replicaSets in a safe manner |
| 2 | + |
| 3 | +* Date: 2021-06-15 |
| 4 | + |
| 5 | +## Status |
| 6 | + |
| 7 | +* Status: Accepted |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +Currently there are no mechanisms to stop users downscaling MongoDB replicaSets |
| 12 | +in a manner that causes cluster failure. For example, if a user has 7 members |
| 13 | +of replicaSet and downscales it to 3 members, the cluster is going to lose |
| 14 | +majority (4 members) and the operator won't be able to run `replSetReconfig` |
| 15 | +because of that. |
| 16 | + |
| 17 | +## Considered Options |
| 18 | + |
| 19 | +* Compare current statefulset size with replicaSet size in CR and downscale one |
| 20 | + by one on each reconciliation until reaching the target size. |
| 21 | +* Compare current statefulset size with replicaSet size in CR and if the target |
| 22 | + size breaks the majority throw an error. |
| 23 | +* Rather than populating replicaSet members based on a set of pods that are selected |
| 24 | + according to labels, we could fetch pods one by one in respect to replicaSet size and |
| 25 | + thus removing the excess pods from replicaSet config *hopefully* before they |
| 26 | + become inaccessible. |
| 27 | +* ~Use [admission controllers](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/) to validate size updates.~ For every CRD, there can be only one webhook in endpoint in a cluster. PSMDB Operator doesn't work cluster wide |
| 28 | +* Document this issue and let the end users decide |
| 29 | + |
| 30 | +## Decision |
| 31 | + |
| 32 | +Chosen option: We will compare the current statefulset size with the replicaSet size in |
| 33 | +the CR and downscale one by one on each reconciliation until reaching the target |
| 34 | +size. |
| 35 | + |
| 36 | +## Consequences |
| 37 | + |
| 38 | +Users can downscale their clusters to any size they like in a single step. |
| 39 | + |
| 40 | +### Negative Consequences |
| 41 | + |
| 42 | +We will be mutating the replicaSet size field in CR to downscale one by one. If |
| 43 | +CR is updated by operator before the replicaSet reaches the target size, we'll |
| 44 | +overwrite the user's changes on size field. For instance, in the `writeStatus` |
| 45 | +method, we're trying to update the status subresource but if it fails we update |
| 46 | +the whole CR. |
0 commit comments