From 7b60703634a291a4a01fbf6ef91f1cd84f6111ca Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 27 Oct 2016 19:31:20 -0400 Subject: [PATCH 1/2] Add logging for all container/sandbox responses Signed-off-by: Mrunal Patel --- server/container.go | 60 +++++++++++++++++++++++++++------------------ server/sandbox.go | 35 +++++++++++++++++--------- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/server/container.go b/server/container.go index 21cc9755..1cd2a742 100644 --- a/server/container.go +++ b/server/container.go @@ -58,7 +58,7 @@ func (s *Server) getContainerFromRequest(req containerRequest) (*oci.Container, // 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("CreateContainer %+v", req) + logrus.Debugf("CreateContainerRequest %+v", req) sbID := req.GetPodSandboxId() if sbID == "" { return nil, fmt.Errorf("PodSandboxId should not be empty") @@ -131,9 +131,12 @@ func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerReq return nil, err } - return &pb.CreateContainerResponse{ + resp := &pb.CreateContainerResponse{ ContainerId: &containerID, - }, nil + } + + logrus.Debugf("CreateContainerResponse: %+v", resp) + return resp, nil } func (s *Server) createSandboxContainer(containerID string, containerName string, sb *sandbox, SandboxConfig *pb.PodSandboxConfig, containerDir string, containerConfig *pb.ContainerConfig) (*oci.Container, error) { @@ -293,7 +296,7 @@ func (s *Server) createSandboxContainer(containerID string, containerName string // Join the namespace paths for the pod sandbox container. podInfraState := s.runtime.ContainerStatus(sb.infraContainer) - logrus.Infof("pod container state %v", podInfraState) + logrus.Debugf("pod container state %+v", podInfraState) for nsType, nsFile := range map[string]string{ "ipc": "ipc", @@ -346,7 +349,7 @@ func (s *Server) createSandboxContainer(containerID string, containerName string // StartContainer starts the container. func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) { - logrus.Debugf("StartContainer %+v", req) + logrus.Debugf("StartContainerRequest %+v", req) c, err := s.getContainerFromRequest(req) if err != nil { return nil, err @@ -356,12 +359,14 @@ func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerReque return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err) } - return &pb.StartContainerResponse{}, nil + resp := &pb.StartContainerResponse{} + logrus.Debugf("StartContainerResponse %+v", resp) + return resp, nil } // StopContainer stops a running container with a grace period (i.e., timeout). func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) { - logrus.Debugf("StopContainer %+v", req) + logrus.Debugf("StopContainerRequest %+v", req) c, err := s.getContainerFromRequest(req) if err != nil { return nil, err @@ -371,13 +376,15 @@ func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err) } - return &pb.StopContainerResponse{}, nil + resp := &pb.StopContainerResponse{} + logrus.Debugf("StopContainerResponse: %+v", resp) + return resp, nil } // RemoveContainer removes the container. If the container is running, the container // should be force removed. func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (*pb.RemoveContainerResponse, error) { - logrus.Debugf("RemoveContainer %+v", req) + logrus.Debugf("RemoveContainerRequest %+v", req) c, err := s.getContainerFromRequest(req) if err != nil { return nil, err @@ -410,7 +417,9 @@ func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerReq return nil, err } - return &pb.RemoveContainerResponse{}, nil + resp := &pb.RemoveContainerResponse{} + logrus.Debugf("RemoveContainerResponse: %+v", resp) + return resp, nil } // filterContainer returns whether passed container matches filtering criteria @@ -433,7 +442,7 @@ func filterContainer(c *pb.Container, filter *pb.ContainerFilter) bool { // ListContainers lists all containers by filters. func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersRequest) (*pb.ListContainersResponse, error) { - logrus.Debugf("ListContainers %+v", req) + logrus.Debugf("ListContainersRequest %+v", req) var ctrs []*pb.Container filter := req.Filter ctrList := s.state.containers.List() @@ -500,14 +509,16 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque } } - return &pb.ListContainersResponse{ + resp := &pb.ListContainersResponse{ Containers: ctrs, - }, nil + } + logrus.Debugf("ListContainersResponse: %+v", resp) + return resp, nil } // ContainerStatus returns status of the container. func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) { - logrus.Debugf("ContainerStatus %+v", req) + logrus.Debugf("ContainerStatusRequest %+v", req) c, err := s.getContainerFromRequest(req) if err != nil { return nil, err @@ -518,7 +529,7 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq } containerID := c.ID() - csr := &pb.ContainerStatusResponse{ + resp := &pb.ContainerStatusResponse{ Status: &pb.ContainerStatus{ Id: &containerID, }, @@ -531,27 +542,28 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq case oci.ContainerStateCreated: rStatus = pb.ContainerState_CREATED created := cState.Created.Unix() - csr.Status.CreatedAt = int64Ptr(created) + resp.Status.CreatedAt = int64Ptr(created) case oci.ContainerStateRunning: rStatus = pb.ContainerState_RUNNING created := cState.Created.Unix() - csr.Status.CreatedAt = int64Ptr(created) + resp.Status.CreatedAt = int64Ptr(created) started := cState.Started.Unix() - csr.Status.StartedAt = int64Ptr(started) + resp.Status.StartedAt = int64Ptr(started) case oci.ContainerStateStopped: rStatus = pb.ContainerState_EXITED created := cState.Created.Unix() - csr.Status.CreatedAt = int64Ptr(created) + resp.Status.CreatedAt = int64Ptr(created) started := cState.Started.Unix() - csr.Status.StartedAt = int64Ptr(started) + resp.Status.StartedAt = int64Ptr(started) finished := cState.Finished.Unix() - csr.Status.FinishedAt = int64Ptr(finished) - csr.Status.ExitCode = int32Ptr(cState.ExitCode) + resp.Status.FinishedAt = int64Ptr(finished) + resp.Status.ExitCode = int32Ptr(cState.ExitCode) } - csr.Status.State = &rStatus + resp.Status.State = &rStatus - return csr, nil + logrus.Debugf("ContainerStatusResponse: %+v", resp) + return resp, nil } // UpdateRuntimeConfig updates the configuration of a running container. diff --git a/server/sandbox.go b/server/sandbox.go index ab428911..0eafe97f 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -86,7 +86,7 @@ func (s *Server) getPodSandboxFromRequest(req podSandboxRequest) (*sandbox, erro // RunPodSandbox creates and runs a pod-level sandbox. func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (*pb.RunPodSandboxResponse, error) { - logrus.Debugf("RunPodSandbox %+v", req) + logrus.Debugf("RunPodSandboxRequest %+v", req) var processLabel, mountLabel string // process req.Name name := req.GetConfig().GetMetadata().GetName() @@ -323,13 +323,15 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest return nil, err } - return &pb.RunPodSandboxResponse{PodSandboxId: &id}, nil + resp := &pb.RunPodSandboxResponse{PodSandboxId: &id} + logrus.Debugf("RunPodSandboxResponse: %+v", resp) + return resp, nil } // 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) { - logrus.Debugf("StopPodSandbox %+v", req) + logrus.Debugf("StopPodSandboxRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req) if err != nil { return nil, err @@ -359,13 +361,15 @@ func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxReque } } - return &pb.StopPodSandboxResponse{}, nil + resp := &pb.StopPodSandboxResponse{} + logrus.Debugf("StopPodSandboxResponse: %+v", resp) + return resp, nil } // 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) { - logrus.Debugf("RemovePodSandbox %+v", req) + logrus.Debugf("RemovePodSandboxRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req) if err != nil { return nil, err @@ -421,12 +425,14 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR s.releasePodName(sb.name) s.removeSandbox(sb.id) - return &pb.RemovePodSandboxResponse{}, nil + resp := &pb.RemovePodSandboxResponse{} + logrus.Debugf("RemovePodSandboxResponse %+v", resp) + return resp, nil } // PodSandboxStatus returns the Status of the PodSandbox. func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) { - logrus.Debugf("PodSandboxStatus %+v", req) + logrus.Debugf("PodSandboxStatusRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req) if err != nil { return nil, err @@ -457,7 +463,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR } sandboxID := sb.id - return &pb.PodSandboxStatusResponse{ + resp := &pb.PodSandboxStatusResponse{ Status: &pb.PodSandboxStatus{ Id: &sandboxID, CreatedAt: int64Ptr(created), @@ -472,7 +478,10 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR Annotations: sb.annotations, Metadata: sb.metadata, }, - }, nil + } + + logrus.Infof("PodSandboxStatusResponse: %+v", resp) + return resp, nil } // filterSandbox returns whether passed container matches filtering criteria @@ -495,7 +504,7 @@ func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool { // ListPodSandbox returns a list of SandBoxes. func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxRequest) (*pb.ListPodSandboxResponse, error) { - logrus.Debugf("ListPodSandbox %+v", req) + logrus.Debugf("ListPodSandboxRequest %+v", req) var pods []*pb.PodSandbox var podList []*sandbox for _, sb := range s.state.sandboxes { @@ -547,9 +556,11 @@ func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxReque } } - return &pb.ListPodSandboxResponse{ + resp := &pb.ListPodSandboxResponse{ Items: pods, - }, nil + } + logrus.Debugf("ListPodSandboxResponse %+v", resp) + return resp, nil } func getSELinuxLabels(selinuxOptions *pb.SELinuxOption) (processLabel string, mountLabel string, err error) { From 80ef36ba2ead3ca57d3b9758a788c3a6dee063bf Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Mon, 31 Oct 2016 13:38:03 -0400 Subject: [PATCH 2/2] Fix install of unit file and configuration file Signed-off-by: Dan Walsh --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4775dbae..4712f8f1 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ PREFIX ?= ${DESTDIR}/usr BINDIR ?= ${PREFIX}/bin LIBEXECDIR ?= ${PREFIX}/libexec MANDIR ?= ${PREFIX}/share/man -ETCDIR ?= ${PREFIX}/etc +ETCDIR ?= ${DESTDIR}/etc GO_MD2MAN ?= $(shell which go-md2man) export GOPATH := ${CURDIR}/vendor BUILDTAGS := selinux @@ -102,7 +102,7 @@ install: install -D -m 644 ocid.conf $(ETCDIR)/ocid.conf install.systemd: - install -D -m 644 contrib/systemd/ocid.service $(PREFIX)/lib/systemd/system + install -D -m 644 contrib/systemd/ocid.service $(PREFIX)/lib/systemd/system/ocid.service uninstall: rm -f $(BINDIR)/{ocid,ocic}