This repository was archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 347
Support runtime specific configurations. #943
Merged
Random-Liu
merged 1 commit into
containerd:master
from
Random-Liu:support-per-runtime-config
Oct 9, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,10 @@ import ( | |
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
| "github.com/containerd/containerd/containers" | ||
| "github.com/containerd/containerd/runtime/linux/runctypes" | ||
| runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" | ||
| "github.com/containerd/typeurl" | ||
| "github.com/docker/distribution/reference" | ||
| imagedigest "github.com/opencontainers/go-digest" | ||
|
|
@@ -123,6 +125,14 @@ const ( | |
| networkAttachCount = 2 | ||
| ) | ||
|
|
||
| // Runtime type strings for various runtimes. | ||
| const ( | ||
| // linuxRuntime is the legacy linux runtime for shim v1. | ||
| linuxRuntime = "io.containerd.runtime.v1.linux" | ||
| // runcRuntime is the runc runtime for shim v2. | ||
| runcRuntime = "io.containerd.runc.v1" | ||
| ) | ||
|
|
||
| // makeSandboxName generates sandbox name from sandbox metadata. The name | ||
| // generated is unique as long as sandbox metadata is unique. | ||
| func makeSandboxName(s *runtime.PodSandboxMetadata) string { | ||
|
|
@@ -390,26 +400,6 @@ func getPodCNILabels(id string, config *runtime.PodSandboxConfig) map[string]str | |
| } | ||
| } | ||
|
|
||
| // getRuntimeConfigFromContainerInfo gets runtime configuration from containerd | ||
| // container info. | ||
| func getRuntimeConfigFromContainerInfo(c containers.Container) (criconfig.Runtime, error) { | ||
| r := criconfig.Runtime{ | ||
| Type: c.Runtime.Name, | ||
| } | ||
| if c.Runtime.Options == nil { | ||
| // CRI plugin makes sure that runtime option is always set. | ||
| return criconfig.Runtime{}, errors.New("runtime options is nil") | ||
| } | ||
| data, err := typeurl.UnmarshalAny(c.Runtime.Options) | ||
| if err != nil { | ||
| return criconfig.Runtime{}, errors.Wrap(err, "failed to unmarshal runtime options") | ||
| } | ||
| runtimeOpts := data.(*runctypes.RuncOptions) | ||
| r.Engine = runtimeOpts.Runtime | ||
| r.Root = runtimeOpts.RuntimeRoot | ||
| return r, nil | ||
| } | ||
|
|
||
| // toRuntimeAuthConfig converts cri plugin auth config to runtime auth config. | ||
| func toRuntimeAuthConfig(a criconfig.AuthConfig) *runtime.AuthConfig { | ||
| return &runtime.AuthConfig{ | ||
|
|
@@ -464,3 +454,45 @@ func parseImageReferences(refs []string) ([]string, []string) { | |
| } | ||
| return tags, digests | ||
| } | ||
|
|
||
| // generateRuntimeOptions generates runtime options from cri plugin config. | ||
| func generateRuntimeOptions(r criconfig.Runtime, c criconfig.Config) (interface{}, error) { | ||
| if r.Options == nil { | ||
| if r.Type != linuxRuntime { | ||
| return nil, nil | ||
| } | ||
| // This is a legacy config, generate runctypes.RuncOptions. | ||
| return &runctypes.RuncOptions{ | ||
| Runtime: r.Engine, | ||
| RuntimeRoot: r.Root, | ||
| SystemdCgroup: c.SystemdCgroup, | ||
| }, nil | ||
| } | ||
| options := getRuntimeOptionsType(r.Type) | ||
| if err := toml.PrimitiveDecode(*r.Options, options); err != nil { | ||
| return nil, err | ||
| } | ||
| return options, nil | ||
|
Member
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. I suppose if we're not supporting those fancy new options we'd fail them here if set.
Member
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. ok... fail not needed, pass through is the new meta :-) |
||
| } | ||
|
|
||
| // getRuntimeOptionsType gets empty runtime options by the runtime type name. | ||
| func getRuntimeOptionsType(t string) interface{} { | ||
| switch t { | ||
| case runcRuntime: | ||
| return &runcoptions.Options{} | ||
| default: | ||
| return &runctypes.RuncOptions{} | ||
| } | ||
| } | ||
|
|
||
| // getRuntimeOptions get runtime options from container metadata. | ||
| func getRuntimeOptions(c containers.Container) (interface{}, error) { | ||
| if c.Runtime.Options == nil { | ||
| return nil, nil | ||
| } | ||
| opts, err := typeurl.UnmarshalAny(c.Runtime.Options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return opts, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
let's go ahead and document these here. or generate a runc_options.md file and link to 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.
also we're missing:
We should list them and if necessary say that they are not supported, yet, and link to an issue for tracking. or you could even have a section for fields not supported. If not supported we need to test for and flag as an error so the user does not try them out. This because the fields are actually there.
Uh oh!
There was an error while loading. Please reload this page.
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.
All of them are supported now actually. We just pass through whatever configurations from the config file. That is why I just linked to the code, because everything is supported there. I can add that "all fields" are supported.
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.
Granted these .md's could use some more content but probably should document the fields here vs say go read the code :-)
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.
Will document them then. :)
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.
criu supported ? FYI that's checkpoint and restore..
Uh oh!
There was an error while loading. Please reload this page.
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 option is supported, means that you can config it. We are just not using it - there is no code path that
checkpointorrestorewill be called.Uh oh!
There was an error while loading. Please reload this page.
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.
We now support whatever configurations supported by the runtime, we directly pass through the config, and don't do anything special in the cri plugin.
For example, if we have a KataOptions type, and contains all kinds of VM specific options, we can support it now with shim v2.
Uh oh!
There was an error while loading. Please reload this page.
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.
A little surprised but ok, new meta! :-)
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, our goal is to support multiple runtimes now. If not necessary, we may not want to add runtime specific logic, just pass through. :)