-
Notifications
You must be signed in to change notification settings - Fork 348
Add RuntimeHandler support #891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,18 @@ type Runtime struct { | |
type ContainerdConfig struct { | ||
// Snapshotter is the snapshotter used by containerd. | ||
Snapshotter string `toml:"snapshotter" json:"snapshotter"` | ||
// DefaultRuntime is the runtime to use in containerd. | ||
// DefaultRuntime is the default runtime to use in containerd. | ||
// This runtime is used when no runtime handler (or the empty string) is provided. | ||
DefaultRuntime Runtime `toml:"default_runtime" json:"defaultRuntime"` | ||
// UntrustedWorkloadRuntime is a runtime to run untrusted workloads on it. | ||
// DEPRECATED: use Runtimes instead. If provided, this runtime is mapped to the runtime handler | ||
// named 'untrusted'. It is a configuration error to provide both the (now deprecated) | ||
// UntrustedWorkloadRuntime and a handler in the Runtimes handler map (below) for 'untrusted' | ||
// workloads at the same time. Please provide one or the other. | ||
UntrustedWorkloadRuntime Runtime `toml:"untrusted_workload_runtime" json:"untrustedWorkloadRuntime"` | ||
// Runtimes is a map from CRI RuntimeHandler strings, which specify types of runtime | ||
// configurations, to the matching configurations. | ||
Runtimes map[string]Runtime `toml:"runtimes" json:"runtimes"` | ||
// NoPivot disables pivot-root (linux only), required when running a container in a RamDisk with runc | ||
NoPivot bool `toml:"no_pivot" json:"noPivot"` | ||
} | ||
|
@@ -183,3 +191,8 @@ func DefaultConfig() PluginConfig { | |
}, | ||
} | ||
} | ||
|
||
const ( | ||
// RuntimeUntrusted is the implicit runtime defined for ContainerdConfig.UntrustedWorkloadRuntime | ||
RuntimeUntrusted = "untrusted" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we could move this string over to CRI maybe a TODO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't an "official" concept, even though most (all?) runtimes have implemented it. We've talked about something like that with RuntimeClass, but for now we decided to keep it open ended. I just used this string as a transitional thing while migrating to the runtime handler based configuration. Once the annotation is no longer used, the runtime can be called anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true.. yet it would be beneficial to have example patterns and reserved names that have more meaning than .. anything :-) |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,10 +533,18 @@ func TestGetSandboxRuntime(t *testing.T) { | |
Root: "", | ||
} | ||
|
||
fooRuntime := criconfig.Runtime{ | ||
Type: "io.containerd.runtime.v1.linux", | ||
Engine: "foo-bar", | ||
Root: "", | ||
} | ||
|
||
for desc, test := range map[string]struct { | ||
sandboxConfig *runtime.PodSandboxConfig | ||
runtimeHandler string | ||
defaultRuntime criconfig.Runtime | ||
untrustedWorkloadRuntime criconfig.Runtime | ||
runtimes map[string]criconfig.Runtime | ||
expectErr bool | ||
expectedRuntime criconfig.Runtime | ||
}{ | ||
|
@@ -595,6 +603,54 @@ func TestGetSandboxRuntime(t *testing.T) { | |
defaultRuntime: defaultRuntime, | ||
expectErr: true, | ||
}, | ||
"should use 'untrusted' runtime for untrusted workload": { | ||
sandboxConfig: &runtime.PodSandboxConfig{ | ||
Annotations: map[string]string{ | ||
annotations.UntrustedWorkload: "true", | ||
}, | ||
}, | ||
defaultRuntime: defaultRuntime, | ||
runtimes: map[string]criconfig.Runtime{criconfig.RuntimeUntrusted: untrustedWorkloadRuntime}, | ||
expectedRuntime: untrustedWorkloadRuntime, | ||
}, | ||
"should use 'untrusted' runtime for untrusted workload & handler": { | ||
sandboxConfig: &runtime.PodSandboxConfig{ | ||
Annotations: map[string]string{ | ||
annotations.UntrustedWorkload: "true", | ||
}, | ||
}, | ||
runtimeHandler: "untrusted", | ||
defaultRuntime: defaultRuntime, | ||
runtimes: map[string]criconfig.Runtime{criconfig.RuntimeUntrusted: untrustedWorkloadRuntime}, | ||
expectedRuntime: untrustedWorkloadRuntime, | ||
}, | ||
"should return an error if untrusted annotation with conflicting handler": { | ||
sandboxConfig: &runtime.PodSandboxConfig{ | ||
Annotations: map[string]string{ | ||
annotations.UntrustedWorkload: "true", | ||
}, | ||
}, | ||
runtimeHandler: "foo", | ||
defaultRuntime: defaultRuntime, | ||
untrustedWorkloadRuntime: untrustedWorkloadRuntime, | ||
runtimes: map[string]criconfig.Runtime{"foo": fooRuntime}, | ||
expectErr: true, | ||
}, | ||
"should use correct runtime for a runtime handler": { | ||
sandboxConfig: &runtime.PodSandboxConfig{}, | ||
runtimeHandler: "foo", | ||
defaultRuntime: defaultRuntime, | ||
untrustedWorkloadRuntime: untrustedWorkloadRuntime, | ||
runtimes: map[string]criconfig.Runtime{"foo": fooRuntime}, | ||
expectedRuntime: fooRuntime, | ||
}, | ||
"should return error if runtime handler is required but not configured": { | ||
sandboxConfig: &runtime.PodSandboxConfig{}, | ||
runtimeHandler: "bar", | ||
defaultRuntime: defaultRuntime, | ||
runtimes: map[string]criconfig.Runtime{"foo": fooRuntime}, | ||
expectErr: true, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing test case: should return error if both annotation and runtime handler are specified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} { | ||
t.Run(desc, func(t *testing.T) { | ||
cri := newTestCRIService() | ||
|
@@ -603,7 +659,8 @@ func TestGetSandboxRuntime(t *testing.T) { | |
} | ||
cri.config.ContainerdConfig.DefaultRuntime = test.defaultRuntime | ||
cri.config.ContainerdConfig.UntrustedWorkloadRuntime = test.untrustedWorkloadRuntime | ||
r, err := cri.getSandboxRuntime(test.sandboxConfig) | ||
cri.config.ContainerdConfig.Runtimes = test.runtimes | ||
r, err := cri.getSandboxRuntime(test.sandboxConfig, test.runtimeHandler) | ||
assert.Equal(t, test.expectErr, err != nil) | ||
assert.Equal(t, test.expectedRuntime, r) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for these fields has to be cut and pasted to here: https://github.com/containerd/cri/blame/master/docs/config.md#L52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Add a clarification about the example to the runtimes entry.