Skip to content

Commit 11e7eaa

Browse files
authored
fix(storage): identify what is holding rebuilt workers (#6577)
* fix(storage): report the temporary recovery readiness gate * fix(storage): observe a held temporary worker recovery * fix(storage): preserve endpoint masking in recovery observation
1 parent f5b5a85 commit 11e7eaa

8 files changed

Lines changed: 366 additions & 19 deletions
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
name: Observe Longhorn Temporary Worker Recovery
3+
4+
"on":
5+
workflow_dispatch:
6+
inputs:
7+
node:
8+
description: Temporary worker with an existing reset journal
9+
required: true
10+
type: choice
11+
options: [temporary-v1-1, temporary-v1-2]
12+
confirm:
13+
description: Type observe-longhorn-v2-recovery- followed by the selected worker
14+
required: true
15+
type: string
16+
17+
permissions: {}
18+
concurrency:
19+
group: prod-deploy
20+
cancel-in-progress: false
21+
queue: max
22+
23+
jobs:
24+
observe:
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 10
27+
environment: prod
28+
permissions:
29+
contents: read
30+
env:
31+
LONGHORN_V2_OPERATION: observe-temporary-recovery
32+
LONGHORN_V2_NODE: ${{ inputs.node }}
33+
LONGHORN_V2_CONFIRM: ${{ inputs.confirm }}
34+
steps:
35+
- name: Require the confirmed first attempt on main
36+
shell: bash
37+
run: |
38+
set -euo pipefail
39+
[[ "${GITHUB_REPOSITORY}" == devantler-tech/platform &&
40+
"${GITHUB_EVENT_NAME}" == workflow_dispatch &&
41+
"${GITHUB_REF}" == refs/heads/main && "${GITHUB_RUN_ATTEMPT}" == 1 &&
42+
"${LONGHORN_V2_NODE}" =~ ^temporary-v1-[12]$ &&
43+
"${LONGHORN_V2_CONFIRM}" == "observe-longhorn-v2-recovery-${LONGHORN_V2_NODE}" ]]
44+
45+
- name: Checkout the reviewed revision
46+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
47+
with:
48+
ref: ${{ github.sha }}
49+
persist-credentials: false
50+
51+
- name: Require current main
52+
env:
53+
GH_TOKEN: ${{ github.token }}
54+
run: ./scripts/verify-prod-recovery-source.sh "${GITHUB_SHA}"
55+
56+
- name: Set up Go
57+
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
58+
with:
59+
go-version-file: go.mod
60+
cache: false
61+
62+
- name: Build the observer before restoring credentials
63+
run: go build -o "${RUNNER_TEMP}/longhorn-recovery-observer" ./scripts/migrate-longhorn-v2
64+
65+
- name: Install the verified Talos client
66+
run: .github/scripts/setup-talosctl.sh
67+
68+
- name: Install the verified Kubernetes client
69+
shell: bash
70+
env:
71+
KUBECTL_VERSION: v1.36.2
72+
KUBECTL_SHA256: 1e9045ec32bea85da43de85f0065358529ea7c7a152eca78154fba5b58c27d82
73+
run: |
74+
set -euo pipefail
75+
kubectl_path="${RUNNER_TEMP}/longhorn-recovery-kubectl"
76+
curl --disable -fsSL --proto '=https' --proto-redir '=https' --retry 3 --retry-all-errors \
77+
--retry-delay 5 --retry-max-time 120 --connect-timeout 10 --max-time 60 \
78+
"https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" -o "${kubectl_path}"
79+
printf '%s %s\n' "${KUBECTL_SHA256}" "${kubectl_path}" | sha256sum --check
80+
sudo install "${kubectl_path}" /usr/local/bin/kubectl
81+
82+
- name: Observe the existing reset journal and native worker
83+
shell: bash
84+
env:
85+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
86+
TALOS_CONFIG: ${{ secrets.TALOS_CONFIG }}
87+
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
88+
run: |
89+
set +x
90+
set -euo pipefail
91+
umask 077
92+
[[ -n "${KUBE_CONFIG}" && -n "${TALOS_CONFIG}" ]]
93+
credential_dir="$(mktemp -d /dev/shm/longhorn-v2.XXXXXX)"
94+
trap 'rm -rf -- "${credential_dir}"' EXIT
95+
export LONGHORN_V2_CREDENTIAL_DIR="${credential_dir}"
96+
export KUBECONFIG="${credential_dir}/kubeconfig" TALOSCONFIG="${credential_dir}/talosconfig"
97+
printf '%s' "${KUBE_CONFIG}" >"${KUBECONFIG}"
98+
printf '%s' "${TALOS_CONFIG}" >"${TALOSCONFIG}"
99+
unset KUBE_CONFIG TALOS_CONFIG
100+
if ! ./scripts/use-prod-stable-api-endpoint.sh >/dev/null; then
101+
printf '%s\n' 'TEMPORARY_WORKER_RECOVERY=UNVERIFIED stable endpoint unavailable'
102+
exit 2
103+
fi
104+
unset HCLOUD_TOKEN
105+
"${RUNNER_TEMP}/longhorn-recovery-observer"

‎scripts/migrate-longhorn-v2/authorization.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ func authorize(getenv func(string) string, target string) error {
1616
}
1717

1818
func authorizeWorkflow(getenv func(string) string, confirmation string) error {
19+
return authorizeWorkflowRef(getenv, confirmation, ".github/workflows/prepare-longhorn-v2-node.yaml")
20+
}
21+
22+
func authorizeWorkflowRef(getenv func(string) string, confirmation, path string) error {
1923
for key, expected := range map[string]string{
2024
"GITHUB_ACTIONS": "true", "GITHUB_EVENT_NAME": "workflow_dispatch", "GITHUB_REF": "refs/heads/main",
2125
"GITHUB_REPOSITORY": "devantler-tech/platform", "GITHUB_RUN_ATTEMPT": "1", "RUNNER_ENVIRONMENT": "github-hosted",
22-
"GITHUB_WORKFLOW_REF": "devantler-tech/platform/.github/workflows/prepare-longhorn-v2-node.yaml@refs/heads/main",
26+
"GITHUB_WORKFLOW_REF": "devantler-tech/platform/" + path + "@refs/heads/main",
2327
"LONGHORN_V2_CONFIRM": confirmation,
2428
} {
2529
if getenv(key) != expected {

‎scripts/migrate-longhorn-v2/main.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func main() {
2929
authorization = authorizeTemporaryPreparation(os.Getenv, target)
3030
case "prepare-retained-temporary-worker":
3131
authorization = authorizeRetainedTemporaryPreparation(os.Getenv, target)
32+
case observeTemporaryRecoveryOperation:
33+
authorization = authorizeTemporaryRecoveryObservation(os.Getenv, target)
3234
case "benchmark-v1", "benchmark-v2":
3335
authorization = authorizeBenchmark(os.Getenv, operation[len("benchmark-"):])
3436
case recoverUnstartedV1Operation:
@@ -198,8 +200,11 @@ func main() {
198200
fmt.Fprintln(os.Stderr, err)
199201
os.Exit(1)
200202
}
201-
if operation == "prepare-unused-temporary-worker" || operation == "prepare-retained-temporary-worker" {
203+
if operation == "prepare-unused-temporary-worker" || operation == "prepare-retained-temporary-worker" || operation == observeTemporaryRecoveryOperation {
202204
c := client{run: execute, context: "admin@prod", inventoryPools: pools}
205+
if operation == observeTemporaryRecoveryOperation {
206+
c.run = temporaryRecoveryReadCommand
207+
}
203208
nodes, readErr := c.list(ctx, "nodes", "")
204209
if readErr != nil {
205210
fmt.Fprintln(os.Stderr, "Temporary preparation held: node inventory is unreadable.")
@@ -235,6 +240,14 @@ func main() {
235240
}
236241
}
237242
p := temporaryPreparation{preparation: preparation{c: c, target: resolved, name: "longhorn-v2-prepare-" + target, temporarySelection: target, source: os.Getenv("GITHUB_SHA"), owner: os.Getenv("GITHUB_RUN_ID"), pools: pools}, staging: true}
243+
if operation == observeTemporaryRecoveryOperation {
244+
if err = p.observeRecovery(ctx); err != nil {
245+
fmt.Fprintln(os.Stderr, "Temporary worker recovery observation held:", err)
246+
os.Exit(1)
247+
}
248+
fmt.Println("TEMPORARY_WORKER_RECOVERY=OBSERVED writes=0")
249+
return
250+
}
238251
if err = p.prepare(ctx); err != nil {
239252
fmt.Fprintln(os.Stderr, "Temporary worker preparation held:", err)
240253
fmt.Fprintln(os.Stderr, "Preserve its journal and owned cordon; uncertain resets are never replayed.")

‎scripts/migrate-longhorn-v2/temporary_authorization.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ func authorizeRetainedTemporaryPreparation(getenv func(string) string, selection
1717
}
1818
return authorizeWorkflow(getenv, "prepare-retained-longhorn-v2-temporary-v2-1")
1919
}
20+
21+
const observeTemporaryRecoveryOperation = "observe-temporary-recovery"
22+
23+
func authorizeTemporaryRecoveryObservation(getenv func(string) string, selection string) error {
24+
if (selection != "temporary-v1-1" && selection != "temporary-v1-2") ||
25+
getenv("LONGHORN_V2_NODE") != selection || getenv("LONGHORN_V2_OPERATION") != observeTemporaryRecoveryOperation ||
26+
getenv("LONGHORN_V2_DATABASE") != "" {
27+
return errors.New("the explicit unused temporary recovery observation is required")
28+
}
29+
return authorizeWorkflowRef(getenv, "observe-longhorn-v2-recovery-"+selection, ".github/workflows/observe-longhorn-temporary-recovery.yaml")
30+
}

‎scripts/migrate-longhorn-v2/temporary_prepare.go‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ type temporaryPreparation struct {
1818
staging bool
1919
}
2020

21+
// temporaryRecoveryGate carries only source-defined descriptions, so the
22+
// readiness timeout can report the last failed check without native diagnostics.
23+
type temporaryRecoveryGate string
24+
25+
func (g temporaryRecoveryGate) Error() string { return "temporary recovery waiting for " + string(g) }
26+
func (g temporaryRecoveryGate) Unwrap() error { return errInventory }
27+
2128
// prepare advances the separately journaled unused-worker profile, recording reset
2229
// intent before its single request and accepting recovery only after native proof.
2330
// A resumed reset request observes recovery without issuing another reset.
@@ -51,7 +58,15 @@ func (p *temporaryPreparation) prepare(ctx context.Context) error {
5158
}
5259
}
5360
if p.j.Phase == "reset-requested" {
54-
if err := waitReady(ctx, func(ctx context.Context) error { _, err := p.unusedPostState(ctx); return err }); err != nil {
61+
var checkErr error
62+
if err := waitReady(ctx, func(ctx context.Context) error {
63+
_, checkErr = p.unusedPostState(ctx)
64+
return checkErr
65+
}); err != nil {
66+
var gate temporaryRecoveryGate
67+
if errors.As(checkErr, &gate) {
68+
return errors.Join(err, gate)
69+
}
5570
return err
5671
}
5772
var stagedUUID string
@@ -433,27 +448,27 @@ func (p *temporaryPreparation) resetUnused(ctx context.Context) error {
433448
func (p temporaryPreparation) unusedPostState(ctx context.Context) (node object, err error) {
434449
n, address, err := p.node(ctx, true)
435450
if err != nil {
436-
return nil, err
451+
return nil, temporaryRecoveryGate("the original worker and hardware identity")
437452
}
438453
status := valueObject(n, "status")
439454
boot := text(n, "status", "nodeInfo", "bootID")
440455
if !ready(status) || !hugepagesReady(n) || !inventoryBoot.MatchString(boot) || boot == p.j.OriginalBootID {
441-
return nil, errInventory
456+
return nil, temporaryRecoveryGate("a ready worker with huge pages and a new boot")
442457
}
443458
if p.retainsRaw() {
444459
if _, err = p.readRetainedRecovery(ctx, address, boot, false); err != nil && p.j.Phase == "reset-requested" {
445460
_, err = p.readRetainedRecovery(ctx, address, boot, true)
446461
}
447462
if err != nil {
448-
return nil, err
463+
return nil, temporaryRecoveryGate("the retained raw partition and staged layout")
449464
}
450465
lh, err := p.storageNode(ctx)
451466
if err != nil || !unusedStorageFenced(lh) {
452-
return nil, errInventory
467+
return nil, temporaryRecoveryGate("the empty fenced Longhorn node")
453468
}
454469
current, currentAddress, err := p.node(ctx, true)
455470
if err != nil || currentAddress != address || text(current, "status", "nodeInfo", "bootID") != boot {
456-
return nil, errInventory
471+
return nil, temporaryRecoveryGate("a stable worker identity and boot")
457472
}
458473
return current, nil
459474
}
@@ -463,50 +478,50 @@ func (p temporaryPreparation) unusedPostState(ctx context.Context) (node object,
463478
}
464479
reader, closeReader, err := factory(ctx, address)
465480
if err != nil || reader == nil || closeReader == nil {
466-
return nil, errInventory
481+
return nil, temporaryRecoveryGate("a node-bound native reader")
467482
}
468483
defer func() {
469484
if closeReader() != nil {
470485
node = nil
471-
err = errInventory
486+
err = temporaryRecoveryGate("clean native reader shutdown")
472487
}
473488
}()
474489
actualBoot, err := reader.BootID(ctx)
475490
if err != nil || actualBoot != boot {
476-
return nil, errInventory
491+
return nil, temporaryRecoveryGate("the native boot identity matching Kubernetes")
477492
}
478493
if err = p.verifyUnusedLayout(ctx, address); err != nil {
479-
return nil, err
494+
return nil, temporaryRecoveryGate("the reviewed staged volume configuration")
480495
}
481496
raw, err := p.c.talosVolume(ctx, address, "r-longhorn")
482497
if err != nil {
483-
return nil, err
498+
return nil, temporaryRecoveryGate("readable raw volume status")
484499
}
485500
eph, err := p.c.talosVolume(ctx, address, "EPHEMERAL")
486501
if err != nil {
487-
return nil, err
502+
return nil, temporaryRecoveryGate("readable EPHEMERAL volume status")
488503
}
489504
rawGiB := uint64(permanentRawDiskGiB)
490505
if p.staging {
491506
rawGiB = stagingRawDiskGiB
492507
}
493508
if err = verifyEncryptedRawDisk(raw, eph, rawGiB); err != nil {
494-
return nil, err
509+
return nil, temporaryRecoveryGate("the expected encrypted partition geometry")
495510
}
496511
uuid, err := recoveredEphemeralUUID(ctx, address, eph, factory)
497512
if err != nil || p.j.EphemeralUUID == "" || strings.EqualFold(uuid, p.j.EphemeralUUID) {
498-
return nil, errInventory
513+
return nil, temporaryRecoveryGate("the new encrypted EPHEMERAL identity")
499514
}
500515
recheckedBoot, err := reader.BootID(ctx)
501516
if err != nil || recheckedBoot != actualBoot {
502-
return nil, errInventory
517+
return nil, temporaryRecoveryGate("the same native boot after reading storage")
503518
}
504519
lh, err := p.storageNode(ctx)
505520
if err != nil {
506-
return nil, err
521+
return nil, temporaryRecoveryGate("the original Longhorn node identity")
507522
}
508523
if !unusedStorageFenced(lh) {
509-
return nil, errInventory
524+
return nil, temporaryRecoveryGate("the empty fenced Longhorn node")
510525
}
511526
return n, nil
512527
}

‎scripts/migrate-longhorn-v2/temporary_prepare_flow_test.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ func TestUnusedStagingPreparationRequiresTheLargerNativeLayout(t *testing.T) {
4141
}
4242
}
4343

44+
func TestResetRecoveryReportsTheLastSafeReadinessGate(t *testing.T) {
45+
f, p := unusedPreparationAPI(t)
46+
p.staging = true
47+
initial, cancelInitial := context.WithCancel(t.Context())
48+
defer cancelInitial()
49+
f.afterReset = cancelInitial
50+
if err := p.prepare(initial); !errors.Is(err, context.Canceled) || f.base.resets != 1 || p.j.Phase != "reset-requested" {
51+
t.Fatalf("need the interrupted, journaled reset: phase=%s resets=%d err=%v", p.j.Phase, f.base.resets, err)
52+
}
53+
54+
recovery, cancelRecovery := context.WithCancel(t.Context())
55+
defer cancelRecovery()
56+
const privateDiagnostic = "private native command details"
57+
witnessed := false
58+
p.c.run = func(ctx context.Context, input []byte, program string, args ...string) ([]byte, error) {
59+
if program == "talosctl" && len(args) == 5 && args[2] == "volumestatus" && args[3] == "r-longhorn" {
60+
witnessed = true
61+
cancelRecovery()
62+
return nil, errors.New(privateDiagnostic)
63+
}
64+
return f.run(ctx, input, program, args...)
65+
}
66+
err := p.prepare(recovery)
67+
if !witnessed || !errors.Is(err, context.Canceled) ||
68+
!strings.Contains(err.Error(), "temporary recovery waiting for readable raw volume status") ||
69+
strings.Contains(err.Error(), privateDiagnostic) {
70+
t.Fatalf("interrupted recovery did not report its safe failed gate: %v", err)
71+
}
72+
if f.base.resets != 1 || p.j.Phase != "reset-requested" || value(f.base.node, "spec", "unschedulable") != true {
73+
t.Fatalf("recovery gate failure mutated its worker: phase=%s resets=%d", p.j.Phase, f.base.resets)
74+
}
75+
}
76+
4477
func TestResetRecoveryUsesMatchingNativeEphemeralIdentityWhenStatusOmitsUUID(t *testing.T) {
4578
const originalUUID = "12345678-1234-4234-8234-000000000047"
4679
for _, mode := range []string{"new", "original", "wrong partition", "missing"} {

0 commit comments

Comments
 (0)