Skip to content

Commit 619c0d5

Browse files
author
Alan Christie
committed
fix: Better handling of poor file definitions
1 parent f905d90 commit 619c0d5

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

operator/handlers.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,27 @@ def create(name, namespace, spec, **_):
302302
# If so they have a 'name', 'content' and 'origin'.
303303
# The name is expected to be a qualified path like '/usr/local/blob.txt'.
304304
# We create a ConfigMap for each.
305-
306305
image_files: List[Dict[str, str]] = material.get("file", [])
307306
file_number: int = 0
308307
for image_file in image_files:
309-
file_number += 1
308+
if "name" not in image_file:
309+
msg = "Got a file from the imDataManager element but name was not provided"
310+
logging.error(msg)
311+
raise kopf.PermanentError(msg)
312+
elif "content" not in image_file:
313+
msg = (
314+
"Got a file from the imDataManager element but content was not provided"
315+
)
316+
logging.error(msg)
317+
raise kopf.PermanentError(msg)
318+
elif "origin" not in image_file:
319+
msg = (
320+
"Got a file from the imDataManager element but origin was not provided"
321+
)
322+
logging.error(msg)
323+
raise kopf.PermanentError(msg)
310324
file_name: str = os.path.basename(image_file["name"])
325+
file_number += 1
311326
cm_name: str = f"{name}-file-{file_number}"
312327
configmap_file = {
313328
"apiVersion": "v1",

0 commit comments

Comments
 (0)