From e35204c5e0b424eb9e8ed3c02e9bf9be8c9c468c Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Thu, 1 Mar 2018 13:35:08 -0500 Subject: [PATCH] Fix create container failure due to wrong image reference When the image name is resolved with the registries from crio.conf only the resolved name with the first registry is passed to create_container eventhough there are more registries in the crio.conf file. Fix this to try the resolved image names with all the registries given in the conf file. Signed-off-by: umohnani8 --- pkg/storage/image.go | 2 ++ server/container_create.go | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pkg/storage/image.go b/pkg/storage/image.go index 9df7ffbc..c14c9204 100644 --- a/pkg/storage/image.go +++ b/pkg/storage/image.go @@ -616,6 +616,8 @@ func splitDockerDomain(name string) (domain, remainder string) { return } +// ResolveNames resolves an image name into a storage image ID or a fully-qualified image name (domain/repo/image:tag). +// Will only return an empty slice if err != nil. func (svc *imageService) ResolveNames(imageName string) ([]string, error) { // _Maybe_ it's a truncated image ID. Don't prepend a registry name, then. if len(imageName) >= minimumTruncatedIDLength && svc.store != nil { diff --git a/server/container_create.go b/server/container_create.go index e815a14f..ce335ec1 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -1038,14 +1038,24 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, } // Get imageName and imageRef that are later requested in container status - status, err := s.StorageImageServer().ImageStatus(s.ImageContext(), images[0]) - if err != nil { - return nil, err + var ( + imgResult *storage.ImageResult + imgResultErr error + ) + for _, img := range images { + imgResult, imgResultErr = s.StorageImageServer().ImageStatus(s.ImageContext(), img) + if imgResultErr == nil { + break + } } - imageName := status.Name - imageRef := status.ID - if len(status.RepoDigests) > 0 { - imageRef = status.RepoDigests[0] + if imgResultErr != nil { + return nil, imgResultErr + } + + imageName := imgResult.Name + imageRef := imgResult.ID + if len(imgResult.RepoDigests) > 0 { + imageRef = imgResult.RepoDigests[0] } specgen.AddAnnotation(annotations.Image, image) @@ -1163,7 +1173,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, attempt := metadata.Attempt containerInfo, err := s.StorageRuntimeServer().CreateContainer(s.ImageContext(), sb.Name(), sb.ID(), - image, status.ID, + image, imgResult.ID, containerName, containerID, metaname, attempt,