]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move logic to build pull command to container engines 54134/head
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 21 Oct 2023 16:05:43 +0000 (12:05 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 6 Nov 2023 16:03:43 +0000 (11:03 -0500)
Move the logic needed to build a pull command to a function in the
container_engines.py file. This continues the effort to improve the
locality of items with regards to specific options for container
engines. I had thought to move the whole pull function but the logging
and retry code made me change my mind. We can always move it later if it
makes sense.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/container_engines.py

index 650e080843ede8c0436c4e2dca9888e60ae48eef..478de27f0b5ef67e157752f94fb646461cb49c70 100755 (executable)
@@ -103,6 +103,7 @@ from cephadmlib.container_engines import (
     Podman,
     check_container_engine,
     find_container_engine,
+    pull_command,
     registry_login,
 )
 from cephadmlib.data_utils import (
@@ -3926,14 +3927,7 @@ def _pull_image(ctx, image, insecure=False):
         'Digest did not match, expected',
     ]
 
-    cmd = [ctx.container_engine.path, 'pull', image]
-    if isinstance(ctx.container_engine, Podman):
-        if insecure:
-            cmd.append('--tls-verify=false')
-
-        if os.path.exists('/etc/ceph/podman-auth.json'):
-            cmd.append('--authfile=/etc/ceph/podman-auth.json')
-    cmd_str = ' '.join(cmd)
+    cmd = pull_command(ctx, image, insecure=insecure)
 
     for sleep_secs in [1, 4, 25]:
         out, err, ret = call(ctx, cmd, verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
@@ -3943,6 +3937,7 @@ def _pull_image(ctx, image, insecure=False):
         if 'unauthorized' in err:
             raise UnauthorizedRegistryError()
 
+        cmd_str = ' '.join(cmd)
         if not any(pattern in err for pattern in ignorelist):
             raise Error('Failed command: %s' % cmd_str)
 
index 98019fa820b3a9cfac882f5dabab7e05150e9d67..64ce7ae821abf30504ec95863e3dec7cc6cdf541 100644 (file)
@@ -175,3 +175,17 @@ def registry_login(
             'Failed to login to custom registry @ %s as %s with given password'
             % (ctx.registry_url, ctx.registry_username)
         )
+
+
+def pull_command(
+    ctx: CephadmContext, image: str, insecure: bool = False
+) -> List[str]:
+    """Return a command that can be run to pull an image."""
+    cmd = [ctx.container_engine.path, 'pull', image]
+    if isinstance(ctx.container_engine, Podman):
+        if insecure:
+            cmd.append('--tls-verify=false')
+
+        if os.path.exists('/etc/ceph/podman-auth.json'):
+            cmd.append('--authfile=/etc/ceph/podman-auth.json')
+    return cmd