generate: container: Add or improve log messages
Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
parent
589a9125f4
commit
a8d0148f72
1 changed files with 18 additions and 11 deletions
|
@ -186,6 +186,7 @@ class Memory:
|
||||||
reservation = maybe_or(val, "reservation", "")
|
reservation = maybe_or(val, "reservation", "")
|
||||||
swap = maybe_or(val, "swap", "")
|
swap = maybe_or(val, "swap", "")
|
||||||
if limit == "":
|
if limit == "":
|
||||||
|
logger.log_warning("No limit set, memory config is not needed")
|
||||||
return cls("", "", "")
|
return cls("", "", "")
|
||||||
return cls(limit, reservation, swap)
|
return cls(limit, reservation, swap)
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ class Volume:
|
||||||
if val is None:
|
if val is None:
|
||||||
return []
|
return []
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
logger.log_warning("Volume key is present, but malformed.")
|
logger.log_warning("Volume key is malformed.")
|
||||||
return []
|
return []
|
||||||
return [
|
return [
|
||||||
Volume.from_json_entry(key, value) for key, value in val.items()
|
Volume.from_json_entry(key, value) for key, value in val.items()
|
||||||
|
@ -319,7 +320,7 @@ class Secret:
|
||||||
if val is None:
|
if val is None:
|
||||||
return []
|
return []
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
logger.log_warning("Secret key is present, but malformed!")
|
logger.log_warning("Secret key is malformed!")
|
||||||
return []
|
return []
|
||||||
secrets = []
|
secrets = []
|
||||||
for key in val:
|
for key in val:
|
||||||
|
@ -332,6 +333,9 @@ class Secret:
|
||||||
if isinstance(target, str):
|
if isinstance(target, str):
|
||||||
target = [target]
|
target = [target]
|
||||||
if not isinstance(target, list):
|
if not isinstance(target, list):
|
||||||
|
logger.log_warning(
|
||||||
|
f"Secret {name} has no target and will be ignored"
|
||||||
|
)
|
||||||
target = []
|
target = []
|
||||||
options = maybe_or(val[key], "options", "")
|
options = maybe_or(val[key], "options", "")
|
||||||
if options is None:
|
if options is None:
|
||||||
|
@ -393,7 +397,7 @@ class Environment:
|
||||||
if val is None:
|
if val is None:
|
||||||
return cls([], "")
|
return cls([], "")
|
||||||
if not isinstance(val, dict):
|
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([], "")
|
||||||
return cls([f"{key}='{value}'" for key, value in val.items()], "")
|
return cls([f"{key}='{value}'" for key, value in val.items()], "")
|
||||||
|
|
||||||
|
@ -440,7 +444,7 @@ class Ports:
|
||||||
if val is None:
|
if val is None:
|
||||||
return cls([], [])
|
return cls([], [])
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
logger.log_warning("Ports key is present, but malformed!")
|
logger.log_warning("Ports key is malformed!")
|
||||||
return cls([], [])
|
return cls([], [])
|
||||||
tcp_ports = maybe(val, "tcp")
|
tcp_ports = maybe(val, "tcp")
|
||||||
udp_ports = maybe(val, "udp")
|
udp_ports = maybe(val, "udp")
|
||||||
|
@ -499,13 +503,13 @@ class Network:
|
||||||
return cls("", [])
|
return cls("", [])
|
||||||
mode = maybe(val, "mode")
|
mode = maybe(val, "mode")
|
||||||
options = maybe(val, "options")
|
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!"
|
err = "Network configuration is missing or has malformed elements!"
|
||||||
logger.log_error(err)
|
logger.log_error(err)
|
||||||
return cls("", [])
|
return cls("", [])
|
||||||
if options is None or not isinstance(options, list):
|
if options is None or not isinstance(options, list):
|
||||||
return cls(str(mode), [])
|
return cls(mode, [])
|
||||||
return cls(str(mode), options)
|
return cls(mode, options)
|
||||||
|
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
|
@ -537,7 +541,7 @@ class Image:
|
||||||
image = maybe_or(val, "image", "")
|
image = maybe_or(val, "image", "")
|
||||||
tag = maybe_or(val, "tag", "")
|
tag = maybe_or(val, "tag", "")
|
||||||
cmd = maybe_or(val, "command", "")
|
cmd = maybe_or(val, "command", "")
|
||||||
return cls(str(registry), str(image), str(tag), cmd)
|
return cls(registry, image, tag, cmd)
|
||||||
|
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
|
@ -589,9 +593,9 @@ class Dns:
|
||||||
search = maybe_or(val, "search", "")
|
search = maybe_or(val, "search", "")
|
||||||
servers = maybe(val, "servers")
|
servers = maybe(val, "servers")
|
||||||
if not isinstance(servers, list):
|
if not isinstance(servers, list):
|
||||||
logger.log_error("Servers key is not an array!")
|
logger.log_warning("Servers key is not an array!")
|
||||||
return cls([], "")
|
return cls([], search)
|
||||||
return cls(servers, str(search))
|
return cls(servers, search)
|
||||||
|
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
|
@ -721,6 +725,9 @@ class Container:
|
||||||
if image is None:
|
if image is None:
|
||||||
logger.log_error("No image set, aborting!")
|
logger.log_error("No image set, aborting!")
|
||||||
return
|
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)
|
ct_opts = ContainerOptions.from_json(json, logger)
|
||||||
if not ct_opts.is_valid:
|
if not ct_opts.is_valid:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue