4.7 KiB
4.7 KiB
Postgres variables
- Results are saved to gha_vars table.
- Key is
name, values are various columns starting withvalue_- different types are supported. - Per project variables can be defined here (kubernetes example).
- This is
metrics/{{project_name}}/vars.yamlfor other projects. - They use
varstool, called here (Kubernetes) or here (Prometheus). varscan also be used for defining per project variables using OS commands results.- To use command result just provide
command: [your_command, arg1, ..., argN]invars.yamlfile. It will overwrite value if command result is non-empty. - It can use previous variables by defining
replaces: [[from1, to1], .., [fromN, toN]]. - If
fromisfromNandtoistoN- then it will replace[[fromN]]with:- Already defined variable contents
toNif no special charactes before variable name are used. - Environment variable
toNif used special syntax$toN. - Direct string value
toNif used special syntax:toN.
- Already defined variable contents
- If
fromstarts with:,:from- then it will replacefromdirectly, instead of[[from]]. This allows replace any text, not only template variables. - Any replacement
f->tmade creates additional variablefwith valuetthat can be used in next replacements or next variables. - All those options are used here, here or there.
- We can even create conditional partial (conditional on variable name, in this case
hostname). See this:
- [hostname, os_hostname]
#- [hostname, ':devstats.cncf.io']
- [':testsrv=teststats.cncf.io ', ':']
- [': teststats.cncf.io=testsrv', ':']
- [':testsrv=', ':<!-- ']
- [':=testsrv', ': -->']
- [':prodsrv=devstats.cncf.io ', ':']
- [': devstats.cncf.io=prodsrv', ':']
- [':prodsrv=', ':<!-- ']
- [':=prodsrv', ': -->']
- Assume we already have
os_hostnamevariable which contains current hostname. - In first line we replace all
[[hostname]]with current host name. - Second line is commented out, but here we're replacing
[[hostname]]with hardcoded value. We can comment out 1st line and uncomment 2nd to test how it would work on a specific hostname. - We can use 'test server' markers:
testsrv=[[hostname]]and[[hostname]]=testsrvto mark beginning and end of content that will only be inserted whenhostname = 'teststats.cncf.io'. - We can use 'production server' markers:
prodsrv=[[hostname]]and[[hostname]]=prodsrvto mark beginning and end of content that will only be inserted whenhostname = 'devstats.cncf.io'. - See home dashboard projects panel for example usage.
- This works like this:
- Text
testsrv=[[hostname]]is first replaced with the current hostname, for example:testsrv=teststats.cncf.ioon the test server. - Then we have a direct replacement (marek by replacements starting with
:) 'testsrv=teststats.cncf.io ' -> '', so finally entiretestsrv=[[hostname]]is cleared. - Similar story happens with
[[hostname]]=testsrv. - That makes content between those markers directly available.
- Now let's assume we are on the production server, so
hostname=devstats.cncf.io. - Text
testsrv=[[hostname]]is first replaced with the current hostname, for example:testsrv=devstats.cncf.ioon the test server. - There is no direct replacement for
:testsrv=devstats.cncf.io(there only is:prodsrv=devstats.cncf.iowith this hostname). - But there is replacement for nonmatching
testsrvpart:':testsrv=', ':<!-- ', so finallytestsrv=[[hostname]]->testsrv=devstats.cncf.io-><!-- devstats.cncf.io. - Similar:
[[hostname]]=testsrv->devstats.cncf.io=testsrv->devstats.cncf.io -->, using':=testsrv', ': -->'.
- Text
- So finally
testsrv=[[hostname]]is cleared on the test server and evaluates to<!-- devstats.cncf.ioon the production. [[hostname]]=testsrvis cleared on the test server and evaluates todevstats.cncf.io -->on the production.prodsrv=[[hostname]]is cleared on the production server and evaluates to<!-- teststats.cncf.ioon the test.[[hostname]]=prodsrvis cleared on the production server and evaluates toteststats.cncf.io -->on the test.