Skip to content

Commit

Permalink
finish up image overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneknapp committed Jun 28, 2024
1 parent 758c6ed commit acf5209
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
8 changes: 3 additions & 5 deletions hubploy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def main():
help=textwrap.dedent("""\
Override one or more images and tags to deploy. Format is:\n
<path_to_image1/image_name>:<tag1> <path_to_image2/image_name>:<tag2> ...\n \n
IMPORTANT: The order of images passed in must match the order in which
they appear in hubploy.yaml and separated by spaces without quotes.
""")
Expand All @@ -104,14 +103,13 @@ def main():
elif args.debug:
logger.setLevel(logging.DEBUG)
logger.info(args)
logger.info(args.image_overrides)


# Attempt to load the config early, fail if it doesn't exist or is invalid
try:
config = hubploy.config.get_config(
args.deployment,
args.debug,
args.verbose
debug=False,
verbose=False
)
except hubploy.config.DeploymentNotFoundError as e:
print(e, file=sys.stderr)
Expand Down
5 changes: 3 additions & 2 deletions hubploy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self,
self.helm_substitution_path = helm_substitution_path
self.image_spec = f"{self.name}:{self.tag}"

def get_config(deployment, debug, verbose):
def get_config(deployment, debug=False, verbose=False):
"""
Returns hubploy.yaml configuration as a Python dictionary if it exists for
a given deployment, and also augments it with a set of RemoteImage objects
Expand All @@ -72,9 +72,9 @@ def get_config(deployment, debug, verbose):
config = yaml.load(f)

if "images" in config:
# A single image is being deployed
images_config = config["images"]

# A single image is being deployed
if "image_name" in images_config:
if ":" in images_config["image_name"]:
image_name, tag = images_config["image_name"].split(":")
Expand Down Expand Up @@ -106,6 +106,7 @@ def get_config(deployment, debug, verbose):
"name": image_name,
"tag": tag,
})

config["images"]["images"] = [RemoteImage(**i) for i in images]

# Backwards compatibility checker for images block
Expand Down
27 changes: 15 additions & 12 deletions hubploy/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,45 +204,48 @@ def deploy(

if config.get("images"):
if image_overrides is not None:
print(f"Image overrides found: {image_overrides}")
num_images = len(config["images"]["images"])
num_overrides = len(image_overrides)

if num_images != num_overrides:
raise ValueError(
f"Number of image overrides ({num_overrides}) must match " +
f"number of images in hubploy.yaml ({num_images})"
f"number of images found in " +
f"deployments/{deployment}/hubploy.yaml ({num_images})"
)
for override in image_overrides:
if ":" not in override:
raise ValueError(
f"Image override must be in the format " +
f"<path_to_image/image_name>:<tag>. Got {override}"
)

count = 0
for image in config["images"]["images"]:
logger.info(
f"Using image {image.name}:{image.tag} for " +
f"{image.helm_substitution_path}"
)
# We can support other charts that wrap z2jh by allowing various
# config paths where we set image tags and names.
# We default to one sublevel, but we can do multiple levels.
if image_overrides is not None:
override = image_overrides[count]
image_name, tag = override.split(":")
image.name = image_name
image.tag = tag
logger.info(
f"Overriding image {image.helm_substitution_path} to " +
f"{image.name}:{image.tag}"
override_image, override_tag = override.split(":")
print(
f"Overriding image {image.name}:{image.tag} to " +
f"{override_image}:{override_tag}"
)
image.name = override_image
image.tag = override_tag
logger.info(
f"Using image {image.name}:{image.tag} for " +
f"{image.helm_substitution_path}"
)
helm_config_overrides_string.append(
f"{image.helm_substitution_path}.tag={image.tag}"
)
helm_config_overrides_string.append(
f"{image.helm_substitution_path}.name={image.name}"
)
count+=1
print(helm_config_overrides_string)

with ExitStack() as stack:
decrypted_secret_files = [
Expand Down

0 comments on commit acf5209

Please sign in to comment.