Skip to content

Commit

Permalink
better handling of no image tags
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneknapp committed Aug 7, 2024
1 parent fa7122f commit c3e5b43
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
35 changes: 17 additions & 18 deletions hubploy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class RemoteImage:
"""
def __init__(self,
name,
tag,
tag=None,
helm_substitution_path="jupyterhub.singleuser.image"
):
"""
Define an Image from the hubploy config
name: Fully qualified name of image
tag: Tag of image (latest or github hash)
tag: Tag of image (github hash)
helm_substitution_path: Dot separated path in a helm file that should
be populated with this image spec
"""
Expand All @@ -47,7 +47,11 @@ def __init__(self,
self.name = name
self.tag = tag
self.helm_substitution_path = helm_substitution_path
self.image_spec = f"{self.name}:{self.tag}"

if self.tag is None:
self.image_spec = f"{self.name}"
else:
self.image_spec = f"{self.name}:{self.tag}"

def get_config(deployment, debug=False, verbose=False):
"""
Expand Down Expand Up @@ -77,13 +81,12 @@ def get_config(deployment, debug=False, verbose=False):
if "image_name" in images_config:
if ":" in images_config["image_name"]:
image_name, tag = images_config["image_name"].split(":")
images = [{
"name": image_name,
"tag": tag
}]
else:
image_name = images_config["image_name"]
tag = "latest"
images = [{
"name": image_name,
"tag": tag
}]
images = [{"name": images_config["image_name"]}]

else:
# Multiple images are being deployed
Expand All @@ -95,16 +98,12 @@ def get_config(deployment, debug=False, verbose=False):
logger.info(
f"Tag for {image_name}: {tag}"
)
images.append({
"name": image_name,
"tag": tag,
})
else:
image_name = i["name"]
tag = "latest"
logger.info(
f"No tag specified for {image_name}. Using 'latest'"
)
images.append({
"name": image_name,
"tag": tag,
})
images.append({"name": i["name"]})

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

Expand Down
32 changes: 22 additions & 10 deletions hubploy/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,28 @@ def deploy(
)
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}"
)

if image.tag is not None:
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}"
)
else:
logger.info(
f"Using image {image.name} for " +
f"{image.helm_substitution_path}"
)
helm_config_overrides_string.append(
f"{image.helm_substitution_path}.name={image.name}"
)


count+=1

with ExitStack() as stack:
Expand Down

0 comments on commit c3e5b43

Please sign in to comment.