Skip to content

Commit 0254396

Browse files
committed
Make local verification and certificate rotation tests deterministic
Keep asset tests independent of registry pulls and model certificate rotation without relying on filesystem timestamp resolution. Allow license verification in temporary worktrees without VCS stamping. Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
1 parent 999fb75 commit 0254396

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎cmd/atelet/sandbox_prewarm_test.go‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,37 +359,28 @@ func TestSandboxAssetPrewarmDownloads(t *testing.T) {
359359
prewarmMaxJitter = 0
360360
t.Cleanup(func() { nodepath.StaticFilesDir, prewarmMaxJitter = origDir, origJitter })
361361

362-
host := imageVolumeTestRegistry(t)
363-
pauseRef := host + "/pause:3.10"
364-
pushPauseImage(t, pauseRef)
365-
366362
content := []byte("runsc binary bytes")
367363
sha := fmt.Sprintf("%x", sha256.Sum256(content))
368364
cfg := gvisorConfig("gvisor-default", "gs://bucket/runsc", sha)
369-
cfg.Spec.PauseImage = pauseRef
365+
cfg.Spec.PauseImage = ""
370366

371367
ctx := t.Context()
372368
client := fake.NewSimpleClientset(cfg)
373369
factory := externalversions.NewSharedInformerFactory(client, 0)
374370
informer := factory.Api().V1alpha1().SandboxConfigs().Informer()
375371

376-
store, err := imagecache.New(t.TempDir())
377-
if err != nil {
378-
t.Fatalf("imagecache.New: %v", err)
379-
}
380372
herder := &AteomHerder{anonGCSClient: fakeObjectStorage{data: content}}
381373
// Handler first, informer start second, mirroring main: atelet startup
382374
// must never wait on this informer's sync, and the initial List replays
383375
// the pre-existing config into the handler as an Add.
384-
p, err := startSandboxAssetPrewarm(ctx, informer, herder, store, false)
376+
p, err := startSandboxAssetPrewarm(ctx, informer, herder, nil, false)
385377
if err != nil {
386378
t.Fatalf("startSandboxAssetPrewarm: %v", err)
387379
}
388380
// The worker reads the patched globals above. t.Context() is canceled
389381
// before cleanups run, and cleanups run last-registered-first, so this
390382
// joins the worker before the earlier cleanup restores the globals —
391-
// without it the restore races the worker's tail (pause-image pull
392-
// after the asset lands) and trips the race detector.
383+
// without it the restore can race the worker's tail.
393384
t.Cleanup(p.wait)
394385
stopCh := make(chan struct{})
395386
defer close(stopCh)

‎cmd/atelet/tlsconfig_test.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ func TestAteletServerTLSConfigReloadsCACertsWithoutRestart(t *testing.T) {
4949
t.Fatalf("GetConfigForClient() first call error = %v", err)
5050
}
5151

52-
if err := os.WriteFile(path, testCertPEM(t), 0o600); err != nil {
52+
// Replace the file like a projected-volume rotation, even when writes
53+
// share a filesystem timestamp.
54+
rotatedPath := path + ".rotated"
55+
if err := os.WriteFile(rotatedPath, testCertPEM(t), 0o600); err != nil {
5356
t.Fatalf("WriteFile() error = %v", err)
5457
}
58+
if err := os.Rename(rotatedPath, path); err != nil {
59+
t.Fatalf("Rename() error = %v", err)
60+
}
5561

5662
after, err := cfg.GetConfigForClient(nil)
5763
if err != nil {

‎hack/update/licenses.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ OUTDIR="_LICENSES" # under $ROOT
2424
# Ensure the tool is built and up-to-date
2525
GO_LICENSES_BIN="$(bash "${ROOT}/hack/run-tool.sh" --print-bin-path go-licenses)"
2626

27+
# go-licenses runs in temporary verification worktrees that do not have enough
28+
# VCS metadata for Go's build stamping.
29+
if [[ -n "${GOFLAGS:-}" ]]; then
30+
export GOFLAGS="${GOFLAGS} -buildvcs=false"
31+
else
32+
export GOFLAGS="-buildvcs=false"
33+
fi
34+
2735
# Clean out previous licenses
2836
rm -rf "${OUTDIR}"
2937
mkdir -p "${OUTDIR}"

‎internal/volume/csi/tls_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ func TestCAPoolCache_HitAndFileChange(t *testing.T) {
391391

392392
// Modify the file.
393393
writeFile(t, caPath, ca.certPEM())
394+
// Advance mtime explicitly; consecutive writes can share a filesystem tick.
395+
modified := cache.fi.ModTime().Add(time.Second)
396+
if err := os.Chtimes(caPath, modified, modified); err != nil {
397+
t.Fatal(err)
398+
}
394399

395400
// 3rd call should detect file change and return a newly parsed pool.
396401
pool3, err := cache.getCertPool()

0 commit comments

Comments
 (0)