Skip to content

Commit 81ddf9c

Browse files
authored
Merge pull request #145 from awslabs/fix/combined-variables
Fix: allow referencing dynamic and static variables in one field
2 parents 179fafb + d0c10f8 commit 81ddf9c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

internal/runtime/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ func (rt *ResourceGroupRuntime) evaluateDynamicVariables() error {
346346
// and are resolved after all the dependencies are resolved.
347347

348348
resolvedResources := maps.Keys(rt.resolvedResources)
349+
resolvedResources = append(resolvedResources, "schema")
349350
env, err := krocel.DefaultEnvironment(krocel.WithResourceIDs(resolvedResources))
350351
if err != nil {
351352
return err
@@ -374,6 +375,8 @@ func (rt *ResourceGroupRuntime) evaluateDynamicVariables() error {
374375
evalContext[dep] = rt.resolvedResources[dep].Object
375376
}
376377

378+
evalContext["schema"] = rt.instance.Unstructured().Object
379+
377380
value, err := evaluateExpression(env, evalContext, variable.Expression)
378381
if err != nil {
379382
if strings.Contains(err.Error(), "no such key") {

internal/runtime/runtime_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func Test_RuntimeWorkflow(t *testing.T) {
179179
},
180180
"spec": map[string]interface{}{
181181
"selector": map[string]interface{}{
182-
"app": "${deployment.spec.selector.app}",
182+
"app": "${deployment.spec.selector.app + schema.spec.appName}",
183183
},
184184
},
185185
}),
@@ -195,7 +195,7 @@ func Test_RuntimeWorkflow(t *testing.T) {
195195
{
196196
FieldDescriptor: variable.FieldDescriptor{
197197
Path: "spec.selector.app",
198-
Expressions: []string{"deployment.spec.selector.app"},
198+
Expressions: []string{"deployment.spec.selector.app + schema.spec.appName"},
199199
StandaloneExpression: true,
200200
},
201201
Kind: variable.ResourceVariableKindDynamic,
@@ -1690,6 +1690,9 @@ func Test_evaluateDynamicVariables(t *testing.T) {
16901690
for _, tt := range tests {
16911691
t.Run(tt.name, func(t *testing.T) {
16921692
rt := &ResourceGroupRuntime{
1693+
instance: newTestResource(
1694+
withObject(map[string]interface{}{}),
1695+
),
16931696
expressionsCache: tt.expressionsCache,
16941697
resolvedResources: tt.resolvedResources,
16951698
}

test/integration/suites/core/conditional_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ var _ = Describe("Conditions", func() {
123123
},
124124
},
125125
"spec": map[string]interface{}{
126-
"serviceAccountName": "${serviceAccountA.metadata.name}",
126+
"serviceAccountName": "${serviceAccountA.metadata.name + schema.spec.name}",
127127
"containers": []interface{}{
128128
map[string]interface{}{
129129
"name": "${schema.spec.name}-deployment",
@@ -302,7 +302,7 @@ var _ = Describe("Conditions", func() {
302302

303303
// Verify deployment specs
304304
g.Expect(deploymentB.Spec.Template.Spec.Containers).To(HaveLen(1))
305-
g.Expect(deploymentB.Spec.Template.Spec.ServiceAccountName).To(Equal(name + "-a"))
305+
g.Expect(deploymentB.Spec.Template.Spec.ServiceAccountName).To(Equal(name + "-a" + name))
306306
}, 20*time.Second, time.Second).Should(Succeed())
307307

308308
// Verify ServiceA is not created

0 commit comments

Comments
 (0)