Skip to content

Commit 18a7b16

Browse files
committed
refactor: config.yaml to toggle dependency graph status field.
Signed-off-by: Yuki Ito <yuki462@ibm.com>
1 parent b2de359 commit 18a7b16

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

oper8/config/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ manage_status: true
3333
# Whether or not to apply the internal name annotation to output resources
3434
internal_name_annotation: true
3535

36+
# Whether to include the session dependency graph in the CR status field.
37+
# When enabled, the dependency graph will be added to status.componentStatus.dependencyGraph
38+
include_dependency_graph_in_status: false
39+
3640
# Specify a single controller to watch, else an empty string leads to watches
3741
# for all controllers
3842
controller_name: ""

oper8/config/config_validation.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ working_dir:
3030
standalone:
3131
type: bool
3232

33+
include_dependency_graph_in_status:
34+
type: bool
35+
3336
strict_versioning:
3437
type: bool
3538

oper8/reconcile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,12 @@ def _update_reconcile_completion_status(
10871087
"""
10881088
status_update = {
10891089
"component_state": completion_state,
1090-
"dependency_graph": str(session.graph),
10911090
}
10921091

1092+
# Include dependency graph if configured
1093+
if config.library_config.include_dependency_graph_in_status:
1094+
status_update["dependency_graph"] = str(session.graph)
1095+
10931096
# If everything completed and verified, set ready and updating to STABLE
10941097
# and set the status's reconciled version to the desired version
10951098
if completion_state.verify_completed():

tests/test_reconcile.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,63 @@ def test_update_reconcile_completion_status(
13011301
check_status(dm, cr, ready_reason, updating_reason, completion_state)
13021302

13031303

1304+
@pytest.mark.parametrize(
1305+
["include_graph", "should_include_graph"],
1306+
[
1307+
[True, True],
1308+
[False, False],
1309+
],
1310+
)
1311+
def test_update_reconcile_completion_status_dependency_graph_by_config(
1312+
include_graph, should_include_graph
1313+
):
1314+
"""Test that dependency_graph is included in status based on config setting"""
1315+
# Local
1316+
from oper8.dag import Graph
1317+
1318+
# Setup CR
1319+
cr = setup_cr()
1320+
1321+
# Create a graph with nodes
1322+
graph = Graph()
1323+
node_a = Node("A")
1324+
node_b = Node("B")
1325+
graph.add_node(node_a)
1326+
graph.add_node(node_b)
1327+
graph.add_node_dependency(node_a, node_b)
1328+
1329+
completion_state = CompletionState(verified_nodes=[node_a, node_b])
1330+
1331+
dm = MockDeployManager(resources=[cr])
1332+
rm = ReconcileManager(deploy_manager=dm)
1333+
session = setup_session(full_cr=cr, deploy_manager=dm)
1334+
# Access the private __graph attribute
1335+
session._Session__graph = graph
1336+
1337+
# Set the config value
1338+
with library_config(include_dependency_graph_in_status=include_graph):
1339+
rm._update_reconcile_completion_status(session, completion_state)
1340+
1341+
# Check the status
1342+
obj = dm.get_obj(
1343+
kind=cr.kind,
1344+
name=cr.metadata.name,
1345+
namespace=cr.metadata.namespace,
1346+
api_version=cr.apiVersion,
1347+
)
1348+
assert obj is not None
1349+
assert obj.get("status")
1350+
1351+
component_status = obj["status"].get(status.COMPONENT_STATUS)
1352+
assert component_status is not None
1353+
1354+
if should_include_graph:
1355+
assert status.COMPONENT_STATUS_DEPENDENCY_GRAPH in component_status
1356+
assert component_status[status.COMPONENT_STATUS_DEPENDENCY_GRAPH] == str(graph)
1357+
else:
1358+
assert status.COMPONENT_STATUS_DEPENDENCY_GRAPH not in component_status
1359+
1360+
13041361
###############
13051362
## _update_error_status ##
13061363
###############

0 commit comments

Comments
 (0)