Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/controllers/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def substitute_identifiers(
for identf in tmpl.get_identifiers():
identf_func = self.get_identifier_func(identf)
if not identf_func:
return False, f"Invalid placeholder {identf}"
continue
try:
mapping[identf] = identf_func(
dry_run=dry_run,
Expand Down
25 changes: 19 additions & 6 deletions tests/test_k8s_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys
import tempfile
import types
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

import pytest

Expand Down Expand Up @@ -131,15 +131,28 @@ def test_get_identifier_func(self, ctrl):

def test_substitute_identifiers_ok(self, ctrl):
status, data = ctrl.substitute_identifiers(
"id=${pod_hash}", pod_hash="abc", dry_run=True
"id=${pod_hash} $TEST2", pod_hash="abc", dry_run=True
)
assert status is True
assert data == "id=abc"
assert data == "id=abc $TEST2"

def test_substitute_identifiers_invalid_placeholder(self, ctrl):
status, data = ctrl.substitute_identifiers("x=${bogus}", dry_run=True)
def test_substitute_identifiers_exceptions(self, ctrl):
with patch("string.Template") as mock_template:
mock_template.side_effect = ValueError("err")
status, data = ctrl.substitute_identifiers("a=x")
assert status is False
assert data == "Failed to read manifest content: err"

ctrl.identifiers["test"] = MagicMock(side_effect=ValueError("err"))
status, data = ctrl.substitute_identifiers("a=${test}")
assert status is False
assert "Invalid placeholder bogus" in data
assert data == "Error while processing template: err"

with patch("string.Template.safe_substitute") as mock_func:
mock_func.side_effect = ValueError("err")
status, data = ctrl.substitute_identifiers("a=x")
assert status is False
assert data == "Failed to apply placeholders: err"


# --- registry secret ----------------------------------------------------
Expand Down
Loading