Files
cozystack/packages
IvanHunters 84345da93a fix(opensearch-operator): gate leader election on replica count (#3040)
## What this PR does

**Problem**

opensearch-operator installs intermittently fail with Helm reporting the
controller-manager `Deployment status: 'Failed'`. The real driver is the
manager container (`operator-controller-manager`) crashlooping on
`leader election lost`: controller-runtime calls `os.Exit(1)` when it
misses a lease-renewal deadline under the apiserver/etcd latency that
install-time load creates. The Deployment runs a single replica
(`replicas: 1`) yet still passes `--leader-elect`, so leader election
adds no availability — its only effect is to let a transient
control-plane blip self-terminate the sole manager. The kube-rbac-proxy
`BackOff` seen alongside is collateral restart-window noise, not the
cause: on a long-running cluster the proxy shows `restartCount: 0` while
the manager has restarted repeatedly with `exitCode: 1`, `reason:
Error`.

**Fix**

Gate `--leader-elect` on the replica count instead of passing it
unconditionally. A new `manager.replicaCount` value (default `1`) drives
both `spec.replicas` and the flag: at one replica the manager runs
without leader election and rides out control-plane latency instead of
crashlooping; setting `replicaCount > 1` re-enables `--leader-elect`
automatically so a genuine HA deployment still coordinates. Because both
derive from one value, there is no window where multiple managers run
without a lease.

The same single-replica path also sets the Deployment strategy to
`Recreate`. With leader election off, a default `RollingUpdate` would
briefly run two managers (maxSurge) during an operator upgrade, both
reconciling without lease coordination; `Recreate` closes that window at
zero availability cost on one replica. Installs scaled past one replica
keep `RollingUpdate`.

The arg is hardcoded in the vendored opensearch-operator 2.8.0 chart, so
the change ships as
`packages/system/opensearch-operator/patches/leaderElection.diff`,
re-applied by the package `make update` target after `helm pull
--untar`. This mirrors the existing fluxcd-operator patch mechanism so
the customization survives a chart refresh. A helm-unittest suite pins
both states: the default render drops `--leader-elect` and sets
`strategy: Recreate`; a `replicaCount: 2` render restores
`--leader-elect` and leaves the strategy at the RollingUpdate default.

### Screenshots

Not applicable — no UI change.

### Release note

```release-note
fix(opensearch-operator): disable leader election on the single-replica operator Deployment so a transient apiserver/etcd latency spike no longer crashloops the manager at install time; leader election re-enables automatically when scaled past one replica
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added configurable replica count for the operator manager, with a
default of 1.
* Single-replica deployments now use a safer rollout strategy and skip
leader election.
  * Multi-replica deployments automatically enable leader election.

* **Tests**
  * Added coverage for single- and multi-replica deployment behavior.

* **Documentation**
* Updated configuration notes to explain replica count behavior and
related deployment changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-25 19:21:42 +03:00
..