Skip to content

Commit b8f1e46

Browse files
authored
feat(storage): prepare V2 storage for OpenBao backups (#6693)
* feat(storage): prepare V2 storage for the OpenBao backup mirror * fix(storage): group OpenBao recovery claims by kind
1 parent ac00b69 commit b8f1e46

6 files changed

Lines changed: 67 additions & 5 deletions

File tree

‎k8s/clusters/base/flux-kustomization-infrastructure.yaml‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ spec:
3636
# KRO reports readiness via `status.state: Active|Inactive`, so teach Flux to
3737
# health-check RGDs by that field via a CEL expression.
3838
healthCheckExprs:
39-
# Active snapshot storage must bind. The preparation-only Pending allowance
40-
# is retired with the first consumers of its main-owned retained claim.
39+
# The prepared V2 snapshot claim waits for its first consumer. Once a
40+
# consumer selects a node or the preparation label is removed, it must bind.
4141
- apiVersion: v1
4242
kind: PersistentVolumeClaim
4343
failed: has(status.phase) && status.phase == 'Lost'
4444
current: >-
45-
!has(metadata.deletionTimestamp) && has(status.phase) && status.phase == 'Bound'
45+
!has(metadata.deletionTimestamp) && has(status.phase) &&
46+
(status.phase == 'Bound' ||
47+
(status.phase == 'Pending' && metadata.namespace == 'openbao' &&
48+
metadata.name == 'vault-snapshots-recovery-v2' &&
49+
has(spec.storageClassName) && spec.storageClassName == 'longhorn-v2' &&
50+
has(metadata.labels) && 'platform.devantler.tech/storage-stage' in metadata.labels &&
51+
metadata.labels['platform.devantler.tech/storage-stage'] == 'prepared' &&
52+
!has(spec.volumeName) &&
53+
(!has(metadata.annotations) || !('volume.kubernetes.io/selected-node' in metadata.annotations))))
4654
# `Active` alone stays true from the previous generation while kro is still
4755
# regenerating the instance CRD from a changed graph. Wait until kro reports
4856
# Ready for THIS generation, so `apps` never applies an instance against the

‎k8s/providers/hetzner/infrastructure/vault-backup-recovery/kustomization.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
apiVersion: kustomize.config.k8s.io/v1beta1
33
kind: Kustomization
44
resources:
5-
- persistent-volume-claim.yaml
5+
- persistent-volume-claims
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
resources:
5+
- persistent-volume-claim-original.yaml
6+
- persistent-volume-claim-v2.yaml

k8s/providers/hetzner/infrastructure/vault-backup-recovery/persistent-volume-claim.yaml renamed to k8s/providers/hetzner/infrastructure/vault-backup-recovery/persistent-volume-claims/persistent-volume-claim-original.yaml

File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: vault-snapshots-recovery-v2
6+
namespace: openbao
7+
labels:
8+
platform.devantler.tech/storage-stage: prepared
9+
annotations:
10+
kustomize.toolkit.fluxcd.io/prune: disabled
11+
spec:
12+
storageClassName: longhorn-v2
13+
volumeMode: Filesystem
14+
accessModes:
15+
- ReadWriteOnce
16+
resources:
17+
requests:
18+
storage: 10Gi

‎scripts/tests/vault-backup-recovery/storage_test.go‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ func object(t *testing.T, objects []map[string]any, kind, name string) map[strin
5050
// TestCutoverPreservesOldStorageAndUsesRetainedReplacement fences the storage handoff.
5151
func TestCutoverPreservesOldStorageAndUsesRetainedReplacement(t *testing.T) {
5252
production := render(t, "k8s/providers/hetzner/infrastructure")
53+
prepared := object(t, production, "PersistentVolumeClaim", "vault-snapshots-recovery-v2")
54+
preparedMetadata := prepared["metadata"].(map[string]any)
55+
preparedSpec := prepared["spec"].(map[string]any)
56+
if preparedMetadata["namespace"] != "openbao" || preparedMetadata["annotations"].(map[string]any)["kustomize.toolkit.fluxcd.io/prune"] != "disabled" ||
57+
preparedMetadata["labels"].(map[string]any)["platform.devantler.tech/storage-stage"] != "prepared" ||
58+
preparedSpec["storageClassName"] != "longhorn-v2" || preparedSpec["volumeName"] != nil ||
59+
preparedSpec["volumeMode"] != "Filesystem" || preparedSpec["resources"].(map[string]any)["requests"].(map[string]any)["storage"] != "10Gi" {
60+
t.Fatal("the new claim must remain an unbound and retained V2 staging claim with the original capacity")
61+
}
62+
if modes := preparedSpec["accessModes"].([]any); len(modes) != 1 || modes[0] != "ReadWriteOnce" {
63+
t.Fatal("the V2 claim must preserve single-writer access")
64+
}
5365
for _, name := range []string{"vault-snapshots", "vault-snapshots-recovery"} {
5466
claim := object(t, production, "PersistentVolumeClaim", name)
5567
metadata := claim["metadata"].(map[string]any)
@@ -170,13 +182,27 @@ func TestActiveSnapshotStorageRequiresBinding(t *testing.T) {
170182
ready, lost := compile(current), compile(failed)
171183
for _, tt := range []struct {
172184
name, phase string
185+
claim string
173186
mutate func(map[string]any, map[string]any)
174187
want bool
175188
wantFailed bool
176189
}{
177190
{name: "old prepared marker cannot bypass binding", phase: "Pending", mutate: func(m, _ map[string]any) {
178191
m["labels"] = map[string]any{"platform.devantler.tech/storage-stage": "prepared"}
179192
}},
193+
{name: "prepared V2 claim waits without a first consumer", phase: "Pending", claim: "vault-snapshots-recovery-v2", want: true},
194+
{name: "a selected V2 consumer must bind", phase: "Pending", claim: "vault-snapshots-recovery-v2", mutate: func(m, _ map[string]any) {
195+
m["annotations"].(map[string]any)["volume.kubernetes.io/selected-node"] = "worker"
196+
}},
197+
{name: "the V2 claim must bind after serving starts", phase: "Pending", claim: "vault-snapshots-recovery-v2", mutate: func(m, _ map[string]any) {
198+
delete(m, "labels")
199+
}},
200+
{name: "V2 preparation requires the exact namespace", phase: "Pending", claim: "vault-snapshots-recovery-v2", mutate: func(m, _ map[string]any) {
201+
m["namespace"] = "other"
202+
}},
203+
{name: "V2 preparation requires the exact class", phase: "Pending", claim: "vault-snapshots-recovery-v2", mutate: func(_, s map[string]any) {
204+
s["storageClassName"] = "hcloud"
205+
}},
180206
{name: "bound claim", phase: "Bound", want: true},
181207
{name: "lost claim", phase: "Lost", wantFailed: true},
182208
{name: "unobserved status"},
@@ -195,7 +221,11 @@ func TestActiveSnapshotStorageRequiresBinding(t *testing.T) {
195221
{name: "terminating bound claim", phase: "Bound", mutate: func(m, _ map[string]any) { m["deletionTimestamp"] = "2026-10-26T00:00:00Z" }},
196222
} {
197223
t.Run(tt.name, func(t *testing.T) {
198-
claim := object(t, render(t, "k8s/providers/hetzner/infrastructure/vault-backup-recovery"), "PersistentVolumeClaim", "vault-snapshots-recovery")
224+
name := tt.claim
225+
if name == "" {
226+
name = "vault-snapshots-recovery"
227+
}
228+
claim := object(t, render(t, "k8s/providers/hetzner/infrastructure/vault-backup-recovery"), "PersistentVolumeClaim", name)
199229
metadata, spec := claim["metadata"].(map[string]any), claim["spec"].(map[string]any)
200230
if tt.mutate != nil {
201231
tt.mutate(metadata, spec)

0 commit comments

Comments
 (0)