Hi again,
Hmm, I don't spot anything obviously wrong with your example. Knowing
what code is at
keptn.jsonnet:95:26
may be more telling.
My only guess is that....
> , std.extVar('stages'));
...is not producing what you think it is.
Here is, I think, a minimal example of your pattern:
$ jsonnet -e 'std.mapWithIndex(function(i,e) ["in",i,e] + ["out",i,e], std.range(0,1))'
[
[
"in",
0,
0,
"out",
0,
0
],
[
"in",
1,
1,
"out",
1,
1
]
]
If this truly is representative of your code then I think the problem
must be with what pops out of std.extVar(). Especially when using this
function to inject code (instead of just strings) I often have trouble
getting it right on the command line side of the injection. A little
test with just your std.extVar() may be helpful.
If I may give one unsolicited suggestion and just because it is fresh in
my own work: consider using "top-level arguments" (TLA) instead of
std.extVar(). I used to rely on std.extVar() heavily to "inject" data
from the command line but found it rather awkward and its use has two
big issues which TLA overcomes:
- you *must* provide every extVar (no way to set a default so a extVar
may be optional)
- you can not provide an extVar from Jsonnet (no way to reuse
extVar-using Jsonnet from other Jsonnet which may know the proper
extVar values to use).
The only downside with TLA (that I found) is that it requires factoring
existing extVar-using code into a top-level function definition.
Arguably, the effort to do that will almost always make the code far
better but it can still be a small pain to do the work. It tends to
turn big monoliths into many small files.
Because I *just* worked this out for myself yesterday, here is a simple
but full example. The "printf" part is some Bash to form a JSON string
from a matching set of file names.
$ cat junk.jsonnet
function(msg="",foo=[]) [msg]+foo
## make a Jsonnet array from one scalar and a JSON array formed from
## matching file names
$ jsonnet --tla-str msg="hello" --tla-code foo="[ $(printf '"%s", ' *.org) ]" junk.jsonnet
[
"hello",
"README.org"
]
## show call relying on default argument values
$ jsonnet junk.jsonnet
[
""
]
## show use of original function fully inside Jsonnet
$ cat junk2.jsonnet
local junk = import "junk.jsonnet";
junk("goodbye", ["a", "b", "c"])
$ jsonnet junk2.jsonnet
[
"goodbye",
"a",
"b",
"c"
]
Cheers,
-Brett.