Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mgr/cephadm/upgrade: normalize unqualified target image
If we get an unqualified target image, assume it's docker.io.  This
ensures that we're passing a fully-qualified target to docker|podman on
the various hosts and don't end up with something different based on the
per-host search path for unqualified image names.

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit 38f8452)
  • Loading branch information
liewegas committed Apr 10, 2021
1 parent 3d5531f commit 1f7c13a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/pybind/mgr/cephadm/module.py
Expand Up @@ -313,6 +313,12 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
default=False,
desc='Enable or disable the cephadm configuration analysis',
),
Option(
'default_registry',
type='str',
default='docker.io',
desc='Registry to which we should normalize unqualified image names',
),
]

def __init__(self, *args: Any, **kwargs: Any):
Expand Down Expand Up @@ -357,6 +363,7 @@ def __init__(self, *args: Any, **kwargs: Any):
self.registry_username: Optional[str] = None
self.registry_password: Optional[str] = None
self.use_repo_digest = True
self.default_registry = ''

self._cons: Dict[str, Tuple[remoto.backends.BaseConnection,
remoto.backends.LegacyModuleExecute]] = {}
Expand Down
16 changes: 8 additions & 8 deletions src/pybind/mgr/cephadm/tests/test_upgrade.py
Expand Up @@ -14,16 +14,16 @@
def test_upgrade_start(cephadm_module: CephadmOrchestrator):
with with_host(cephadm_module, 'test'):
assert wait(cephadm_module, cephadm_module.upgrade_start(
'image_id', None)) == 'Initiating upgrade to image_id'
'image_id', None)) == 'Initiating upgrade to docker.io/image_id'

assert wait(cephadm_module, cephadm_module.upgrade_status()).target_image == 'image_id'
assert wait(cephadm_module, cephadm_module.upgrade_status()).target_image == 'docker.io/image_id'

assert wait(cephadm_module, cephadm_module.upgrade_pause()) == 'Paused upgrade to image_id'
assert wait(cephadm_module, cephadm_module.upgrade_pause()) == 'Paused upgrade to docker.io/image_id'

assert wait(cephadm_module, cephadm_module.upgrade_resume()
) == 'Resumed upgrade to image_id'
) == 'Resumed upgrade to docker.io/image_id'

assert wait(cephadm_module, cephadm_module.upgrade_stop()) == 'Stopped upgrade to image_id'
assert wait(cephadm_module, cephadm_module.upgrade_stop()) == 'Stopped upgrade to docker.io/image_id'


@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
Expand All @@ -50,10 +50,10 @@ def test_upgrade_run(use_repo_digest, cephadm_module: CephadmOrchestrator):
}):
version_mock.return_value = 'ceph version 18.2.1 (somehash)'
assert wait(cephadm_module, cephadm_module.upgrade_start(
'to_image', None)) == 'Initiating upgrade to to_image'
'to_image', None)) == 'Initiating upgrade to docker.io/to_image'

assert wait(cephadm_module, cephadm_module.upgrade_status()
).target_image == 'to_image'
).target_image == 'docker.io/to_image'

def _versions_mock(cmd):
return json.dumps({
Expand Down Expand Up @@ -106,7 +106,7 @@ def _versions_mock(cmd):
if use_repo_digest:
assert image == 'to_image@repo_digest'
else:
assert image == 'to_image'
assert image == 'docker.io/to_image'


def test_upgrade_state_null(cephadm_module: CephadmOrchestrator):
Expand Down
16 changes: 15 additions & 1 deletion src/pybind/mgr/cephadm/upgrade.py
Expand Up @@ -17,6 +17,20 @@
logger = logging.getLogger(__name__)


def normalize_image_digest(digest: str, default_registry: str) -> str:
# normal case:
# ceph/ceph -> docker.io/ceph/ceph
# edge cases that shouldn't ever come up:
# ubuntu -> docker.io/ubuntu (ubuntu alias for library/ubuntu)
# no change:
# quay.ceph.io/ceph/ceph -> ceph
# docker.io/ubuntu -> no change
bits = digest.split('/')
if '.' not in bits[0] or len(bits) < 3:
digest = 'docker.io/' + digest
return digest


class UpgradeState:
def __init__(self,
target_name: str,
Expand Down Expand Up @@ -171,7 +185,7 @@ def upgrade_start(self, image: str, version: str) -> str:
raise OrchestratorError(version_error)
target_name = self.mgr.container_image_base + ':v' + version
elif image:
target_name = image
target_name = normalize_image_digest(image, self.mgr.default_registry)
else:
raise OrchestratorError('must specify either image or version')
if self.upgrade_state:
Expand Down

0 comments on commit 1f7c13a

Please sign in to comment.