fix(etcd): leave compaction to etcd and pass the real quota to defrag

The hourly defrag CronJob runs etcd-defrag with its defaults, which compact
to the latest revision before defragmenting. Every cluster already compacts
itself with a periodic five-minute retention, so the second compaction
either fails with "required revision has been compacted" when nothing was
written since, or drops the history that retention keeps for watchers to
resume from.

The same defaults evaluate dbQuotaUsage in the defrag rule against 2 GiB
rather than the quotaBackendBytes the cluster runs with, so the 80 percent
threshold fires at a different database size than intended.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
This commit is contained in:
Yan Bondarenko committed 2026-10-11 20:21:26 +03:00
1 parent 9a348eeb50
commit fe59a6bf91
2 files changed
+51

No files matched your search

@@ -44,6 +44,14 @@ spec:
- --cert=/etc/etcd/pki/client/cert/tls.crt
- --key=/etc/etcd/pki/client/cert/tls.key
- --cluster
# etcd compacts itself (periodic, 5m retention, see etcd-cluster.yaml).
# Compacting again to the latest revision either fails because nothing
# was written since, or drops the history that retention keeps for
# watchers to resume from.
- --compaction=false
# dbQuotaUsage below is dbSize over this value, and the tool assumes
# 2 GiB unless told the quota the cluster actually runs with.
- --etcd-storage-quota-bytes={{ include "calculateQuotaBackendBytes" .Values.size }}
- --defrag-rule
- "dbQuotaUsage > 0.8 || dbSize - dbSizeInUse > 200*1024*1024"
volumeMounts:
@@ -0,0 +1,43 @@
suite: etcd defrag CronJob leaves compaction to etcd and knows the real quota
release:
name: etcd
namespace: tenant-test
templates:
- templates/etcd-defrag.yaml
- templates/etcd-cluster.yaml
set:
_cluster: {}
tests:
- it: does not compact before defragmenting
template: templates/etcd-defrag.yaml
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].args
content: --compaction=false
- it: evaluates dbQuotaUsage against the default 4Gi cluster quota
template: templates/etcd-defrag.yaml
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].args
content: --etcd-storage-quota-bytes=4080218931
- it: passes the defrag tool the same quota the EtcdCluster gets
set:
size: 10Gi
asserts:
- contains:
path: spec.jobTemplate.spec.template.spec.containers[0].args
content: --etcd-storage-quota-bytes=10200547328
template: templates/etcd-defrag.yaml
- equal:
path: spec.options.quotaBackendBytes
value: 10200547328
template: templates/etcd-cluster.yaml
documentSelector:
path: kind
value: EtcdCluster