Skip to content
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

Properly handle graceful shutdown of the kubelet plugin #197

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/nvidia-dra-plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) {
return driver, nil
}

func (d *driver) Shutdown(ctx context.Context) error {
func (d *driver) Shutdown() error {
if d == nil {
return nil
}
d.plugin.Stop()
return nil
}
Expand Down
25 changes: 15 additions & 10 deletions cmd/nvidia-dra-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,24 @@ func StartPlugin(ctx context.Context, config *Config) error {
return fmt.Errorf("path for cdi file generation is not a directory: '%v'", config.flags.cdiRoot)
}

driver, err := NewDriver(ctx, config)
if err != nil {
return err
}

sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-sigc
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

var driver *driver
ctx, cancel := context.WithCancel(ctx)
defer func() {
cancel()
if err := driver.Shutdown(); err != nil {
klog.Errorf("Unable to cleanly shutdown driver: %v", err)
}
}()

err = driver.Shutdown(ctx)
driver, err = NewDriver(ctx, config)
if err != nil {
klog.Errorf("Unable to cleanly shutdown driver: %v", err)
return fmt.Errorf("error creating driver: %w", err)
}

<-sigs

return nil
}
4 changes: 1 addition & 3 deletions deployments/helm/k8s-dra-driver/templates/kubeletplugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ spec:
command: ["bash", "-c"]
args:
- |-
trap 'exit 0' TERM
# TODO: Masking of the params file is done below to allow nvkind to
# selectively exclude certain GPUs from being visible to the driver.
# At present, this is only feasible with a host-mounted driver where
Expand All @@ -69,8 +68,7 @@ spec:
sed -i 's/^ModifyDeviceFiles: 1$/ModifyDeviceFiles: 0/' root/gpu-params
mount --bind root/gpu-params /proc/driver/nvidia/params
fi
nvidia-dra-plugin &
wait
nvidia-dra-plugin
resources:
{{- toYaml .Values.kubeletPlugin.containers.plugin.resources | nindent 10 }}
env:
Expand Down