@@ -26,6 +26,7 @@ import (
2626
2727 "github.com/urfave/cli/v2"
2828
29+ "k8s.io/dynamic-resource-allocation/kubeletplugin"
2930 "k8s.io/klog/v2"
3031
3132 "github.com/NVIDIA/k8s-dra-driver-gpu/internal/info"
@@ -34,7 +35,6 @@ import (
3435
3536const (
3637 DriverName = "compute-domain.nvidia.com"
37- DriverPluginPath = "/var/lib/kubelet/plugins/" + DriverName
3838 DriverPluginCheckpointFileBasename = "checkpoint.json"
3939)
4040
@@ -43,19 +43,25 @@ type Flags struct {
4343 loggingConfig * flags.LoggingConfig
4444 featureGateConfig * flags.FeatureGateConfig
4545
46- nodeName string
47- namespace string
48- cdiRoot string
49- containerDriverRoot string
50- hostDriverRoot string
51- nvidiaCDIHookPath string
46+ nodeName string
47+ namespace string
48+ cdiRoot string
49+ containerDriverRoot string
50+ hostDriverRoot string
51+ nvidiaCDIHookPath string
52+ kubeletRegistrarDirectoryPath string
53+ kubeletPluginsDirectoryPath string
5254}
5355
5456type Config struct {
5557 flags * Flags
5658 clientsets flags.ClientSets
5759}
5860
61+ func (c Config ) DriverPluginPath () string {
62+ return filepath .Join (c .flags .kubeletPluginsDirectoryPath , DriverName )
63+ }
64+
5965func main () {
6066 if err := newApp ().Run (os .Args ); err != nil {
6167 fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
@@ -111,6 +117,20 @@ func newApp() *cli.App {
111117 Destination : & flags .nvidiaCDIHookPath ,
112118 EnvVars : []string {"NVIDIA_CDI_HOOK_PATH" },
113119 },
120+ & cli.StringFlag {
121+ Name : "kubelet-registrar-directory-path" ,
122+ Usage : "Absolute path to the directory where kubelet stores plugin registrations." ,
123+ Value : kubeletplugin .KubeletRegistryDir ,
124+ Destination : & flags .kubeletRegistrarDirectoryPath ,
125+ EnvVars : []string {"KUBELET_REGISTRAR_DIRECTORY_PATH" },
126+ },
127+ & cli.StringFlag {
128+ Name : "kubelet-plugins-directory-path" ,
129+ Usage : "Absolute path to the directory where kubelet stores plugin data." ,
130+ Value : kubeletplugin .KubeletPluginsDir ,
131+ Destination : & flags .kubeletPluginsDirectoryPath ,
132+ EnvVars : []string {"KUBELET_PLUGINS_DIRECTORY_PATH" },
133+ },
114134 }
115135 cliFlags = append (cliFlags , flags .kubeClientConfig .Flags ()... )
116136 cliFlags = append (cliFlags , flags .featureGateConfig .Flags ()... )
@@ -158,13 +178,13 @@ func newApp() *cli.App {
158178// StartPlugin initializes and runs the compute domain kubelet plugin.
159179func StartPlugin (ctx context.Context , config * Config ) error {
160180 // Create the plugin directory
161- err := os .MkdirAll (DriverPluginPath , 0750 )
181+ err := os .MkdirAll (config . DriverPluginPath () , 0750 )
162182 if err != nil {
163183 return err
164184 }
165185
166186 // Setup nvidia-cdi-hook binary
167- if err := config .flags . setNvidiaCDIHookPath (); err != nil {
187+ if err := config .setNvidiaCDIHookPath (); err != nil {
168188 return fmt .Errorf ("error setting up nvidia-cdi-hook: %w" , err )
169189 }
170190
@@ -215,13 +235,13 @@ func StartPlugin(ctx context.Context, config *Config) error {
215235// to this path. The /usr/bin/nvidia-cdi-hook is present in the current
216236// container image because it is copied from the toolkit image into this
217237// container at build time.
218- func (f * Flags ) setNvidiaCDIHookPath () error {
219- if f .nvidiaCDIHookPath != "" {
238+ func (c Config ) setNvidiaCDIHookPath () error {
239+ if c . flags .nvidiaCDIHookPath != "" {
220240 return nil
221241 }
222242
223243 sourcePath := "/usr/bin/nvidia-cdi-hook"
224- targetPath := filepath .Join (DriverPluginPath , "nvidia-cdi-hook" )
244+ targetPath := filepath .Join (c . DriverPluginPath () , "nvidia-cdi-hook" )
225245
226246 input , err := os .ReadFile (sourcePath )
227247 if err != nil {
@@ -232,7 +252,7 @@ func (f *Flags) setNvidiaCDIHookPath() error {
232252 return fmt .Errorf ("error copying nvidia-cdi-hook: %w" , err )
233253 }
234254
235- f .nvidiaCDIHookPath = targetPath
255+ c . flags .nvidiaCDIHookPath = targetPath
236256
237257 return nil
238258}
0 commit comments