From fe59a6bf9199271d3743011277af7e7bf5d293de Mon Sep 17 00:00:00 2001 From: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:21:26 +0300 Subject: [PATCH] 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> --- .../extra/etcd/templates/etcd-defrag.yaml | 8 ++++ packages/extra/etcd/tests/defrag_test.yaml | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 packages/extra/etcd/tests/defrag_test.yaml diff --git a/packages/extra/etcd/templates/etcd-defrag.yaml b/packages/extra/etcd/templates/etcd-defrag.yaml index 0afcd6d18..52cc63518 100644 --- a/packages/extra/etcd/templates/etcd-defrag.yaml +++ b/packages/extra/etcd/templates/etcd-defrag.yaml @@ -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: diff --git a/packages/extra/etcd/tests/defrag_test.yaml b/packages/extra/etcd/tests/defrag_test.yaml new file mode 100644 index 000000000..8d74e1a6b --- /dev/null +++ b/packages/extra/etcd/tests/defrag_test.yaml @@ -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