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: complete the details of StartPodSandbox #2242

Merged
merged 1 commit into from
Sep 18, 2018

Conversation

starnop
Copy link
Contributor

@starnop starnop commented Sep 14, 2018

Signed-off-by: Starnop [email protected]

Ⅰ. Describe what this PR did

Provide an interface to start a sandbox pod which was stopped by accident and setup the network with network plugin.

Note: Only if the CNI-plugin supports returning the same IP with the same parameters of containdID ,pod name,pod namespace, we will make sure it reacquire the original network configuration of sandbox, like IP address.

Ⅱ. Does this pull request fix one issue?

None.

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

None.

Ⅳ. Describe how to verify it

use cri-tools

# cat pod-config.json 
{
    "metadata": {
        "name": "nginx-sandbox",
        "namespace": "default",
        "attempt": 1,
        "uid": "hdishd83djaidwnduwk28bcsb"
    },
    "linux": {
    }
}

# cat container-config.json 
{
  "metadata": {
      "name": "busybox"
  },
  "image":{
      "image": "busybox"
  },
  "command": [
      "top"
  ],
  "linux": {
  }
}

# crictl runp pod-config.json 
DEBU[0000] RunPodSandboxRequest: &RunPodSandboxRequest{Config:&PodSandboxConfig{Metadata:&PodSandboxMetadata{Name:nginx-sandbox,Uid:hdishd83djaidwnduwk28bcsb,Namespace:default,Attempt:1,},Hostname:,LogDirectory:,DnsConfig:nil,PortMappings:[],Labels:map[string]string{},Annotations:map[string]string{},Linux:&LinuxPodSandboxConfig{CgroupParent:,SecurityContext:nil,Sysctls:map[string]string{},},},} 
DEBU[0000] RunPodSandboxResponse: &RunPodSandboxResponse{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,} 
7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6

# crictl create 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6 container-config.json pod-config.json 
DEBU[0000] CreateContainerRequest: &CreateContainerRequest{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,Config:&ContainerConfig{Metadata:&ContainerMetadata{Name:busybox,Attempt:0,},Image:&ImageSpec{Image:busybox,},Command:[top],Args:[],WorkingDir:,Envs:[],Mounts:[],Devices:[],Labels:map[string]string{},Annotations:map[string]string{},LogPath:,Stdin:false,StdinOnce:false,Tty:false,Linux:&LinuxContainerConfig{Resources:nil,SecurityContext:nil,},Windows:nil,NetPriority:0,QuotaId:,},SandboxConfig:&PodSandboxConfig{Metadata:&PodSandboxMetadata{Name:nginx-sandbox,Uid:hdishd83djaidwnduwk28bcsb,Namespace:default,Attempt:1,},Hostname:,LogDirectory:,DnsConfig:nil,PortMappings:[],Labels:map[string]string{},Annotations:map[string]string{},Linux:&LinuxPodSandboxConfig{CgroupParent:,SecurityContext:nil,Sysctls:map[string]string{},},},} 
DEBU[0000] CreateContainerResponse: &CreateContainerResponse{ContainerId:a0bf0780844bb939c14cf43c2f34e42c99eb021fd35645dd1a1aeb6bbbce535f,} 
a0bf0780844bb939c14cf43c2f34e42c99eb021fd35645dd1a1aeb6bbbce535f

# crictl inspectp 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6
DEBU[0000] PodSandboxStatusRequest: &PodSandboxStatusRequest{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,Verbose:true,} 
DEBU[0000] PodSandboxStatusResponse: &PodSandboxStatusResponse{Status:&PodSandboxStatus{Id:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,Metadata:&PodSandboxMetadata{Name:nginx-sandbox,Uid:hdishd83djaidwnduwk28bcsb,Namespace:default,Attempt:1,},State:SANDBOX_READY,CreatedAt:1536916075102934587,Network:&PodSandboxNetworkStatus{Ip:10.244.1.108,},Linux:&LinuxPodSandboxStatus{Namespaces:&Namespace{Options:&NamespaceOption{Network:POD,Pid:POD,Ipc:POD,},},},Labels:map[string]string{},Annotations:map[string]string{},},Info:map[string]string{},} 
{
  "status": {
    "id": "7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6",
    "metadata": {
      "attempt": 1,
      "name": "nginx-sandbox",
      "namespace": "default",
      "uid": "hdishd83djaidwnduwk28bcsb"
    },
    "state": "SANDBOX_READY",
    "createdAt": "2018-09-14T09:07:55.102934587Z",
    "network": {
      "ip": "10.244.1.108"
    },
    "linux": {
      "namespaces": {
        "options": {
          "ipc": "POD",
          "network": "POD",
          "pid": "POD"
        }
      }
    },
    "labels": {},
    "annotations": {}
  }
}

# crictl stopp 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6
DEBU[0000] StopPodSandboxRequest: &StopPodSandboxRequest{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,} 
DEBU[0000] StopPodSandboxResponse: &StopPodSandboxResponse{} 
Stopped sandbox 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6

# crictl startp 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6
DEBU[0000] StartPodSandboxRequest: &StartPodSandboxRequest{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,} 
DEBU[0000] StartPodSandboxResponse: &StartPodSandboxResponse{} 
7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6

# crictl inspectp 7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6
DEBU[0000] PodSandboxStatusRequest: &PodSandboxStatusRequest{PodSandboxId:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,Verbose:true,} 
DEBU[0000] PodSandboxStatusResponse: &PodSandboxStatusResponse{Status:&PodSandboxStatus{Id:7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6,Metadata:&PodSandboxMetadata{Name:nginx-sandbox,Uid:hdishd83djaidwnduwk28bcsb,Namespace:default,Attempt:1,},State:SANDBOX_READY,CreatedAt:1536916075102934587,Network:&PodSandboxNetworkStatus{Ip:10.244.1.109,},Linux:&LinuxPodSandboxStatus{Namespaces:&Namespace{Options:&NamespaceOption{Network:POD,Pid:POD,Ipc:POD,},},},Labels:map[string]string{},Annotations:map[string]string{},},Info:map[string]string{},} 
{
  "status": {
    "id": "7fa3bf8c5cb8e97f1b09369bf182afb6b6f1ebdf74d072a95960942a3f2b9fb6",
    "metadata": {
      "attempt": 1,
      "name": "nginx-sandbox",
      "namespace": "default",
      "uid": "hdishd83djaidwnduwk28bcsb"
    },
    "state": "SANDBOX_READY",
    "createdAt": "2018-09-14T09:07:55.102934587Z",
    "network": {
      "ip": "10.244.1.108"
    },
    "linux": {
      "namespaces": {
        "options": {
          "ipc": "POD",
          "network": "POD",
          "pid": "POD"
        }
      }
    },
    "labels": {},
    "annotations": {}
  }
}

Ⅴ. Special notes for reviews

Related Pull Request: #2237

@starnop starnop force-pushed the cri-start-sandbox branch 2 times, most recently from df6301d to c763955 Compare September 14, 2018 10:07
var netnsPath string
hostNet := networkNamespaceMode == runtime.NamespaceMode_NODE
// If it is in host network, no need to configure the network of sandbox.
if !hostNet {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about

if hostNet {
    return netnsPath, nil
}

Use return fast to reduce ident and make code more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, and has been updated. ^_^

@starnop
Copy link
Contributor Author

starnop commented Sep 17, 2018

@rudyfly @YaoZengzeng PTAL. Thanks. ^_^

sandboxMeta := res.(*SandboxMeta)

// Setup networking for the sandbox.
netnsPath, setupNeterr := c.setupPodNetwork(ctx, podSandboxID, sandboxMeta.Config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork(), sandboxMeta.Config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/setupNeterr/setupNetErr

Copy link
Contributor Author

@starnop starnop Sep 18, 2018

Choose a reason for hiding this comment

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

Has been updated.

if setupNetErr != nil {
return nil, setupNetErr
}
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If setupNetErr is not nil, the defer function will never being invoked.


podSandboxID := r.GetPodSandboxId()

// start Podsandbox.
Copy link
Contributor

Choose a reason for hiding this comment

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

Podsandbox -> PodSandbox

}
sandboxMeta := res.(*SandboxMeta)

// Setup networking for the sandbox.
Copy link
Contributor

Choose a reason for hiding this comment

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

Setup -> setup

@starnop starnop force-pushed the cri-start-sandbox branch 8 times, most recently from 72d3738 to 95b82d5 Compare September 18, 2018 06:20
@pouchrobot pouchrobot added size/XL and removed size/L labels Sep 18, 2018
@starnop starnop force-pushed the cri-start-sandbox branch 2 times, most recently from 3cd2a30 to 9d1fb49 Compare September 18, 2018 06:35
@pouchrobot pouchrobot added size/L and removed size/XL labels Sep 18, 2018
@YaoZengzeng
Copy link
Contributor

LGTM

@rudyfly
Copy link
Collaborator

rudyfly commented Sep 18, 2018

LGTM, and waiting for the ci passed.

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Sep 18, 2018
@pouchrobot pouchrobot added conflict/needs-rebase and removed LGTM one maintainer or community participant agrees to merge the pull reuqest. labels Sep 18, 2018
@pouchrobot pouchrobot added size/XL and removed size/L labels Sep 18, 2018
@allencloud allencloud merged commit 2208220 into AliyunContainerService:master Sep 18, 2018
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.

5 participants