hako icon indicating copy to clipboard operation
hako copied to clipboard

support --ext-var argument

Open hatappi opened this issue 6 years ago • 2 comments

I will prepare common files for all environments when deploying using hako. and it reads the variable for each environment defined in another file. It is currently used after replacing it with sed -i -e" s / {{ENV}} / dev / g "base.jsonnet.

base.jsonnet

local vars = import './{{ ENV }}/variables.libsonnet';

{
  scheduler: {
    cluster: vars.cluster,
  ...

dev/variables.libsonnet

{
  env: 'dev',
  cluster: 'cluster-dev',
  ...
}

stg/variables.libsonnet

{
  env: 'stg',
  cluster: 'cluster-stg',
  ...
}

jsonnet has sed.extVar for receiving external variables. I can specify this from the command line.

hatappi avatar May 31 '19 03:05 hatappi

@eagletmt Please review PR 🙏

hatappi avatar May 31 '19 03:05 hatappi

I don't think it's a good idea to add dynamic values in Hako application definition. In your example, I highly recommend to define two applications like below.

% cat dev/variables.libsonnet
{
  env: 'dev',
  cluster: 'cluster-dev',
}
% cat stg/variables.libsonnet
{
  env: 'stg',
  cluster: 'cluster-stg',
}
% cat base.libsonnet
local dev = import './dev/variables.libsonnet';
local stg = import './stg/variables.libsonnet';

local variables = {
  dev: dev,
  stg: stg,
};

{
  app(env):: {
    scheduler: {
      cluster: variables[env].cluster,
    },
  },
}
% cat nanika-dev.jsonnet
(import 'base.libsonnet').app('dev')
% cat nanika-stg.jsonnet
(import 'base.libsonnet').app('stg')

eagletmt avatar Jul 26 '19 02:07 eagletmt