*: stability fixes

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-06-01 11:20:22 +02:00
parent b5153e08c5
commit a37dd46654
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
3 changed files with 38 additions and 13 deletions

View file

@ -345,11 +345,11 @@ func (r *runtimeService) RemovePodSandbox(idOrName string) error {
} }
func (r *runtimeService) DeleteContainer(idOrName string) error { func (r *runtimeService) DeleteContainer(idOrName string) error {
container, err := r.storageImageServer.GetStore().Container(idOrName) if idOrName == "" {
if err != nil {
if err == storage.ErrContainerUnknown {
return ErrInvalidContainerID return ErrInvalidContainerID
} }
container, err := r.storageImageServer.GetStore().Container(idOrName)
if err != nil {
return err return err
} }
err = r.storageImageServer.GetStore().DeleteContainer(container.ID) err = r.storageImageServer.GetStore().DeleteContainer(container.ID)
@ -403,11 +403,11 @@ func (r *runtimeService) StartContainer(idOrName string) (string, error) {
} }
func (r *runtimeService) StopContainer(idOrName string) error { func (r *runtimeService) StopContainer(idOrName string) error {
container, err := r.storageImageServer.GetStore().Container(idOrName) if idOrName == "" {
if err != nil {
if err == storage.ErrContainerUnknown {
return ErrInvalidContainerID return ErrInvalidContainerID
} }
container, err := r.storageImageServer.GetStore().Container(idOrName)
if err != nil {
return err return err
} }
err = r.storageImageServer.GetStore().Unmount(container.ID) err = r.storageImageServer.GetStore().Unmount(container.ID)

View file

@ -5,6 +5,8 @@ import (
"syscall" "syscall"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/containers/storage"
"github.com/docker/docker/pkg/mount"
"github.com/kubernetes-incubator/cri-o/oci" "github.com/kubernetes-incubator/cri-o/oci"
"github.com/opencontainers/selinux/go-selinux/label" "github.com/opencontainers/selinux/go-selinux/label"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -56,10 +58,11 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
continue continue
} }
if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil { if err := s.storageRuntimeServer.StopContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown {
return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.id, err) // assume container already umounted
logrus.Warnf("failed to stop container %s in pod sandbox %s: %v", c.Name(), sb.id, err)
} }
if err := s.storageRuntimeServer.DeleteContainer(c.ID()); err != nil { if err := s.storageRuntimeServer.DeleteContainer(c.ID()); err != nil && err != storage.ErrContainerUnknown {
return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.id, err) return nil, fmt.Errorf("failed to delete container %s in pod sandbox %s: %v", c.Name(), sb.id, err)
} }
@ -76,10 +79,12 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
// unmount the shm for the pod // unmount the shm for the pod
if sb.shmPath != "/dev/shm" { if sb.shmPath != "/dev/shm" {
if mounted, err := mount.Mounted(sb.shmPath); err == nil && mounted {
if err := syscall.Unmount(sb.shmPath, syscall.MNT_DETACH); err != nil { if err := syscall.Unmount(sb.shmPath, syscall.MNT_DETACH); err != nil {
return nil, err return nil, err
} }
} }
}
if err := sb.netNsRemove(); err != nil { if err := sb.netNsRemove(); err != nil {
return nil, fmt.Errorf("failed to remove networking namespace for sandbox %s: %v", sb.id, err) return nil, fmt.Errorf("failed to remove networking namespace for sandbox %s: %v", sb.id, err)
@ -89,7 +94,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
// Remove the files related to the sandbox // Remove the files related to the sandbox
if err := s.storageRuntimeServer.StopContainer(sb.id); err != nil { if err := s.storageRuntimeServer.StopContainer(sb.id); err != nil {
return nil, fmt.Errorf("failed to delete sandbox container in pod sandbox %s: %v", sb.id, err) logrus.Warnf("failed to stop sandbox container in pod sandbox %s: %v", sb.id, err)
} }
if err := s.storageRuntimeServer.RemovePodSandbox(sb.id); err != nil { if err := s.storageRuntimeServer.RemovePodSandbox(sb.id); err != nil {
return nil, fmt.Errorf("failed to remove pod sandbox %s: %v", sb.id, err) return nil, fmt.Errorf("failed to remove pod sandbox %s: %v", sb.id, err)

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@ -66,6 +67,10 @@ func (s *Server) runContainer(container *oci.Container, cgroupParent string) err
return nil return nil
} }
var (
conflictRE = regexp.MustCompile(`already reserved for pod "([0-9a-z]+)"`)
)
// RunPodSandbox creates and runs a pod-level sandbox. // RunPodSandbox creates and runs a pod-level sandbox.
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) { func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) {
s.updateLock.RLock() s.updateLock.RLock()
@ -84,8 +89,23 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
id, name, err := s.generatePodIDandName(kubeName, namespace, attempt) id, name, err := s.generatePodIDandName(kubeName, namespace, attempt)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "already reserved for pod") {
matches := conflictRE.FindStringSubmatch(err.Error())
if len(matches) != 2 {
return nil, err return nil, err
} }
dupID := matches[1]
if _, err := s.RemovePodSandbox(ctx, &pb.RemovePodSandboxRequest{PodSandboxId: dupID}); err != nil {
return nil, err
}
id, name, err = s.generatePodIDandName(kubeName, namespace, attempt)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
_, containerName, err := s.generateContainerIDandName(name, "infra", attempt) _, containerName, err := s.generateContainerIDandName(name, "infra", attempt)
if err != nil { if err != nil {
return nil, err return nil, err