Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh flattened references when interpolating values #8

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions reclass/datatypes/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ def _interpolate_inner(self, path, inventory):
# list or dict has already been visited by _interpolate_inner
del self._unrendered[path]
return
# Refresh internal ref cache for the unrendered value with our current context
# to ensure that flattened cached references are updated if necessary if the
# value is part of the parameters tree of multiple nodes.
#
# Side-note (@simu,2022-05-27): I haven't quite determined when a value becomes
# part of the parameters tree of multiple nodes, but I've observed it to be the
# case by looking at `hex(id(value))` for the same parameters key in multiple
# targets in an example inventory which results in a ResolveError without the
# line below.
value.assembleRefs(self._base)
self._unrendered[path] = False
self._interpolate_references(path, value, inventory)
new = self._interpolate_render_value(path, value, inventory)
Expand Down
14 changes: 14 additions & 0 deletions reclass/tests/data/07/classes/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
base:
=_mixed_lookup:
v1:
registry: ghcr.io
repository: path/to/image
tag: v1.2.0
v2: ${base:image}

version: v2
image:
registry: ghcr.io
repository: path/to/image
tag: v2.4.0
5 changes: 5 additions & 0 deletions reclass/tests/data/07/classes/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
build:
inputs:
- type: https
source: https://example.com/downloads/${base:_mixed_lookup:${base:version}:tag}/
3 changes: 3 additions & 0 deletions reclass/tests/data/07/classes/global.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
base:
version: v1
3 changes: 3 additions & 0 deletions reclass/tests/data/07/classes/target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
instance:
version: v2
13 changes: 13 additions & 0 deletions reclass/tests/data/07/nodes/t1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
classes:
- base
- build
- global
- target
parameters:
_instance: t1
kapitan:
vars:
target: t1

# Expected value for `parameters.build.inputs.0.source:
# https://example.com/downloads/v1.2.0
15 changes: 15 additions & 0 deletions reclass/tests/data/07/nodes/t2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
classes:
- base
- build
- global
- target
parameters:
_instance: t2
base: ${instance}
instance: {}
kapitan:
vars:
target: t2

# Expected value for `parameters.build.inputs.0.source:
# https://example.com/downloads/v2.4.0
9 changes: 9 additions & 0 deletions reclass/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,14 @@ def test_application_removal(self):
self.assertEqual(A_node['applications'], A_node['parameters']['expected_apps'])
self.assertEqual(B_node['applications'], B_node['parameters']['expected_apps'])

def test_mixed_value_constant_parameter_lookup(self):
reclass = self._core("07")

t1 = reclass.nodeinfo("t1")
t2 = reclass.nodeinfo("t2")

self.assertEqual(t1["parameters"]["build"]["inputs"][0]["source"], "https://example.com/downloads/v1.2.0/")
self.assertEqual(t2["parameters"]["build"]["inputs"][0]["source"], "https://example.com/downloads/v2.4.0/")

if __name__ == '__main__':
unittest.main()