Skip to content

Conversation

@elezar
Copy link
Member

@elezar elezar commented Jul 10, 2025

This change migrates the mig-reconfigure implementation from NVIDIA/vgpu-device-manager#93 to a package in mig-parted so that it can be shared between the mig-manager and the vgpu-device-manager.

We will extend the API to support the mig-manager use case as a follow-up.

See #216

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the mig-reconfigure implementation from the vgpu-device-manager repository to a shared package in mig-parted, enabling both mig-manager and vgpu-device-manager to utilize the same functionality.

  • Creates a new pkg/mig/reconfigure package with configuration, validation, and execution logic
  • Implements validation for systemd service names using custom validators
  • Provides comprehensive test coverage using mocked interfaces

Reviewed Changes

Copilot reviewed 9 out of 194 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/mig/reconfigure/reconfigure.go Core implementation of MIG reconfiguration logic with systemd service management
pkg/mig/reconfigure/options.go Configuration options and functional option pattern for API construction
pkg/mig/reconfigure/validate.go Validation logic including custom systemd service name validator
pkg/mig/reconfigure/api.go Public API interfaces and constants
pkg/mig/reconfigure/reconfigure_test.go Comprehensive test suite with mocked dependencies
pkg/mig/reconfigure/*_mock.go Generated mock implementations for testing
go.mod Added validator dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.


err := validate.RegisterValidation("systemd_service_name", validateSystemdServiceName)
if err != nil {
return fmt.Errorf("unable to registre systemd service name validator: %w", err)
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word 'registre' is misspelled. It should be 'register'.

Suggested change
return fmt.Errorf("unable to registre systemd service name validator: %w", err)
return fmt.Errorf("unable to register systemd service name validator: %w", err)

Copilot uses AI. Check for mistakes.
expectedError: nil,
},
{
description: "reconfigure exists if config is applied",
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word 'exists' should be 'exits' to match the similar test case on line 131.

Suggested change
description: "reconfigure exists if config is applied",
description: "reconfigure exits if config is applied",

Copilot uses AI. Check for mistakes.
// TODO: Define the validation schema.
SelectedMIGConfig string `validate:"required"`

// DriverLibrayPath is the path to libnvidia-ml.so.1 in the container.
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word 'DriverLibrayPath' is misspelled. It should be 'DriverLibraryPath'.

Suggested change
// DriverLibrayPath is the path to libnvidia-ml.so.1 in the container.
// DriverLibraryPath is the path to libnvidia-ml.so.1 in the container.

Copilot uses AI. Check for mistakes.
}

cmd = exec.Command("chroot", opts.HostRootMount, "systemctl", "-q", "is-enabled", service) // #nosec G204 -- HostRootMount validated via dirpath, service validated via systemd_service_name.
if err := cmd.Run(); err != nil {
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate check of the same command executed on line 331. Consider extracting this repeated logic into a helper function to reduce code duplication.

Suggested change
if err := cmd.Run(); err != nil {
if err := runSystemctlIsEnabled(opts.HostRootMount, service); err != nil {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@ArangoGutierrez ArangoGutierrez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Nits

@@ -0,0 +1,40 @@
package reconfigure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: License header

@@ -0,0 +1,132 @@
package reconfigure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: License header

This change adds a mig/reconfigure package that implements the
functionality added to the vgpu-device-manager.

Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
@elezar elezar force-pushed the add-reconfigure-api branch from e9f7a10 to 9cf3052 Compare September 16, 2025 12:27
return false
}

cmd = exec.Command("chroot", opts.HostRootMount, "systemctl", "-q", "is-enabled", service) // #nosec G204 -- HostRootMount validated via dirpath, service validated via systemd_service_name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on using this library to invoke systemctl functions?

https://github.com/taigrr/systemctl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please disregard the above library, they too are just shelling out and invoking the systemctl command

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we will need to use coreos/go-systemd to replace the shell invocations here - https://github.com/coreos/go-systemd

I found this blog quite helpul - https://blog.gripdev.xyz/2024/09/27/golang-restart-systemd-unit/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants