1
0
Fork 0

generate: container: Add or improve log messages

Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
Enno Tensing 2025-08-12 18:33:44 +02:00
parent 589a9125f4
commit a8d0148f72
Signed by: tenno
GPG key ID: 95265603BD36E66C

View file

@ -186,6 +186,7 @@ class Memory:
reservation = maybe_or(val, "reservation", "")
swap = maybe_or(val, "swap", "")
if limit == "":
logger.log_warning("No limit set, memory config is not needed")
return cls("", "", "")
return cls(limit, reservation, swap)
@ -252,7 +253,7 @@ class Volume:
if val is None:
return []
if not isinstance(val, dict):
logger.log_warning("Volume key is present, but malformed.")
logger.log_warning("Volume key is malformed.")
return []
return [
Volume.from_json_entry(key, value) for key, value in val.items()
@ -319,7 +320,7 @@ class Secret:
if val is None:
return []
if not isinstance(val, dict):
logger.log_warning("Secret key is present, but malformed!")
logger.log_warning("Secret key is malformed!")
return []
secrets = []
for key in val:
@ -332,6 +333,9 @@ class Secret:
if isinstance(target, str):
target = [target]
if not isinstance(target, list):
logger.log_warning(
f"Secret {name} has no target and will be ignored"
)
target = []
options = maybe_or(val[key], "options", "")
if options is None:
@ -393,7 +397,7 @@ class Environment:
if val is None:
return cls([], "")
if not isinstance(val, dict):
logger.log_warning("Environment key is present, but malformed!")
logger.log_warning("Environment key is malformed!")
return cls([], "")
return cls([f"{key}='{value}'" for key, value in val.items()], "")
@ -440,7 +444,7 @@ class Ports:
if val is None:
return cls([], [])
if not isinstance(val, dict):
logger.log_warning("Ports key is present, but malformed!")
logger.log_warning("Ports key is malformed!")
return cls([], [])
tcp_ports = maybe(val, "tcp")
udp_ports = maybe(val, "udp")
@ -499,13 +503,13 @@ class Network:
return cls("", [])
mode = maybe(val, "mode")
options = maybe(val, "options")
if mode is None:
if mode is None or not isinstance(mode, str):
err = "Network configuration is missing or has malformed elements!"
logger.log_error(err)
return cls("", [])
if options is None or not isinstance(options, list):
return cls(str(mode), [])
return cls(str(mode), options)
return cls(mode, [])
return cls(mode, options)
def command(self) -> str:
"""Option for podman container create."""
@ -537,7 +541,7 @@ class Image:
image = maybe_or(val, "image", "")
tag = maybe_or(val, "tag", "")
cmd = maybe_or(val, "command", "")
return cls(str(registry), str(image), str(tag), cmd)
return cls(registry, image, tag, cmd)
def command(self) -> str:
"""Option for podman container create."""
@ -589,9 +593,9 @@ class Dns:
search = maybe_or(val, "search", "")
servers = maybe(val, "servers")
if not isinstance(servers, list):
logger.log_error("Servers key is not an array!")
return cls([], "")
return cls(servers, str(search))
logger.log_warning("Servers key is not an array!")
return cls([], search)
return cls(servers, search)
def command(self) -> str:
"""Option for podman container create."""
@ -721,6 +725,9 @@ class Container:
if image is None:
logger.log_error("No image set, aborting!")
return
if image.name == "" or image.registry == "" or image.tag == "":
logger.log_error("Image config is missing required keys!")
return
ct_opts = ContainerOptions.from_json(json, logger)
if not ct_opts.is_valid:
return