Move default runtime validation to its own function
Since we want to validate the default runtime separately when
reloading the runtime config we factor out default runtime
validation into a ValidateDefaultRuntime method.
@@ -965,21 +965,8 @@ func (c *RuntimeConfig) Validate(systemContext *types.SystemContext, onExecution
return err
}
- // check we do have at least a runtime
- if _, ok := c.Runtimes[c.DefaultRuntime]; !ok {
- // Set the default runtime to "runc" if default_runtime is not set
- if c.DefaultRuntime == "" {
- logrus.Debugf("Defaulting to %q as the runtime since default_runtime is not set", defaultRuntime)
- // The default config sets runc and its path in the runtimes map, so check for that
- // first. If it does not exist then we add runc + its path to the runtimes map.
- if _, ok := c.Runtimes[defaultRuntime]; !ok {
- c.Runtimes[defaultRuntime] = defaultRuntimeHandler()
- }
- // Set the DefaultRuntime to runc so we don't fail further along in the code
- c.DefaultRuntime = defaultRuntime
- } else {
- return fmt.Errorf("default_runtime set to %q, but no runtime entry table [crio.runtime.runtimes.%s] was found", c.DefaultRuntime, c.DefaultRuntime)
- }
+ if err := c.ValidateDefaultRuntime(); err != nil {
+ return err
}
if c.LogSizeMax >= 0 && c.LogSizeMax < OCIBufSize {
@@ -1110,6 +1097,27 @@ func (c *RuntimeConfig) Validate(systemContext *types.SystemContext, onExecution
return nil
}
+// ValidateDefaultRuntime ensures that the default runtime is set and valid.
+func (c *RuntimeConfig) ValidateDefaultRuntime() error {
+ // check we do have at least a runtime
+ if _, ok := c.Runtimes[c.DefaultRuntime]; !ok {
+ // Set the default runtime to "runc" if default_runtime is not set
+ if c.DefaultRuntime == "" {
+ logrus.Debugf("Defaulting to %q as the runtime since default_runtime is not set", defaultRuntime)
+ // The default config sets runc and its path in the runtimes map, so check for that
+ // first. If it does not exist then we add runc + its path to the runtimes map.
+ if _, ok := c.Runtimes[defaultRuntime]; !ok {
+ c.Runtimes[defaultRuntime] = defaultRuntimeHandler()
+ }
+ // Set the DefaultRuntime to runc so we don't fail further along in the code
+ c.DefaultRuntime = defaultRuntime
+ } else {
+ return fmt.Errorf("default_runtime set to %q, but no runtime entry table [crio.runtime.runtimes.%s] was found", c.DefaultRuntime, c.DefaultRuntime)
+ }
+ }
+ return nil
+}
+
func defaultRuntimeHandler() *RuntimeHandler {
return &RuntimeHandler{
RuntimeType: DefaultRuntimeType,
