Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shimv2: use the runtime config file passed from containerd/cri
Browse files Browse the repository at this point in the history
containerd/cri's different runtime handlers can pass different
config files to shimv2 by a generic runtime options, by this kata
can launch the pods using different VMM for different runtime handlers.

Fixes:kata-containers#1082

Signed-off-by: Fupan Li <[email protected]>
lifupan committed Jan 25, 2019
1 parent 6f2c036 commit 7396a71
Showing 11 changed files with 2,543 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@

[[constraint]]
name = "github.com/containerd/cri-containerd"
revision = "3d382e2f5dabe3bae62ceb9ded56bdee847008ee"
revision = "4dd6735020f5596dd41738f8c4f5cb07fa804c5e"

[[constraint]]
name = "github.com/safchain/ethtool"
54 changes: 48 additions & 6 deletions containerd-shim-v2/create.go
Original file line number Diff line number Diff line change
@@ -10,18 +10,22 @@ package containerdshim
import (
"context"
"fmt"

"github.com/containerd/typeurl"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"os"

taskAPI "github.com/containerd/containerd/runtime/v2/task"

"github.com/kata-containers/runtime/pkg/katautils"
"github.com/opencontainers/runtime-spec/specs-go"

// only register the proto type
_ "github.com/containerd/containerd/runtime/linux/runctypes"
crioption "github.com/containerd/cri-containerd/pkg/api/runtimeoptions/v1"
)

func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns string,
runtimeConfig *oci.RuntimeConfig) (*container, error) {
func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns string) (*container, error) {

detach := !r.Terminal

@@ -66,8 +70,6 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns
}
}

katautils.HandleFactory(ctx, vci, runtimeConfig)

disableOutput := noNeedForOutput(detach, ociSpec.Process.Terminal)

switch containerType {
@@ -76,7 +78,13 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns
return nil, fmt.Errorf("cannot create another sandbox in sandbox: %s", s.sandbox.ID())
}

sandbox, _, err := katautils.CreateSandbox(ctx, vci, ociSpec, *runtimeConfig, r.ID, bundlePath, "", disableOutput, false, true)
_, err := loadRuntimeConfig(s, r)
if err != nil {
return nil, err
}

katautils.HandleFactory(ctx, vci, s.config)
sandbox, _, err := katautils.CreateSandbox(ctx, vci, ociSpec, *s.config, r.ID, bundlePath, "", disableOutput, false, true)
if err != nil {
return nil, err
}
@@ -100,3 +108,37 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest, netns

return container, nil
}

func loadRuntimeConfig(s *service, r *taskAPI.CreateTaskRequest) (*oci.RuntimeConfig, error) {
var configPath string

if r.Options != nil {
v, err := typeurl.UnmarshalAny(r.Options)
if err != nil {
return nil, err
}
option, ok := v.(*crioption.Options)
// cri default runtime handler will pass a linux runc options,
// and we'll ignore it.
if ok {
configPath = option.ConfigPath
}
}

// Try to get the config file from the env KATA_CONF_FILE
if configPath == "" {
configPath = os.Getenv("KATA_CONF_FILE")
}

_, runtimeConfig, err := katautils.LoadConfiguration(configPath, false, true)
if err != nil {
return nil, err
}

// For the unit test, the config will be predefined
if s.config == nil {
s.config = &runtimeConfig
}

return &runtimeConfig, nil
}
10 changes: 1 addition & 9 deletions containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
@@ -65,18 +65,10 @@ func New(ctx context.Context, id string, publisher events.Publisher) (cdshim.Shi
vci.SetLogger(ctx, logger)
katautils.SetLogger(ctx, logger, logger.Logger.Level)

// Try to get the config file from the env KATA_CONF_FILE
confPath := os.Getenv("KATA_CONF_FILE")
_, runtimeConfig, err := katautils.LoadConfiguration(confPath, false, true)
if err != nil {
return nil, err
}

s := &service{
id: id,
pid: uint32(os.Getpid()),
context: ctx,
config: &runtimeConfig,
containers: make(map[string]*container),
events: make(chan interface{}, chSize),
ec: make(chan exit, bufferSize),
@@ -327,7 +319,7 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
}
}

container, err := create(ctx, s, r, netns, s.config)
container, err := create(ctx, s, r, netns)
if err != nil {
return nil, err
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7396a71

Please sign in to comment.