Skip to content

Commit fe59a6b

Browse files
committed
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 <[email protected]>
1 parent 9a348ee commit fe59a6b

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎packages/extra/etcd/templates/etcd-defrag.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ spec:
4444
- --cert=/etc/etcd/pki/client/cert/tls.crt
4545
- --key=/etc/etcd/pki/client/cert/tls.key
4646
- --cluster
47+
# etcd compacts itself (periodic, 5m retention, see etcd-cluster.yaml).
48+
# Compacting again to the latest revision either fails because nothing
49+
# was written since, or drops the history that retention keeps for
50+
# watchers to resume from.
51+
- --compaction=false
52+
# dbQuotaUsage below is dbSize over this value, and the tool assumes
53+
# 2 GiB unless told the quota the cluster actually runs with.
54+
- --etcd-storage-quota-bytes={{ include "calculateQuotaBackendBytes" .Values.size }}
4755
- --defrag-rule
4856
- "dbQuotaUsage > 0.8 || dbSize - dbSizeInUse > 200*1024*1024"
4957
volumeMounts:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
suite: etcd defrag CronJob leaves compaction to etcd and knows the real quota
2+
3+
release:
4+
name: etcd
5+
namespace: tenant-test
6+
7+
templates:
8+
- templates/etcd-defrag.yaml
9+
- templates/etcd-cluster.yaml
10+
11+
set:
12+
_cluster: {}
13+
14+
tests:
15+
- it: does not compact before defragmenting
16+
template: templates/etcd-defrag.yaml
17+
asserts:
18+
- contains:
19+
path: spec.jobTemplate.spec.template.spec.containers[0].args
20+
content: --compaction=false
21+
22+
- it: evaluates dbQuotaUsage against the default 4Gi cluster quota
23+
template: templates/etcd-defrag.yaml
24+
asserts:
25+
- contains:
26+
path: spec.jobTemplate.spec.template.spec.containers[0].args
27+
content: --etcd-storage-quota-bytes=4080218931
28+
29+
- it: passes the defrag tool the same quota the EtcdCluster gets
30+
set:
31+
size: 10Gi
32+
asserts:
33+
- contains:
34+
path: spec.jobTemplate.spec.template.spec.containers[0].args
35+
content: --etcd-storage-quota-bytes=10200547328
36+
template: templates/etcd-defrag.yaml
37+
- equal:
38+
path: spec.options.quotaBackendBytes
39+
value: 10200547328
40+
template: templates/etcd-cluster.yaml
41+
documentSelector:
42+
path: kind
43+
value: EtcdCluster

0 commit comments

Comments
 (0)