Skip to content

Commit

Permalink
Merge pull request cri-o#8754 from MarSik/runtime-inherit
Browse files Browse the repository at this point in the history
RuntimeHandler inheritance
  • Loading branch information
openshift-merge-bot[bot] authored Nov 15, 2024
2 parents 8ff657e + 76049fe commit 9dc63d1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/crio.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ Root directory used to store runtime data
**runtime_type**="oci"
Type of the runtime used for this runtime handler. "oci", "vm"

**inherit_default_runtime**=false
Override the runtime path, runtime config path, runtime root and runtime type from the default runtime on load.

**runtime_config_path**=""
Path to the runtime configuration file, should only be used with VM runtime types

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ type RuntimeHandler struct {
// Output of the "features" subcommand.
// This is populated dynamically and not read from config.
features runtimeHandlerFeatures

// Inheritance request
// Fill in the Runtime information (paths and type) from the default runtime
InheritDefaultRuntime bool `toml:"inherit_default_runtime,omitempty"`
}

// Multiple runtime Handlers in a map.
Expand Down
14 changes: 14 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,20 @@ var _ = t.Describe("Config", func() {
// Then
Expect(err).ToNot(HaveOccurred())
})

It("should succeed with empty runtime type and runtime_config_path when inheriting from default", func() {
// Given
sut.Runtimes["inherited"] = &config.RuntimeHandler{
RuntimeConfigPath: invalidPath, RuntimeType: "invalid", InheritDefaultRuntime: true,
}
err := sut.ReloadRuntimes(sut)
Expect(err).ToNot(HaveOccurred())

// When
err = sut.Validate(false)
// Then
Expect(err).ToNot(HaveOccurred())
})
})

t.Describe("RuntimeHandlerFeatures", func() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ func (c *Config) ReloadRuntimes(newConfig *Config) error {
return nil
}

// Update the default runtime paths in all runtimes that are asking for inheritance
for _, runtime := range c.Runtimes {
if runtime.InheritDefaultRuntime {
runtime.RuntimePath = c.Runtimes[c.DefaultRuntime].RuntimePath
runtime.RuntimeType = c.Runtimes[c.DefaultRuntime].RuntimeType
runtime.RuntimeConfigPath = c.Runtimes[c.DefaultRuntime].RuntimeConfigPath
runtime.RuntimeRoot = c.Runtimes[c.DefaultRuntime].RuntimeRoot
}
}

if err := c.ValidateRuntimes(); err != nil {
return fmt.Errorf("unabled to reload runtimes: %w", err)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/config/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,30 @@ var _ = t.Describe("Config", func() {
Expect(sut.Runtimes).To(HaveKeyWithValue("existing", newRuntime))
Expect(sut.Runtimes["existing"].PrivilegedWithoutHostDevices).To(BeTrue())
})

It("should inherit runtime config", func() {
// Given
newRuntime := &config.RuntimeHandler{
RuntimePath: invalidPath,
InheritDefaultRuntime: true,
}
defaultRuntime := &config.RuntimeHandler{
RuntimePath: existingRuntimePath,
}
newConfig := &config.Config{}
newConfig.DefaultRuntime = "default"
newConfig.Runtimes = make(config.Runtimes)
newConfig.Runtimes["default"] = defaultRuntime
newConfig.Runtimes["new"] = newRuntime

// When
err := sut.ReloadRuntimes(newConfig)

// Then
Expect(err).ToNot(HaveOccurred())
Expect(sut.Runtimes).To(HaveKeyWithValue("new", newRuntime))
Expect(sut.Runtimes["new"].RuntimePath).To(Equal(existingRuntimePath))
})
})

t.Describe("ReloadPinnedImages", func() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ const templateStringCrioRuntimeRuntimesRuntimeHandler = `# The "crio.runtime.run
# runtime_path = "/path/to/the/executable"
# runtime_type = "oci"
# runtime_root = "/path/to/the/root"
# inherit_default_runtime = false
# monitor_path = "/path/to/container/monitor"
# monitor_cgroup = "/cgroup/path"
# monitor_exec_cgroup = "/cgroup/path"
Expand All @@ -1250,6 +1251,9 @@ const templateStringCrioRuntimeRuntimesRuntimeHandler = `# The "crio.runtime.run
# state.
# - runtime_config_path (optional, string): the path for the runtime configuration
# file. This can only be used with when using the VM runtime_type.
# - inherit_default_runtime (optional, bool): when true the runtime_path,
# runtime_type, runtime_root and runtime_config_path will be replaced by
# the values from the default runtime on load time.
# - privileged_without_host_devices (optional, bool): an option for restricting
# host devices from being passed to privileged containers.
# - allowed_annotations (optional, array of strings): an option for specifying
Expand Down Expand Up @@ -1320,6 +1324,7 @@ const templateStringCrioRuntimeRuntimesRuntimeHandler = `# The "crio.runtime.run
{{ $.Comment }}runtime_path = "{{ $runtime_handler.RuntimePath }}"
{{ $.Comment }}runtime_type = "{{ $runtime_handler.RuntimeType }}"
{{ $.Comment }}runtime_root = "{{ $runtime_handler.RuntimeRoot }}"
{{ $.Comment }}inherit_default_runtime = {{ $runtime_handler.InheritDefaultRuntime }}
{{ $.Comment }}runtime_config_path = "{{ $runtime_handler.RuntimeConfigPath }}"
{{ $.Comment }}container_min_memory = "{{ $runtime_handler.ContainerMinMemory }}"
{{ $.Comment }}monitor_path = "{{ $runtime_handler.MonitorPath }}"
Expand Down

0 comments on commit 9dc63d1

Please sign in to comment.