Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1173 from lifupan/criconfig
Browse files Browse the repository at this point in the history
shimv2: use the runtime config file passed from containerd/cri
  • Loading branch information
gnawux authored Jan 30, 2019
2 parents 4092eba + f1a12ce commit 7cb2f31
Show file tree
Hide file tree
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
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
54 changes: 48 additions & 6 deletions containerd-shim-v2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
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 7cb2f31

Please sign in to comment.