Skip to content

Commit 15db89b

Browse files
authored
Update Keip operator to support optional ConfigMapRef and SecretRef for populating environment variables (#35)
1 parent 7ff5a20 commit 15db89b

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION ?= 0.11.0
1+
VERSION ?= 0.12.0
22
GIT_TAG := operator_v$(VERSION)
33
KEIP_INTEGRATION_IMAGE ?= ghcr.io/octoconsulting/keip/minimal-app:latest
44

operator/crd/crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,19 @@ spec:
106106
properties:
107107
name:
108108
type: string
109+
optional:
110+
type: boolean
111+
required:
112+
- name
109113
secretRef:
110114
type: object
111115
properties:
112116
name:
113117
type: string
118+
optional:
119+
type: boolean
120+
required:
121+
- name
114122
oneOf:
115123
- properties:
116124
required:

operator/webhook/core/test/test_sync.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,90 @@ def test_no_env_from(full_route):
420420
assert expected_response == actual_response
421421

422422

423+
def test_env_from_config_map_ref_optional_property_not_present(full_route):
424+
expected_response = load_json_as_dict(
425+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
426+
)
427+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
428+
"envFrom"
429+
][0]["configMapRef"].pop("optional", None)
430+
431+
full_route["parent"]["spec"]["envFrom"][0]["configMapRef"].pop("optional", None)
432+
actual_response = sync(full_route)
433+
434+
assert expected_response == actual_response
435+
436+
437+
def test_env_from_config_map_ref_optional_false(full_route):
438+
expected_response = load_json_as_dict(
439+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
440+
)
441+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
442+
"envFrom"
443+
][0]["configMapRef"]["optional"] = False
444+
445+
full_route["parent"]["spec"]["envFrom"][0]["configMapRef"]["optional"] = False
446+
actual_response = sync(full_route)
447+
448+
assert expected_response == actual_response
449+
450+
451+
def test_env_from_config_map_ref_optional_true(full_route):
452+
expected_response = load_json_as_dict(
453+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
454+
)
455+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
456+
"envFrom"
457+
][0]["configMapRef"]["optional"] = True
458+
459+
full_route["parent"]["spec"]["envFrom"][0]["configMapRef"]["optional"] = True
460+
actual_response = sync(full_route)
461+
462+
assert expected_response == actual_response
463+
464+
465+
def test_env_from_secret_ref_optional_property_not_present(full_route):
466+
expected_response = load_json_as_dict(
467+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
468+
)
469+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
470+
"envFrom"
471+
][1]["secretRef"].pop("optional", None)
472+
473+
full_route["parent"]["spec"]["envFrom"][1]["secretRef"].pop("optional", None)
474+
actual_response = sync(full_route)
475+
476+
assert expected_response == actual_response
477+
478+
479+
def test_env_from_secret_ref_optional_false(full_route):
480+
expected_response = load_json_as_dict(
481+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
482+
)
483+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
484+
"envFrom"
485+
][1]["secretRef"]["optional"] = False
486+
487+
full_route["parent"]["spec"]["envFrom"][1]["secretRef"]["optional"] = False
488+
actual_response = sync(full_route)
489+
490+
assert expected_response == actual_response
491+
492+
493+
def test_env_from_secret_ref_optional_true(full_route):
494+
expected_response = load_json_as_dict(
495+
f"{os.path.dirname(os.path.abspath(__file__))}/json/full-response.json"
496+
)
497+
expected_response["children"][0]["spec"]["template"]["spec"]["containers"][0][
498+
"envFrom"
499+
][1]["secretRef"]["optional"] = True
500+
501+
full_route["parent"]["spec"]["envFrom"][1]["secretRef"]["optional"] = True
502+
actual_response = sync(full_route)
503+
504+
assert expected_response == actual_response
505+
506+
423507
def test_deployment_missing_labels(full_route):
424508
del full_route["parent"]["spec"]["labels"]
425509

0 commit comments

Comments
 (0)