97 lines
3.7 KiB
Jsonnet
97 lines
3.7 KiB
Jsonnet
local chart = import 'chart.jsonnet';
|
|
local vars = import 'vars.jsonnet';
|
|
|
|
{
|
|
parent_dir(filePath)::
|
|
std.splitLimit(filePath, '/', 1)[0],
|
|
|
|
file_name(filePath)::
|
|
local words = std.split(filePath, '/');
|
|
words[std.length(words) - 1],
|
|
|
|
// Returns the root domain for given domain
|
|
// dev-camunda.np.navi-tech.in => navi-tech.in
|
|
// dev-camunda.np.navi-ext.com => navi-ext.com
|
|
root_domain(domain)::
|
|
local words = std.split(domain, '.');
|
|
words[std.length(words) - 2] + '.' + words[std.length(words) - 1],
|
|
|
|
get_certs(ssls, domain)::
|
|
local qualified_certificates = std.prune([if std.findSubstr(ssl, domain) != [] then ssl for ssl in std.sort(ssls)]);
|
|
if std.length(qualified_certificates) == 0 then error 'No cert found for domain: %s' % domain
|
|
else qualified_certificates[std.length(qualified_certificates) - 1],
|
|
|
|
// Returns hostname for given full endpoint urls like following
|
|
// https://dev-camunda.np.navi-tech.in => dev-camuna.np.navi-tech.in
|
|
// https://dev-camunda.np.navi-tech.in/camunda => dev-camuna.np.navi-tech.in
|
|
// dev-camunda.np.navi-tech.in:3131 => dev-camuna.np.navi-tech.in
|
|
// 192.168.1.1 => 192.168.1.1
|
|
host_name(endpoint)::
|
|
if std.findSubstr('://', endpoint) != [] then local hostNameStart = std.findSubstr('://', endpoint); self.host_name(std.substr(endpoint, hostNameStart[0] + 3, 9999))
|
|
else if std.findSubstr(':', endpoint) != [] then self.host_name(std.split(endpoint, ':')[0])
|
|
else if std.findSubstr('/', endpoint) != [] then self.host_name(std.split(endpoint, '/')[0])
|
|
else endpoint,
|
|
|
|
is_ipv4_address(endpoint)::
|
|
local ipChars = std.split(endpoint, '.');
|
|
std.length(ipChars) == 4 && std.length(std.filter(function(ipChar) std.length(ipChar) >= 1 && std.length(ipChar) <= 3, ipChars)) == 4,
|
|
|
|
is_field_present(object, field)::
|
|
if object == null then false
|
|
else std.objectHas(object, field),
|
|
|
|
memory_in_mb(memory)::
|
|
local unitMap = {
|
|
Mi: 1,
|
|
Gi: 1024,
|
|
};
|
|
local length = std.length(memory);
|
|
local value = std.parseInt(std.substr(memory, 0, length - 2));
|
|
local unit = std.substr(memory, length - 2, 2);
|
|
value * unitMap[unit],
|
|
|
|
cpu_in_milli_core(cpu)::
|
|
local cpuStr = cpu + '';
|
|
if std.substr(cpuStr, std.length(cpuStr) - 1, 1) == 'm' then cpu else '%dm' % (cpu * 1000),
|
|
|
|
replace_character_in_string(str, a, b):: (
|
|
assert std.length(a) == 1;
|
|
std.join(b, std.split(str, a))
|
|
),
|
|
|
|
is_sandbox(env):: if env == 'sandbox' then true else false,
|
|
|
|
is_local_sandbox(image, env):: std.extVar('IMAGE') == 'null' && $.is_sandbox(env) && (image == null || image == 'null'),
|
|
|
|
get_image(image, env)::
|
|
if std.extVar('IMAGE') == 'null' then
|
|
if $.is_local_sandbox(image, env) then
|
|
vars.sandboxImage
|
|
else
|
|
image
|
|
else
|
|
std.extVar('IMAGE'),
|
|
|
|
is_readiness_probe_enabled(image, environment):: !$.is_local_sandbox(image, environment),
|
|
|
|
is_liveness_probe_enabled(image, environment):: !$.is_local_sandbox(image, environment),
|
|
|
|
is_startup_probe_enabled(is_enabled, image, environment):: is_enabled && !$.is_local_sandbox(image, environment),
|
|
|
|
hpa_scale_target_ref(name, controller, isDisabled):: if isDisabled then {
|
|
apiVersion: 'apps/v1',
|
|
kind: 'Deployment',
|
|
name: 'disabled',
|
|
} else if (controller == vars.rolloutController) then {
|
|
apiVersion: 'argoproj.io/v1alpha1',
|
|
kind: 'Rollout',
|
|
name: chart.full_service_name(name),
|
|
} else {
|
|
apiVersion: 'apps/v1',
|
|
kind: 'Deployment',
|
|
name: chart.full_service_name(name),
|
|
},
|
|
|
|
get( object, key, defaultValue ):: if std.objectHas(object, key) then object[key] else defaultValue,
|
|
}
|