Search code examples
arrayskubernetesjsonnet

Substitute array to jsonnet


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?


Solution

  • 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)"