@@ -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 = "gpu.nvidia.com"
37- DriverPluginPath = "/var/lib/kubelet/plugins/" + DriverName
3838 DriverPluginCheckpointFileBasename = "checkpoint.json"
3939)
4040
@@ -43,20 +43,26 @@ 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
52- imageName string
46+ nodeName string
47+ namespace string
48+ cdiRoot string
49+ containerDriverRoot string
50+ hostDriverRoot string
51+ nvidiaCDIHookPath string
52+ imageName string
53+ kubeletRegistrarDirectoryPath string
54+ kubeletPluginsDirectoryPath string
5355}
5456
5557type Config struct {
5658 flags * Flags
5759 clientsets flags.ClientSets
5860}
5961
62+ func (c Config ) DriverPluginPath () string {
63+ return filepath .Join (c .flags .kubeletPluginsDirectoryPath , DriverName )
64+ }
65+
6066func main () {
6167 if err := newApp ().Run (os .Args ); err != nil {
6268 fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
@@ -119,6 +125,20 @@ func newApp() *cli.App {
119125 Destination : & flags .imageName ,
120126 EnvVars : []string {"IMAGE_NAME" },
121127 },
128+ & cli.StringFlag {
129+ Name : "kubelet-registrar-directory-path" ,
130+ Usage : "Absolute path to the directory where kubelet stores plugin registrations." ,
131+ Value : kubeletplugin .KubeletRegistryDir ,
132+ Destination : & flags .kubeletRegistrarDirectoryPath ,
133+ EnvVars : []string {"KUBELET_REGISTRAR_DIRECTORY_PATH" },
134+ },
135+ & cli.StringFlag {
136+ Name : "kubelet-plugins-directory-path" ,
137+ Usage : "Absolute path to the directory where kubelet stores plugin data." ,
138+ Value : kubeletplugin .KubeletPluginsDir ,
139+ Destination : & flags .kubeletPluginsDirectoryPath ,
140+ EnvVars : []string {"KUBELET_PLUGINS_DIRECTORY_PATH" },
141+ },
122142 }
123143 cliFlags = append (cliFlags , flags .kubeClientConfig .Flags ()... )
124144 cliFlags = append (cliFlags , flags .featureGateConfig .Flags ()... )
@@ -166,13 +186,13 @@ func newApp() *cli.App {
166186// StartPlugin initializes and runs the GPU kubelet plugin.
167187func StartPlugin (ctx context.Context , config * Config ) error {
168188 // Create the plugin directory
169- err := os .MkdirAll (DriverPluginPath , 0750 )
189+ err := os .MkdirAll (config . DriverPluginPath () , 0750 )
170190 if err != nil {
171191 return err
172192 }
173193
174194 // Setup nvidia-cdi-hook binary
175- if err := config .flags . setNvidiaCDIHookPath (); err != nil {
195+ if err := config .setNvidiaCDIHookPath (); err != nil {
176196 return fmt .Errorf ("error setting up nvidia-cdi-hook: %w" , err )
177197 }
178198
@@ -216,19 +236,20 @@ func StartPlugin(ctx context.Context, config *Config) error {
216236 return nil
217237}
218238
239+ // change to config
219240// If 'f.nvidiaCDIHookPath' is already set (from the command line), do nothing.
220241// If 'f.nvidiaCDIHookPath' is empty, it copies the nvidia-cdi-hook binary from
221242// /usr/bin/nvidia-cdi-hook to DriverPluginPath and sets 'f.nvidiaCDIHookPath'
222243// to this path. The /usr/bin/nvidia-cdi-hook is present in the current
223244// container image because it is copied from the toolkit image into this
224245// container at build time.
225- func (f * Flags ) setNvidiaCDIHookPath () error {
226- if f .nvidiaCDIHookPath != "" {
246+ func (c Config ) setNvidiaCDIHookPath () error {
247+ if c . flags .nvidiaCDIHookPath != "" {
227248 return nil
228249 }
229250
230251 sourcePath := "/usr/bin/nvidia-cdi-hook"
231- targetPath := filepath .Join (DriverPluginPath , "nvidia-cdi-hook" )
252+ targetPath := filepath .Join (c . DriverPluginPath () , "nvidia-cdi-hook" )
232253
233254 input , err := os .ReadFile (sourcePath )
234255 if err != nil {
@@ -239,7 +260,7 @@ func (f *Flags) setNvidiaCDIHookPath() error {
239260 return fmt .Errorf ("error copying nvidia-cdi-hook: %w" , err )
240261 }
241262
242- f .nvidiaCDIHookPath = targetPath
263+ c . flags .nvidiaCDIHookPath = targetPath
243264
244265 return nil
245266}
0 commit comments