From 2066b68791d550f424f30971849056c9b9743f9a Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 23 Sep 2016 14:34:31 -0700 Subject: [PATCH 1/5] Fixup stop sandbox logic Signed-off-by: Mrunal Patel --- server/sandbox.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index e43b0b83..c1f0dba5 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -231,16 +231,16 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR // StopPodSandbox stops the sandbox. If there are any running containers in the // sandbox, they should be force terminated. func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (*pb.StopPodSandboxResponse, error) { - sbName := req.PodSandboxId - if *sbName == "" { + sbID := req.PodSandboxId + if *sbID == "" { return nil, fmt.Errorf("PodSandboxId should not be empty") } - sb := s.getSandbox(*sbName) + sb := s.getSandbox(*sbID) if sb == nil { - return nil, fmt.Errorf("specified sandbox not found: %s", *sbName) + return nil, fmt.Errorf("specified sandbox not found: %s", *sbID) } - podInfraContainer := *sbName + "-infra" + podInfraContainer := sb.name + "-infra" for _, c := range sb.containers.List() { if podInfraContainer == c.Name() { podNamespace := "" @@ -248,14 +248,14 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque if err != nil { return nil, err } - if err := s.netPlugin.TearDownPod(netnsPath, podNamespace, *sbName, podInfraContainer); err != nil { - return nil, fmt.Errorf("failed to destroy network for container %s in sandbox %s: %v", c.Name(), *sbName, err) + if err := s.netPlugin.TearDownPod(netnsPath, podNamespace, *sbID, podInfraContainer); err != nil { + return nil, fmt.Errorf("failed to destroy network for container %s in sandbox %s: %v", c.Name(), *sbID, err) } } cStatus := s.runtime.ContainerStatus(c) if cStatus.Status != "stopped" { if err := s.runtime.StopContainer(c); err != nil { - return nil, fmt.Errorf("failed to stop container %s in sandbox %s: %v", c.Name(), *sbName, err) + return nil, fmt.Errorf("failed to stop container %s in sandbox %s: %v", c.Name(), *sbID, err) } } } From 6eab35c6b552a9bc5879c0aaa64b49135e16fad8 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 23 Sep 2016 14:41:20 -0700 Subject: [PATCH 2/5] Fixup remove sandbox logic Signed-off-by: Mrunal Patel --- server/sandbox.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index c1f0dba5..6e7fe08a 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -266,21 +266,21 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque // RemovePodSandbox deletes the sandbox. If there are any running containers in the // sandbox, they should be force deleted. func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxRequest) (*pb.RemovePodSandboxResponse, error) { - sbName := req.PodSandboxId - if *sbName == "" { + sbID := req.PodSandboxId + if *sbID == "" { return nil, fmt.Errorf("PodSandboxId should not be empty") } - sb := s.getSandbox(*sbName) + sb := s.getSandbox(*sbID) if sb == nil { - return nil, fmt.Errorf("specified sandbox not found: %s", *sbName) + return nil, fmt.Errorf("specified sandbox not found: %s", *sbID) } - podInfraContainer := *sbName + "-infra" + podInfraContainer := sb.name + "-infra" // Delete all the containers in the sandbox for _, c := range sb.containers.List() { if err := s.runtime.DeleteContainer(c); err != nil { - return nil, fmt.Errorf("failed to delete container %s in sandbox %s: %v", c.Name(), *sbName, err) + return nil, fmt.Errorf("failed to delete container %s in sandbox %s: %v", c.Name(), *sbID, err) } if podInfraContainer == c.Name() { continue @@ -292,9 +292,9 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR } // Remove the files related to the sandbox - podSandboxDir := filepath.Join(s.sandboxDir, *sbName) + podSandboxDir := filepath.Join(s.sandboxDir, *sbID) if err := os.RemoveAll(podSandboxDir); err != nil { - return nil, fmt.Errorf("failed to remove sandbox %s directory: %v", *sbName, err) + return nil, fmt.Errorf("failed to remove sandbox %s directory: %v", *sbID, err) } return &pb.RemovePodSandboxResponse{}, nil From b839ff1093408c4dd345567af7eeb90df9b13e42 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 23 Sep 2016 14:47:47 -0700 Subject: [PATCH 3/5] Fixup pod sandbox status Signed-off-by: Mrunal Patel --- server/sandbox.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index 6e7fe08a..11b52d3c 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -302,16 +302,16 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR // PodSandboxStatus returns the Status of the PodSandbox. func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) { - sbName := req.PodSandboxId - if *sbName == "" { + sbID := req.PodSandboxId + if *sbID == "" { return nil, fmt.Errorf("PodSandboxId should not be empty") } - sb := s.getSandbox(*sbName) + sb := s.getSandbox(*sbID) if sb == nil { - return nil, fmt.Errorf("specified sandbox not found: %s", *sbName) + return nil, fmt.Errorf("specified sandbox not found: %s", *sbID) } - podInfraContainerName := *sbName + "-infra" + podInfraContainerName := sb.name + "-infra" podInfraContainer := sb.getContainer(podInfraContainerName) cState := s.runtime.ContainerStatus(podInfraContainer) @@ -322,7 +322,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR return nil, err } podNamespace := "" - ip, err := s.netPlugin.GetContainerNetworkStatus(netNsPath, podNamespace, *sbName, podInfraContainerName) + ip, err := s.netPlugin.GetContainerNetworkStatus(netNsPath, podNamespace, *sbID, podInfraContainerName) if err != nil { // ignore the error on network status ip = "" @@ -330,7 +330,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR return &pb.PodSandboxStatusResponse{ Status: &pb.PodSandboxStatus{ - Id: sbName, + Id: sbID, CreatedAt: int64Ptr(created), Linux: &pb.LinuxPodSandboxStatus{ Namespaces: &pb.Namespace{ From 99a7a5330967307e81208d8e95cd272255b0edcd Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 23 Sep 2016 14:51:59 -0700 Subject: [PATCH 4/5] Cleanup comments Signed-off-by: Mrunal Patel --- server/sandbox.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/sandbox.go b/server/sandbox.go index 11b52d3c..fb2ac3b2 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -55,7 +55,6 @@ func (s *Server) generatePodIDandName(name, namespace string) (string, string, e } // CreatePodSandbox creates a pod-level sandbox. -// The definition of PodSandbox is at https://k8s.io/kubernetes/pull/25899 func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxRequest) (*pb.CreatePodSandboxResponse, error) { // process req.Name name := req.GetConfig().GetMetadata().GetName() @@ -95,18 +94,19 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR g.SetRootReadonly(true) g.SetProcessArgs([]string{"/pause"}) - // process req.Hostname + // set hostname hostname := req.GetConfig().GetHostname() if hostname != "" { g.SetHostname(hostname) } - // process req.LogDirectory + // set log directory logDir := req.GetConfig().GetLogDirectory() if logDir == "" { logDir = fmt.Sprintf("/var/log/ocid/pods/%s", id) } + // set DNS options dnsServers := req.GetConfig().GetDnsOptions().GetServers() dnsSearches := req.GetConfig().GetDnsOptions().GetSearches() resolvPath := fmt.Sprintf("%s/resolv.conf", podSandboxDir) @@ -122,6 +122,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR g.AddBindMount(resolvPath, "/etc/resolv.conf", "ro") + // add labels labels := req.GetConfig().GetLabels() labelsJSON, err := json.Marshal(labels) if err != nil { @@ -145,6 +146,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR g.AddAnnotation(k, v) } + // setup cgroup settings cgroupParent := req.GetConfig().GetLinux().GetCgroupParent() if cgroupParent != "" { g.SetLinuxCgroupsPath(cgroupParent) @@ -201,7 +203,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR return nil, err } - // Setup the network + // setup the network podNamespace := "" netnsPath, err := container.NetNsPath() if err != nil { From 5475f6b32bfde052d3c544fb6dcfadba34f9e89c Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 23 Sep 2016 15:06:12 -0700 Subject: [PATCH 5/5] Fix lint error Signed-off-by: Mrunal Patel --- server/sandbox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/sandbox.go b/server/sandbox.go index fb2ac3b2..e762b5d5 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -182,7 +182,7 @@ func (s *Server) CreatePodSandbox(ctx context.Context, req *pb.CreatePodSandboxR if _, err = os.Stat(podInfraRootfs); err != nil { if os.IsNotExist(err) { // TODO: Replace by rootfs creation API when it is ready - if err := utils.CreateFakeRootfs(podInfraRootfs, "docker://kubernetes/pause"); err != nil { + if err = utils.CreateFakeRootfs(podInfraRootfs, "docker://kubernetes/pause"); err != nil { return nil, err } } else {