Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: make runtime choosing supported in CRI managers for Kubernetes #1593

Merged
merged 1 commit into from
Jul 5, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Jun 25, 2018

Signed-off-by: Starnop starnop@163.com

Ⅰ. Describe what this PR did

Ⅱ. Does this pull request fix one issue?

fixes part of #1580

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

  1. Prerequisites Installation, the runtime binaries you will use is necessary
  2. You should start pouchd with the configuration like
pouchd --enable-cri --cri-version v1alpha2 --add-runtime runv=runv >pouchd.log 2>&1  &
  1. After setting up your kubernetes cluster, you can create a deployment like this :
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pouch
  labels:
    pouch: pouch
spec:
  selector:
    matchLabels:
      pouch: pouch
  template:
    metadata:
      labels:
        pouch: pouch
      annotations:
        io.kubernetes.runtime: runv
    spec:
      containers:
      - name: pouch
        image: docker.io/library/nginx:latest
        ports:
        - containerPort: 80
  1. Use command pouch ps to observe the runtime of the container.

Ⅴ. Special notes for reviews

@starnop starnop force-pushed the cri-annotation branch 4 times, most recently from c84d56a to a0f3373 Compare June 25, 2018 08:56
@codecov-io
Copy link

codecov-io commented Jun 25, 2018

Codecov Report

Merging #1593 into master will decrease coverage by 1.15%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1593      +/-   ##
==========================================
- Coverage   41.97%   40.82%   -1.16%     
==========================================
  Files         270      270              
  Lines       17609    18106     +497     
==========================================
  Hits         7392     7392              
- Misses       9307     9806     +499     
+ Partials      910      908       -2
Impacted Files Coverage Δ
cri/v1alpha2/cri_types.go 0% <ø> (ø) ⬆️
cri/v1alpha1/cri_types.go 0% <ø> (ø) ⬆️
cri/v1alpha2/cri_utils.go 27.86% <0%> (-0.49%) ⬇️
cri/v1alpha1/cri.go 0% <0%> (ø) ⬆️
cri/v1alpha2/cri.go 0% <0%> (ø) ⬆️
cri/v1alpha1/cri_utils.go 28.73% <0%> (-0.53%) ⬇️
daemon/mgr/image.go 54.09% <0%> (-14.38%) ⬇️
daemon/logger/syslog/validate.go 40.7% <0%> (-11.93%) ⬇️
daemon/mgr/container.go 38.52% <0%> (-11.68%) ⬇️
daemon/mgr/container_exec.go 67.77% <0%> (-2.34%) ⬇️
... and 1 more

if err != nil {
return nil, err
id := ""
if id = config.ContainerID; id == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not code like this:

id := config.ContainerID
if id == "" {
...
}

It seems more concise. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -235,18 +236,29 @@ func applySandboxLinuxOptions(hc *apitypes.HostConfig, lc *runtime.LinuxPodSandb
}

// makeSandboxPouchConfig returns apitypes.ContainerCreateConfig based on runtime.PodSandboxConfig.
func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, image string) (*apitypes.ContainerCreateConfig, error) {
func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, sandboxID string, image string) (*apitypes.ContainerCreateConfig, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sandboxID, image string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,19 @@
package annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should put the annotations into cri package

@@ -161,19 +162,23 @@ func (c *CriManager) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
return nil, err
}

id, err := c.ContainerMgr.GenerateID()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of generating ContainerID in CRI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be used before sandbox has been created.

@@ -35,6 +35,9 @@ type ContainerConfig struct {
// Command to run specified an array of strings.
Cmd []string `json:"Cmd"`

// The ID of the container
ContainerID string `json:"ContainerID,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainerID is used to be as SandboxID? I think it's a little confusing in the API level. Could we use annotation to handle this part?
cc @YaoZengzeng @starnop

@@ -610,6 +616,19 @@ func applyContainerSecurityContext(lc *runtime.LinuxContainerConfig, podSandboxI

// Apply Linux-specific options if applicable.
func (c *CriManager) updateCreateConfig(createConfig *apitypes.ContainerCreateConfig, config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, podSandboxID string) error {
// Apply runtime options.
if annotations := config.GetAnnotations(); annotations != nil {
createConfig.HostConfig.Runtime = annotations[anno.KubernetesRuntime]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the annotations[anno.KubernetesRuntime] is emtpy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createConfig.HostConfig.Runtime will be "", and then PouchContainer will use the DefaultRuntime,which is runc.

// set container runtime
if config.HostConfig.Runtime == "" {
	config.HostConfig.Runtime = mgr.Config.DefaultRuntime
}

Signed-off-by: Starnop <starnop@163.com>
@fuweid
Copy link
Contributor

fuweid commented Jul 5, 2018

LGTM @YaoZengzeng please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants