Skip to content

Commit e9da2c4

Browse files
authored
fix(storage): pin the signed Longhorn benchmark image (#6553)
* test(storage): preserve benchmark image identity across activation * fix(storage): pin the signed Longhorn benchmark image
1 parent 275258e commit e9da2c4

5 files changed

Lines changed: 44 additions & 14 deletions

File tree

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ func readBenchmark(ctx context.Context, c client, phase string) (object, benchma
121121
return nil, record, errors.New("benchmark journal is malformed")
122122
}
123123
var extra any
124-
if d.Decode(&extra) != io.EOF || !benchmarkNamespaceMatches(record) || record.Phase != phase || record.Image != fioImage || record.Workload != benchmarkWorkload() ||
124+
if d.Decode(&extra) != io.EOF || !benchmarkNamespaceMatches(record) || record.Phase != phase ||
125+
(record.Image != fioImage && record.Image != legacyFioImage) || record.Workload != benchmarkWorkload() ||
125126
!validBenchmarkOwner(record.Run, record.Source) || len(record.Machines) != 3 ||
126127
(record.clientNode() != benchmarkClientNode && record.clientNode() != legacyBenchmarkClientNode) {
127128
return nil, record, errors.New("benchmark journal does not match this reviewed procedure")
@@ -167,8 +168,8 @@ func readBenchmark(ctx context.Context, c client, phase string) (object, benchma
167168

168169
func requireBenchmarkBaseline(ctx context.Context, c client, current []object) error {
169170
_, record, err := readBenchmark(ctx, c, "v1")
170-
if err != nil || !record.Cleaned || len(record.Measurements) != 18 || record.CompletedAt == "" {
171-
return errors.New("the completed, cleaned V1 baseline is required before moving any replicas")
171+
if err != nil || record.Image != fioImage || !record.Cleaned || len(record.Measurements) != 18 || record.CompletedAt == "" {
172+
return errors.New("the completed, cleaned V1 baseline with the pinned benchmark image is required before moving any replicas")
172173
}
173174
if _, err = time.Parse(time.RFC3339, record.CompletedAt); err != nil {
174175
return errors.New("baseline completion time is invalid")
@@ -294,16 +295,16 @@ func (c client) setBenchmarkTag(ctx context.Context, source, tag, name, expected
294295
return err
295296
}
296297

297-
func verifyBenchmarkPod(p object, uid, clientNode string) error {
298+
func verifyBenchmarkPod(p object, uid, clientNode, image string) error {
298299
containers, _ := value(p, "spec", "containers").([]any)
299300
statuses, _ := value(p, "status", "containerStatuses").([]any)
300301
if text(p, "metadata", "uid") != uid || text(p, "spec", "nodeName") != clientNode || len(containers) != 1 || len(statuses) != 1 {
301302
return errors.New("benchmark consumer identity or placement differs")
302303
}
303304
container, _ := containers[0].(object)
304305
status, _ := statuses[0].(object)
305-
digest := strings.Split(fioImage, "@")[1]
306-
if text(container, "image") != fioImage || !reflect.DeepEqual(value(container, "args"), []any{fioScript}) ||
306+
_, digest, pinned := strings.Cut(image, "@")
307+
if !pinned || digest == "" || text(container, "image") != image || !reflect.DeepEqual(value(container, "args"), []any{fioScript}) ||
307308
!reflect.DeepEqual(value(container, "command"), []any{"/bin/sh", "-ec"}) || value(p, "spec", "automountServiceAccountToken") != false ||
308309
value(p, "spec", "hostUsers") != false ||
309310
text(status, "name") != "fio" || !strings.HasSuffix(text(status, "imageID"), digest) {
@@ -330,6 +331,9 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
330331
if err != nil || !baseline.Cleaned {
331332
return errors.New("the baseline's benchmark client is unverified")
332333
}
334+
if baseline.Image != fioImage {
335+
return errors.New("both data engines must be measured with the same pinned benchmark image")
336+
}
333337
clientNode = baseline.clientNode()
334338
}
335339
var v1Runtime *benchmarkV1Runtime
@@ -402,7 +406,7 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
402406
if err != nil || text(current, "status", "phase") != "Running" {
403407
return errors.New("benchmark consumer is not running")
404408
}
405-
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode); err != nil {
409+
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode, record.Image); err != nil {
406410
return err
407411
}
408412
claim, err = c.get(ctx, "persistentvolumeclaim", record.Namespace, "fio-data", false)
@@ -432,7 +436,7 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
432436
if err != nil {
433437
return err
434438
}
435-
if err = verifyBenchmarkPod(pod, text(created["Pod"], "metadata", "uid"), clientNode); err != nil {
439+
if err = verifyBenchmarkPod(pod, text(created["Pod"], "metadata", "uid"), clientNode, record.Image); err != nil {
436440
return err
437441
}
438442
record.CPU, err = captureBenchmarkCPU(ctx, c, phase, pod)
@@ -461,7 +465,7 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
461465
if err != nil {
462466
return err
463467
}
464-
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode); err != nil {
468+
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode, record.Image); err != nil {
465469
return err
466470
}
467471
if _, err = c.kubectl(ctx, nil, "exec", "--namespace="+record.Namespace, "fio", "--container=fio", "--", "/bin/sh", "-ec", "touch /tmp/benchmark-start"); err != nil {
@@ -474,7 +478,7 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
474478
if err != nil {
475479
return err
476480
}
477-
if err = verifyBenchmarkPod(p, text(pod, "metadata", "uid"), clientNode); err != nil {
481+
if err = verifyBenchmarkPod(p, text(pod, "metadata", "uid"), clientNode, record.Image); err != nil {
478482
return err
479483
}
480484
switch text(p, "status", "phase") {
@@ -525,7 +529,7 @@ func runBenchmark(ctx context.Context, c client, source, runID, phase string) er
525529
if err != nil {
526530
return err
527531
}
528-
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode); err != nil {
532+
if err = verifyBenchmarkPod(current, text(pod, "metadata", "uid"), clientNode, record.Image); err != nil {
529533
return err
530534
}
531535
endingCPU, err := captureBenchmarkCPU(ctx, c, phase, current)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ const benchmarkUnprovenSamples = 3
1818
// benchmarkCompletionLimit lets the Pod report Failed at its deadline rather than cutting it short.
1919
const benchmarkCompletionLimit = (benchmarkDeadlineSeconds + 120) * time.Second
2020

21-
// The linux/amd64 manifest of the fio 3.41 image used by longhorn-tests.
22-
const fioImage = "docker.io/openeuler/fio:3.41-oe2403sp2@sha256:335e14c142c65c8da4f83172d53387af7c9cd8336910107a4504ba3a5ddbba7f"
21+
// Older journals bind their scratch Pod to the original Longhorn test image.
22+
const legacyFioImage = "docker.io/openeuler/fio:3.41-oe2403sp2@sha256:335e14c142c65c8da4f83172d53387af7c9cd8336910107a4504ba3a5ddbba7f"
23+
24+
// Use the same signed Linux amd64 image for both benchmark phases.
25+
const fioImage = "ghcr.io/devantler-tech/platform-longhorn-fio:3.41-35354eb7fab273d43729eda40d1ff76046559294-1@sha256:20222110de9f5c38bbcf91b1ccd0d3b9406717f7ca02922183061e1403776631"
2326

2427
const fioScript = `set -eu
2528
while [ ! -f /tmp/benchmark-start ]; do sleep 2; done

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func observeBoundBenchmarkAssets(ctx context.Context, c client, record benchmark
8181
}
8282
pod, claim, class := observed["Pod"], observed["PersistentVolumeClaim"], observed["StorageClass"]
8383
pv, backend := observed["PersistentVolume"], observed["LonghornVolume"]
84-
if pod != nil && (text(pod, "status", "phase") != "Failed" || verifyBenchmarkPod(pod, record.Resources["Pod"].UID, record.clientNode()) != nil) {
84+
if pod != nil && (text(pod, "status", "phase") != "Failed" || verifyBenchmarkPod(pod, record.Resources["Pod"].UID, record.clientNode(), record.Image) != nil) {
8585
return nil, errors.New("the recorded fio Pod is not the failed original consumer")
8686
}
8787
if claim != nil && (text(claim, "status", "phase") != "Bound" || text(claim, "spec", "volumeName") != record.Resources["PersistentVolume"].Name ||

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,25 @@ func TestBoundRecoveryValidatesOriginalStoppedStorageGraph(t *testing.T) {
152152
})
153153
}
154154
}
155+
156+
func TestBoundBenchmarkRecoveryUsesTheImageRecordedAtLaunch(t *testing.T) {
157+
record, observed := unstartedBenchmarkFixture(t)
158+
pod := observed["Pod"]
159+
pod["spec"].(object)["nodeName"] = record.clientNode()
160+
container := pod["spec"].(object)["containers"].([]any)[0].(object)
161+
container["image"] = legacyFioImage
162+
pod["status"] = object{"phase": "Failed", "containerStatuses": []any{object{
163+
"name": "fio", "imageID": legacyFioImage,
164+
}}}
165+
uid := record.Resources["Pod"].UID
166+
if err := verifyBenchmarkPod(pod, uid, record.clientNode(), legacyFioImage); err != nil {
167+
t.Fatal("the reviewed legacy benchmark Pod cannot be verified:", err)
168+
}
169+
if verifyBenchmarkPod(pod, uid, record.clientNode(), "registry.example.invalid/other@sha256:"+strings.Repeat("a", 64)) == nil {
170+
t.Fatal("the original Pod was accepted for a different benchmark image")
171+
}
172+
container["image"] = "registry.example.invalid/unpinned"
173+
if verifyBenchmarkPod(pod, uid, record.clientNode(), text(container, "image")) == nil {
174+
t.Fatal("an unpinned benchmark Pod was accepted")
175+
}
176+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func TestComparisonCannotRunWithAnIncompleteOrForeignBaseline(t *testing.T) {
115115
"incomplete cleanup": func(r *benchmarkRecord) { r.Cleaned = false },
116116
"missing trial": func(r *benchmarkRecord) { r.Measurements = r.Measurements[1:] },
117117
"wrong image": func(r *benchmarkRecord) { r.Image = "unpinned" },
118+
"legacy image": func(r *benchmarkRecord) { r.Image = legacyFioImage },
118119
"changed workload": func(r *benchmarkRecord) { r.Workload = "changed" },
119120
"missing namespace identity": func(r *benchmarkRecord) { r.NamespaceUID = "" },
120121
"lost resource identities": func(r *benchmarkRecord) { r.Resources = nil },

0 commit comments

Comments
 (0)