From a54bccedf6db2bd96546af86d9b4af7d2d76462a Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Thu, 29 Aug 2024 15:23:36 -0600 Subject: [PATCH] Don't error when image pull fails and image exists: HookOS recently got the capability to embed container images. With this capability, pulling an image is not desired. This is expecially true if the image name is not resolvable or there is no network connection to the registry. An image name 127.0.0.1/embedded/myimage, for example. Currently, tink worker will always try to pull an image and will fail if the image pull fails. To allow for embedded images to function properly, when an image pull fails we check if the image already exists in the local Docker cache. If it does we don't fail the method call. Signed-off-by: Jacob Weinstock --- cmd/tink-worker/worker/registry.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/tink-worker/worker/registry.go b/cmd/tink-worker/worker/registry.go index 144d3714f..9b4b06dbb 100644 --- a/cmd/tink-worker/worker/registry.go +++ b/cmd/tink-worker/worker/registry.go @@ -31,6 +31,7 @@ type ImagePullStatus struct { } // PullImage outputs to stdout the contents of the requested image (relative to the registry). +// If a pull fails but the image already exists then we will return a nil error. func (m *containerManager) PullImage(ctx context.Context, img string) error { l := m.getLogger(ctx) authConfig := registry.AuthConfig{ @@ -46,6 +47,9 @@ func (m *containerManager) PullImage(ctx context.Context, img string) error { out, err := m.cli.ImagePull(ctx, path.Join(m.registryDetails.Registry, img), image.PullOptions{RegistryAuth: authStr}) if err != nil { + if _, _, err := m.cli.ImageInspectWithRaw(ctx, path.Join(m.registryDetails.Registry, img)); err == nil { + return nil + } return errors.Wrap(err, "DOCKER PULL") } defer func() {