Skip to content

Commit

Permalink
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 <lifupan@gmail.com>
  • Loading branch information
lifupan committed Jan 25, 2019
1 parent 6f2c036 commit 3311755
Show file tree
Hide file tree
Showing 10 changed files with 2,021 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
Expand Up @@ -60,7 +60,7 @@

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

[[constraint]]
name = "github.com/safchain/ethtool"
Expand Down
53 changes: 47 additions & 6 deletions containerd-shim-v2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ 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"

_ "github.com/containerd/containerd/runtime/v2/runc/options"
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

Expand Down Expand Up @@ -66,8 +69,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 {
Expand All @@ -76,7 +77,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
}
Expand All @@ -100,3 +107,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 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
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand Down

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 3311755

Please sign in to comment.