refactor(docker): share container-name candidate iterator
Both prepare-time probing and launch-time race-retry generated the same `<base>, <base>-2, ..., <base>-N` sequence with their own copies of the suffix arithmetic and the 99-cap. Extract the candidate stream into docker/util.container_name_candidates and have both call sites walk it; each keeps its own predicate (probe vs. retry). Also bumps the cap into a named constant (MAX_CONTAINER_SUFFIX) so the two error messages can't drift.
This commit is contained in:
@@ -7,11 +7,25 @@ from __future__ import annotations
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import Iterable
|
||||
from typing import Iterable, Iterator
|
||||
|
||||
from ...log import die, info
|
||||
|
||||
|
||||
# Cap on the suffix the container-name conflict logic will try before
|
||||
# giving up: base, base-2, ..., base-MAX_CONTAINER_SUFFIX.
|
||||
MAX_CONTAINER_SUFFIX = 100
|
||||
|
||||
|
||||
def container_name_candidates(base: str) -> Iterator[str]:
|
||||
"""Yield `base`, then `base-2`, `base-3`, ... up to
|
||||
`base-MAX_CONTAINER_SUFFIX`. Both the prepare-time probe and the
|
||||
launch-time race retry walk this sequence."""
|
||||
yield base
|
||||
for suffix in range(2, MAX_CONTAINER_SUFFIX + 1):
|
||||
yield f"{base}-{suffix}"
|
||||
|
||||
|
||||
def runsc_available() -> bool:
|
||||
"""Return True if the Docker daemon has the gVisor (`runsc`) runtime
|
||||
registered. Called once per prepare; the result lives on the plan."""
|
||||
|
||||
Reference in New Issue
Block a user