Created
March 15, 2017 14:09
-
-
Save sameo/8641c21d7be3487b687be4153f4d0eba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/server/container_create.go b/server/container_create.go | |
| index 06c172d..86b8758 100644 | |
| --- a/server/container_create.go | |
| +++ b/server/container_create.go | |
| @@ -15,6 +15,7 @@ import ( | |
| "github.com/kubernetes-incubator/cri-o/server/seccomp" | |
| "github.com/opencontainers/runc/libcontainer/label" | |
| "github.com/opencontainers/runtime-tools/generate" | |
| + "github.com/opencontainers/image-spec/specs-go/v1" | |
| "golang.org/x/net/context" | |
| pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" | |
| ) | |
| @@ -56,6 +57,60 @@ func addOciBindMounts(sb *sandbox, containerConfig *pb.ContainerConfig, specgen | |
| return nil | |
| } | |
| +// buildOCIProcessArgs build an OCI compatible process arguments slice. | |
| +func buildOCIProcessArgs(containerKubeConfig *pb.ContainerConfig, imageOCIConfig *v1.Image) []string { | |
| + processArgs := []string{} | |
| + | |
| + kubeCommands := containerKubeConfig.Command | |
| + kubeArgs := containerKubeConfig.Args | |
| + | |
| + if imageOCIConfig == nil { | |
| + // We did not get an OCI Image configuration. | |
| + // We should only use the information we got from kubelet, | |
| + // and fall back to a sane default otherwise. | |
| + | |
| + if kubeCommands == nil && kubeArgs == nil { | |
| + processArgs = []string{podInfraCommand} | |
| + } | |
| + | |
| + if kubeCommands != nil { | |
| + processArgs = append(processArgs, kubeCommands...) | |
| + } | |
| + | |
| + if kubeArgs != nil { | |
| + processArgs = append(processArgs, kubeArgs...) | |
| + } | |
| + } else { | |
| + // We got an OCI Image configuration. | |
| + // We will only use it if the kubelet information | |
| + // is incomplete. | |
| + | |
| + if kubeCommands == nil { | |
| + if imageOCIConfig.Config.Entrypoint != nil { | |
| + processArgs = append(processArgs, imageOCIConfig.Config.Entrypoint...) | |
| + } | |
| + } else { | |
| + processArgs = append(processArgs, kubeCommands...) | |
| + } | |
| + | |
| + if kubeArgs == nil { | |
| + if imageOCIConfig.Config.Entrypoint != nil { | |
| + processArgs = append(processArgs, imageOCIConfig.Config.Entrypoint...) | |
| + } | |
| + } else { | |
| + processArgs = append(processArgs, kubeArgs...) | |
| + } | |
| + | |
| + if processArgs == nil { | |
| + processArgs = []string{podInfraCommand} | |
| + } | |
| + } | |
| + | |
| + logrus.Debugf("OCI process args %v", processArgs) | |
| + | |
| + return processArgs | |
| +} | |
| + | |
| // CreateContainer creates a new container in specified PodSandbox | |
| func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) { | |
| logrus.Debugf("CreateContainerRequest %+v", req) | |
| @@ -145,19 +200,6 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, | |
| // creates a spec Generator with the default spec. | |
| specgen := generate.New() | |
| - processArgs := []string{} | |
| - commands := containerConfig.Command | |
| - args := containerConfig.Args | |
| - if commands == nil && args == nil { | |
| - processArgs = nil | |
| - } | |
| - if commands != nil { | |
| - processArgs = append(processArgs, commands...) | |
| - } | |
| - if args != nil { | |
| - processArgs = append(processArgs, args...) | |
| - } | |
| - | |
| cwd := containerConfig.WorkingDir | |
| if cwd == "" { | |
| cwd = "/" | |
| @@ -367,18 +409,18 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, | |
| return nil, err | |
| } | |
| + if containerInfo.Config == nil { | |
| + logrus.Warnf("WWWWWW NULL Container Image Info") | |
| + } else { | |
| + logrus.Warnf("WWWWWW Container Image Info Config %v", containerInfo.Config.Config) | |
| + } | |
| + | |
| mountPoint, err := s.storage.StartContainer(containerID) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err) | |
| } | |
| - if processArgs == nil { | |
| - if containerInfo.Config != nil && len(containerInfo.Config.Config.Cmd) > 0 { | |
| - processArgs = containerInfo.Config.Config.Cmd | |
| - } else { | |
| - processArgs = []string{"/bin/sh"} | |
| - } | |
| - } | |
| + processArgs := buildOCIProcessArgs(containerConfig, containerInfo.Config) | |
| specgen.SetProcessArgs(processArgs) | |
| // by default, the root path is an empty string. set it now. | |
| diff --git a/server/container_status.go b/server/container_status.go | |
| index 4afd911..33b76a0 100644 | |
| --- a/server/container_status.go | |
| +++ b/server/container_status.go | |
| @@ -21,13 +21,23 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq | |
| } | |
| containerID := c.ID() | |
| + image := c.Image() | |
| resp := &pb.ContainerStatusResponse{ | |
| Status: &pb.ContainerStatus{ | |
| Id: containerID, | |
| Metadata: c.Metadata(), | |
| + Image: image, | |
| }, | |
| } | |
| + status, err := s.images.ImageStatus(s.imageContext, image.Image) | |
| + if err == nil { | |
| + resp.Status.ImageRef = status.ID | |
| + } else { | |
| + logrus.Errorf("Could not get Image status: %v", err) | |
| + resp.Status.ImageRef = "foobarfoobar" | |
| + } | |
| + | |
| cState := s.runtime.ContainerStatus(c) | |
| rStatus := pb.ContainerState_CONTAINER_UNKNOWN | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment