Skip to content

Commit b7647f9

Browse files
committed
Add support for systemd-less systems
Add flag to skip all systemd operations Signed-off-by: Alessandro Vinciguerra <alessandro.vinciguerra@postfinance.ch>
1 parent 3b8e48f commit b7647f9

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

cmd/nvidia-mig-manager/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var (
8181
nvidiaCDIHookPath string
8282

8383
readonlyRootFS bool
84+
systemdUnavailable bool
8485
)
8586

8687
type GPUClients struct {
@@ -273,6 +274,12 @@ func main() {
273274
Destination: &readonlyRootFS,
274275
EnvVars: []string{"READONLY_ROOTFS"},
275276
},
277+
&cli.BoolFlag{
278+
Name: "systemd-unavailable",
279+
Usage: "Indicate that systemd is unavailable on the host",
280+
Destination: &systemdUnavailable,
281+
EnvVars: []string{"SYSTEMD_UNAVAILABLE"},
282+
},
276283
}
277284

278285
err := c.Run(os.Args)
@@ -529,6 +536,7 @@ func migReconfigure(ctx context.Context, migConfigValue string, clientset *kuber
529536
DefaultGPUClientsNamespace: defaultGPUClientsNamespaceFlag,
530537
WithReboot: withRebootFlag,
531538
WithShutdownHostGPUClients: withShutdownHostGPUClientsFlag,
539+
SystemdAvailable: !systemdUnavailable,
532540
ReadonlyHost: readonlyRootFS,
533541
}
534542

pkg/mig/reconfigure/reconfigure.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type Options struct {
7676
DriverLibraryPath string
7777
NvidiaSMIPath string
7878
NvidiaCDIHookPath string
79+
SystemdAvailable bool
7980
ReadonlyHost bool
8081
}
8182

@@ -106,9 +107,15 @@ func New(ctx context.Context, clientset *kubernetes.Clientset, migPartedBinary [
106107
_ = os.Setenv("DBUS_SYSTEM_BUS_ADDRESS", hostSystemBusAddress)
107108
}
108109

109-
systemdManager, err := systemd.NewManager(ctx)
110-
if err != nil {
111-
return nil, fmt.Errorf("failed to initialize systemd manager: %w", err)
110+
var systemdManager *systemd.Manager = nil
111+
112+
if opts.SystemdAvailable {
113+
mgr, err := systemd.NewManager(ctx)
114+
if err != nil {
115+
return nil, fmt.Errorf("failed to initialize systemd manager: %w", err)
116+
}
117+
118+
systemdManager = mgr
112119
}
113120

114121
return &Reconfigure{
@@ -300,11 +307,6 @@ func (r *Reconfigure) isConfigAlreadyApplied() bool {
300307

301308
// persistConfigIfNeeded persists the configuration if needed
302309
func (r *Reconfigure) persistConfigIfNeeded() error {
303-
if r.opts.ReadonlyHost {
304-
log.Info("Host root FS is mounted read-only, config cannot be persisted")
305-
return nil
306-
}
307-
308310
if r.opts.HostRootMount == "" || r.opts.HostMigManagerStateFile == "" {
309311
return nil
310312
}
@@ -320,6 +322,11 @@ func (r *Reconfigure) persistConfigIfNeeded() error {
320322

321323
// persistConfig persists the configuration to the state file
322324
func (r *Reconfigure) persistConfig() error {
325+
if r.opts.ReadonlyHost {
326+
log.Info("Host root FS is mounted read-only, config cannot be persisted")
327+
return nil
328+
}
329+
323330
config := fmt.Sprintf(`[Service]
324331
Environment="MIG_PARTED_SELECTED_CONFIG=%s"
325332
`, r.opts.SelectedMigConfig)
@@ -331,6 +338,10 @@ Environment="MIG_PARTED_SELECTED_CONFIG=%s"
331338
return fmt.Errorf("failed to write config to state file: %w", err)
332339
}
333340

341+
if r.systemdManager == nil {
342+
return nil
343+
}
344+
334345
return r.systemdManager.ReloadDaemon()
335346
}
336347

@@ -420,6 +431,11 @@ func (r *Reconfigure) waitForPodsToBeDeleted() error {
420431

421432
// shutdownHostGPUClients shuts down host GPU clients
422433
func (r *Reconfigure) shutdownHostGPUClients() error {
434+
if r.systemdManager == nil {
435+
log.Info("No systemd manager available, not shutting down GPU clients on the host")
436+
return nil
437+
}
438+
423439
log.Info("Shutting down all GPU clients on the host by stopping their systemd services")
424440

425441
services := strings.Split(r.opts.HostGPUClientServices, ",")
@@ -705,6 +721,11 @@ func (r *Reconfigure) createCDISpec() error {
705721
}
706722

707723
func (r *Reconfigure) hostStartSystemdServices() error {
724+
if r.systemdManager == nil {
725+
log.Info("No systemd manager available, not starting anything via systemd")
726+
return nil
727+
}
728+
708729
services := r.stoppedServices
709730
var restartServices []string
710731
if len(services) == 0 {

0 commit comments

Comments
 (0)