Skip to content

Commit e1f0f36

Browse files
cdesiniotiselezar
andcommitted
Deprecate the hook config mode for cri-o
This chagne updates the default cri-o config mode from 'hook' to 'config' and issues a deprecation warning if hook is explicitly selected. Signed-off-by: Christopher Desiniotis <[email protected]> Co-authored-by: Evan Lezar <[email protected]>
1 parent b3ce3a4 commit e1f0f36

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

cmd/nvidia-ctk-installer/container/runtime/crio/crio.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container"
2828
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
29+
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2930
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
3031
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio"
3132
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook"
@@ -35,7 +36,10 @@ import (
3536
const (
3637
Name = "crio"
3738

38-
defaultConfigMode = "hook"
39+
defaultConfigMode = configModeConfig
40+
41+
configModeConfig = "config"
42+
configModeHook = "hook"
3943

4044
// Hook-based settings
4145
defaultHooksDir = "/usr/share/containers/oci/hooks.d"
@@ -88,6 +92,13 @@ func Flags(opts *Options) []cli.Flag {
8892
return flags
8993
}
9094

95+
func (opts *Options) Validate(logger logger.Interface, _ *cli.Command) error {
96+
if opts.configMode == "hook" {
97+
logger.Warningf("The %q config for cri-o is deprecated", opts.configMode)
98+
}
99+
return nil
100+
}
101+
91102
// Setup installs the prestart hook required to launch GPU-enabled containers
92103
func Setup(c *cli.Command, o *container.Options, co *Options) error {
93104
log.Infof("Starting 'setup' for %v", c.Name)

cmd/nvidia-ctk-installer/container/runtime/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime s
146146
}
147147
case containerd.Name:
148148
case crio.Name:
149+
if err := opts.crioOptions.Validate(logger, c); err != nil {
150+
return fmt.Errorf("invalid cri-o config: %w", err)
151+
}
149152
}
150153

151154
// Apply the runtime-specific config changes.

cmd/nvidia-ctk/runtime/configure/configure.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ func (m command) build() *cli.Command {
135135
Value: defaultConfigSource,
136136
},
137137
&cli.StringFlag{
138-
Name: "oci-hook-path",
139-
Usage: "the path to the OCI runtime hook to create if --config-mode=oci-hook is specified. If no path is specified, the generated hook is output to STDOUT.\n\tNote: The use of OCI hooks is deprecated.",
138+
Name: "oci-hook-path",
139+
Usage: "the path to the OCI runtime hook to create if --config-mode=oci-hook is specified. If no path is specified, the generated hook is output to STDOUT.\n" +
140+
"\tNote: The use of OCI hooks is deprecated.",
140141
Destination: &config.hookFilePath,
141142
},
142143
&cli.StringFlag{
@@ -177,13 +178,14 @@ func (m command) build() *cli.Command {
177178
}
178179

179180
func (m command) validateFlags(config *config) error {
180-
if config.mode == "oci-hook" {
181+
if config.mode == "oci-hook" || config.mode == "hook" {
182+
m.logger.Warningf("The %q config-mode is deprecated", config.mode)
181183
if !filepath.IsAbs(config.nvidiaRuntime.hookPath) {
182184
return fmt.Errorf("the NVIDIA runtime hook path %q is not an absolute path", config.nvidiaRuntime.hookPath)
183185
}
184186
return nil
185187
}
186-
if config.mode != "" && config.mode != "config-file" {
188+
if config.mode != "" && config.mode != "config-file" && config.mode != "config" {
187189
m.logger.Warningf("Ignoring unsupported config mode for %v: %q", config.runtime, config.mode)
188190
}
189191
config.mode = "config-file"
@@ -246,9 +248,9 @@ func (m command) validateFlags(config *config) error {
246248
// configureWrapper updates the specified container engine config to enable the NVIDIA runtime
247249
func (m command) configureWrapper(config *config) error {
248250
switch config.mode {
249-
case "oci-hook":
251+
case "oci-hook", "hook":
250252
return m.configureOCIHook(config)
251-
case "config-file":
253+
case "config-file", "config":
252254
return m.configureConfigFile(config)
253255
}
254256
return fmt.Errorf("unsupported config-mode: %v", config.mode)

0 commit comments

Comments
 (0)