Substitute array to jsonnet

3/20/2020

I have a jsonnet file

local version = std.extVar('version');
local entities = std.extVar('entities');

{

    appname::'app-dev',
    version::version,
    entities::entities,

}

The version field seems to be a string, but "entities" field is an array that is located near jsonnet file. I am using kubecfg show to create json file and substitute variables like this:

kubecfg show test.jsonnet --ext-str "version=$VERSION" --ext-str "entities=$(cat entities.txt)"  

Of course, during this command I receive an error:

got "string", expected "array";

Is there any way to substitute array using kubecfg show?

-- Uladzislau Kaminski
arrays
jsonnet
kubernetes

1 Answer

3/20/2020

The solution was found.

kubecfg 0.15.3 has a flag that provides the way to inject jsonnet from the command line, file or environment.

--ext-code      | jsonnet      | commandline    | std.extVar(...) | 
--ext-code-env  | jsonnet      | environment    | std.extVar(...) |
--ext-code-file | jsonnet      | file           | std.extVar(...) |

So, as a result, the solution looks like that:

kubecfg show test.jsonnet --ext-str "version=$VERSION" --ext-code "entities=$(cat entities.txt)"  
-- Uladzislau Kaminski
Source: StackOverflow