Skip to content

Conversation

@hatappi
Copy link
Contributor

@hatappi hatappi commented May 31, 2019

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
Copy link
Contributor Author

hatappi commented May 31, 2019

@eagletmt Please review PR 🙏

@eagletmt
Copy link
Owner

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants