Skip to content

Commit f5583d1

Browse files
committed
crude var injection
1 parent 9c9b8c9 commit f5583d1

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

internal/eval/eval.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ func evaluationCode(c Context, file string) evalFn {
264264
instances := load.Instances([]string{}, &load.Config{
265265
Package: "_", // file that don't belong to a package
266266
Dir: filepath.Dir(file),
267+
// Requires string array with values of form k=v
268+
Tags: tlas,
269+
// Add builtin tags
270+
TagVars: load.DefaultTagVars(),
267271
// Maybe we'll want to process only select files like index.cue instead of all cue files
268272
//Overlay: map[string]load.Source{file: load.FromBytes(f)},
269273
})

internal/eval/eval_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io/ioutil"
2323
"os"
2424
"path/filepath"
25+
"runtime"
2526
"testing"
2627

2728
"github.com/splunk/qbec/internal/model"
@@ -133,9 +134,11 @@ func TestEvalComponents(t *testing.T) {
133134
Files: []string{"testdata/components/c.jsonnet"},
134135
},
135136
{
136-
Name: "cue",
137-
Files: []string{"testdata/components/cue/index.cue"},
137+
Name: "cue",
138+
Files: []string{"testdata/components/cue/index.cue"},
139+
TopLevelVars: []string{"fooVal=baz"},
138140
},
141+
139142
{
140143
Name: "a",
141144
Files: []string{"testdata/components/a.json"},
@@ -194,6 +197,8 @@ func TestEvalComponents(t *testing.T) {
194197
obj = objs[3]
195198
a.Equal("cue", obj.Component())
196199
a.Equal("name-from-helper-pkg", obj.GetName())
200+
a.Equal("baz", obj.GetAnnotations()["qbec.io/injectedVar"])
201+
a.Equal(runtime.GOOS, obj.GetAnnotations()["qbec.io/injectedBuiltinOS"])
197202

198203
obj = objs[4]
199204
a.Equal("d", obj.Component())
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import "qbec.io/helper"
2-
2+
#fooVal: *"bar" | string @tag(fooVal)
33
apiVersion: "v1"
44
kind: "ConfigMap"
5-
metadata: name: helper.name
6-
data: foo: "bar"
5+
metadata: {
6+
name: helper.name
7+
annotations: {
8+
"qbec.io/injectedVar": #fooVal
9+
"qbec.io/injectedBuiltinOS": string @tag(someTagname,var=os)
10+
}
11+
}
12+
data: foo: #fooVal

site/content/reference/component-evaluation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ How qbec evaluates component code using jsonnet and what it expects the output t
1212
* Check immediate subdirectories of the component directory to see if they contain an `index.jsonnet`, `index.cue` or `index.yaml` file.
1313
If so, create a component with the sub-directory name.
1414
* If an `index.jsonnet` file exists load it for component processing.
15-
* If an `index.cue` file exists load it for component processing.
15+
* If an `index.cue` file exists load it for component processing (experimental).
1616
* If an `index.yaml` file exists load all `.json` and `.yaml` files in the subdirectory.
1717

1818
## Jsonnet evaluation

0 commit comments

Comments
 (0)