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