Skip to content

Commit 4d23e73

Browse files
author
Rafael Garcia
committed
system: use context loggers in initrd building
Replace fmt.Printf calls with proper context loggers so messages appear in structured logs with consistent formatting.
1 parent 8d610e9 commit 4d23e73

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/devices/reconcile_test.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (m *mockLivenessChecker) ListAllInstanceDevices(ctx context.Context) map[st
3838
return m.instanceDevices
3939
}
4040

41+
func (m *mockLivenessChecker) DetectSuspiciousVMMProcesses(ctx context.Context) int {
42+
return 0 // Mock returns no suspicious processes
43+
}
44+
4145
func (m *mockLivenessChecker) setRunning(instanceID string, running bool) {
4246
m.runningInstances[instanceID] = running
4347
}
@@ -563,21 +567,6 @@ func TestResetOrphanedDevice_NonExistentPCIAddress(t *testing.T) {
563567
// The key is it doesn't panic
564568
}
565569

566-
// TestDetectSuspiciousVMMProcesses_NoPgrep tests that detection handles
567-
// missing pgrep gracefully (e.g., in minimal containers)
568-
func TestDetectSuspiciousVMMProcesses_NoPgrep(t *testing.T) {
569-
mgr, _, _ := setupTestManager(t)
570-
ctx := context.Background()
571-
572-
stats := &reconcileStats{}
573-
574-
// This test just verifies no panic when pgrep isn't available
575-
// or returns no results
576-
mgr.detectSuspiciousVMMProcesses(ctx, stats)
577-
578-
// No assertions needed - we just want to ensure no panic
579-
}
580-
581570
// Helper function for testing: verify device directory structure
582571
func verifyDeviceDir(t *testing.T, p *paths.Paths, deviceID string) bool {
583572
t.Helper()

lib/system/initrd.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/onkernel/hypeman/lib/images"
18+
"github.com/onkernel/hypeman/lib/logger"
1819
)
1920

2021
const alpineBaseImage = "alpine:3.22"
@@ -62,7 +63,8 @@ func (m *manager) buildInitrd(ctx context.Context, arch string) (string, error)
6263
// Add NVIDIA kernel modules (for GPU passthrough support)
6364
if err := m.addNvidiaModules(ctx, rootfsDir, arch); err != nil {
6465
// Log but don't fail - NVIDIA modules are optional (not available on all architectures)
65-
fmt.Printf("initrd: skipping NVIDIA modules: %v\n", err)
66+
log := logger.FromContext(ctx)
67+
log.InfoContext(ctx, "skipping NVIDIA modules", "error", err)
6668
}
6769

6870
// Write generated init script
@@ -205,7 +207,8 @@ func (m *manager) addNvidiaModules(ctx context.Context, rootfsDir, arch string)
205207
// Add userspace driver libraries (libcuda.so, libnvidia-ml.so, nvidia-smi, etc.)
206208
// These are injected into containers at boot time - see lib/devices/GPU.md
207209
if err := m.addNvidiaDriverLibs(ctx, rootfsDir, arch); err != nil {
208-
fmt.Printf("initrd: warning: could not add nvidia driver libs: %v\n", err)
210+
log := logger.FromContext(ctx)
211+
log.WarnContext(ctx, "could not add nvidia driver libs", "error", err)
209212
// Don't fail - kernel modules can still work, but containers won't have driver libs
210213
}
211214

@@ -252,7 +255,8 @@ func (m *manager) addNvidiaDriverLibs(ctx context.Context, rootfsDir, arch strin
252255
return fmt.Errorf("extract nvidia driver libs: %w", err)
253256
}
254257

255-
fmt.Printf("initrd: added NVIDIA driver libraries from %s\n", url)
258+
log := logger.FromContext(ctx)
259+
log.InfoContext(ctx, "added NVIDIA driver libraries", "url", url)
256260
return nil
257261
}
258262

0 commit comments

Comments
 (0)