-
Notifications
You must be signed in to change notification settings - Fork 57
Migrate reconfigure to golang #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
elezar
wants to merge
26
commits into
NVIDIA:main
Choose a base branch
from
elezar:migrate-reconfigure-to-golang
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5ea34a6
Add MIG Reconfigure API for vgpu-device-manager
elezar 89e8bfc
Return formatted errors instead of logging
elezar d4ed26a
Add commandRunnner interface and a basic test
elezar f793f1a
Update vendoring
elezar 6544a19
Add migParted interface for testing
elezar 36f8eef
Add nodeLabeller interface for testing
elezar 9cf3052
Add additional test cases
elezar 997f1ab
TOFIX: Use internal reconfigure API
elezar 5e326b1
TOFIX: foo
elezar 14260b7
Fix CDI enabled
elezar fbfb5a2
TOFIX
elezar 152a49c
More fixes
elezar b687e49
TOFIX: DriverLibrary path is optional
elezar e867eb2
Log application version
elezar 9f26086
TOFIX: Ensure that config state label is set
elezar a31f59a
TOFIX: Use Mkdirall
elezar 6b69ef4
Ensure that clientset is set
elezar 87f983b
Fix Dockerfile lint errors
elezar 2b43091
Add logs for waiting for deletion
elezar 878a2bb
TOFIX: Use cmd to delete pods
elezar 5285e2c
TOFIX: Remove logging
elezar 62cb648
Only restart validator if successful
elezar c5dfa7b
FIX: return from select statement
elezar f4d3c11
Add additional logging
elezar df9f766
Ignore missing pods on shutdown
elezar 675541a
Fix delete
elezar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ package main | |
| import ( | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -28,12 +27,14 @@ import ( | |
| cli "github.com/urfave/cli/v2" | ||
|
|
||
| "github.com/NVIDIA/mig-parted/internal/info" | ||
| "github.com/NVIDIA/mig-parted/pkg/mig/reconfigure" | ||
|
|
||
| v1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/fields" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| "k8s.io/klog/v2" | ||
|
|
||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
@@ -280,6 +281,8 @@ func validateFlags(c *cli.Context) error { | |
| } | ||
|
|
||
| func start(c *cli.Context) error { | ||
| klog.InfoS(fmt.Sprintf("Starting %s", c.App.Name), "version", c.App.Version) | ||
|
|
||
| config, err := clientcmd.BuildConfigFromFlags("", kubeconfigFlag) | ||
| if err != nil { | ||
| return fmt.Errorf("error building kubernetes clientcmd config: %s", err) | ||
|
|
@@ -304,7 +307,7 @@ func start(c *cli.Context) error { | |
| log.Infof("Waiting for change to '%s' label", MigConfigLabel) | ||
| value := migConfig.Get() | ||
| log.Infof("Updating to MIG config: %s", value) | ||
| err := runScript(value, driverLibraryPath, nvidiaSMIPath) | ||
| err := runScript(value, driverLibraryPath, nvidiaSMIPath, clientset) | ||
| if err != nil { | ||
| log.Errorf("Error: %s", err) | ||
| continue | ||
|
|
@@ -371,36 +374,49 @@ func parseGPUCLientsFile(file string) (*GPUClients, error) { | |
| return &clients, nil | ||
| } | ||
|
|
||
| func runScript(migConfigValue string, driverLibraryPath string, nvidiaSMIPath string) error { | ||
| func runScript(migConfigValue string, driverLibraryPath string, nvidiaSMIPath string, clientset *kubernetes.Clientset) error { | ||
| gpuClients, err := parseGPUCLientsFile(gpuClientsFileFlag) | ||
| if err != nil { | ||
| return fmt.Errorf("error parsing host's GPU clients file: %s", err) | ||
| } | ||
|
|
||
| args := []string{ | ||
| "-n", nodeNameFlag, | ||
| "-f", configFileFlag, | ||
| "-c", migConfigValue, | ||
| "-m", hostRootMountFlag, | ||
| "-i", hostNvidiaDirFlag, | ||
| "-o", hostMigManagerStateFileFlag, | ||
| "-g", strings.Join(gpuClients.SystemdServices, ","), | ||
| "-k", hostKubeletSystemdServiceFlag, | ||
| "-p", defaultGPUClientsNamespaceFlag, | ||
| options := []reconfigure.Option{ | ||
| reconfigure.WithNodeName(nodeNameFlag), | ||
| reconfigure.WithMIGPartedConfigFile(configFileFlag), | ||
| reconfigure.WithSelectedMIGConfig(migConfigValue), | ||
| reconfigure.WithHostRootMount(hostRootMountFlag), | ||
| reconfigure.WithHostNVIDIADir(hostNvidiaDirFlag), | ||
| reconfigure.WithHostMIGManagerStateFile(hostMigManagerStateFileFlag), | ||
| reconfigure.WithHostGPUClientServices(gpuClients.SystemdServices...), | ||
| reconfigure.WithHostKubeletService(hostKubeletSystemdServiceFlag), | ||
| reconfigure.WithGPUClientNamespace(defaultGPUClientsNamespaceFlag), | ||
| reconfigure.WithConfigStateLabel(reconfigure.MIGConfigStateLabel), | ||
| reconfigure.WithClientset(clientset), | ||
| } | ||
|
|
||
| if cdiEnabledFlag { | ||
| args = append(args, "-e", "-t", driverRoot, "-a", driverRootCtrPath, "-b", devRoot, "-j", devRootCtrPath, "-l", driverLibraryPath, "-q", nvidiaSMIPath, "-s", nvidiaCDIHookPath) | ||
| options = append(options, | ||
| reconfigure.WithCDIEnabled(cdiEnabledFlag), | ||
| reconfigure.WithDriverRoot(driverRoot), | ||
| reconfigure.WithDriverRootCtrPath(driverRootCtrPath), | ||
| reconfigure.WithDevRoot(devRoot), | ||
| reconfigure.WithDevRootCtrPath(devRootCtrPath), | ||
| reconfigure.WithDriverLibraryPath(driverLibraryPath), | ||
| reconfigure.WithNVIDIASMIPath(nvidiaSMIPath), | ||
| reconfigure.WithNVIDIACDIHookPath(nvidiaCDIHookPath), | ||
| ) | ||
| } | ||
| if withRebootFlag { | ||
| args = append(args, "-r") | ||
| } | ||
| if withShutdownHostGPUClientsFlag { | ||
| args = append(args, "-d") | ||
|
|
||
| options = append(options, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question -- is there any value in appending these options here? Can we add them to the list of options during initialization of the options slice? |
||
| reconfigure.WithAllowReboot(withRebootFlag), | ||
| reconfigure.WithShutdownHostGPUClients(withShutdownHostGPUClientsFlag), | ||
| ) | ||
|
|
||
| reconfigurer, err := reconfigure.New(options...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| cmd := exec.Command(reconfigureScriptFlag, args...) | ||
| cmd.Stdout = os.Stdout | ||
| cmd.Stderr = os.Stderr | ||
| return cmd.Run() | ||
| return reconfigurer.Reconfigure() | ||
| } | ||
|
|
||
| func ContinuouslySyncMigConfigChanges(clientset *kubernetes.Clientset, migConfig *SyncableMigConfig) chan struct{} { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question -- do we actually need the conditional here? Or can we always add these options to the options slice?