mirror of
https://github.com/carlosedp/cluster-monitoring.git
synced 2024-11-20 19:07:17 +01:00
Add new functions. Fix formatting
This commit is contained in:
parent
3202c3fe26
commit
cdc33631f4
122
utils.libsonnet
122
utils.libsonnet
@ -1,5 +1,4 @@
|
|||||||
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||||
local vars = import 'vars.jsonnet';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Generates the manifests for all objects in kp except those starting with "_"
|
// Generates the manifests for all objects in kp except those starting with "_"
|
||||||
@ -39,18 +38,18 @@ local vars = import 'vars.jsonnet';
|
|||||||
local policyRule = clusterRole.rulesType;
|
local policyRule = clusterRole.rulesType;
|
||||||
|
|
||||||
local p(apigroups, resources, verbs) = policyRule.new()
|
local p(apigroups, resources, verbs) = policyRule.new()
|
||||||
+ policyRule.withApiGroups([a for a in apigroups])
|
+ policyRule.withApiGroups([a for a in apigroups])
|
||||||
+ policyRule.withResources([r for r in resources])
|
+ policyRule.withResources([r for r in resources])
|
||||||
+ policyRule.withVerbs([v for v in verbs]);
|
+ policyRule.withVerbs([v for v in verbs]);
|
||||||
|
|
||||||
local r = [ p(pol.apis, pol.res, pol.verbs) for pol in roles ];
|
local r = [ p(pol.apis, pol.res, pol.verbs) for pol in roles ];
|
||||||
|
|
||||||
local rules = r;
|
local rules = r;
|
||||||
|
|
||||||
local c = clusterRole.new()
|
local c = clusterRole.new()
|
||||||
+ (if labels != null then clusterRole.mixin.metadata.withLabels(labels) else {})
|
+ (if labels != null then clusterRole.mixin.metadata.withLabels(labels) else {})
|
||||||
+ clusterRole.mixin.metadata.withName(name)
|
+ clusterRole.mixin.metadata.withName(name)
|
||||||
+ clusterRole.withRules(rules);
|
+ clusterRole.withRules(rules);
|
||||||
c
|
c
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -72,22 +71,22 @@ local vars = import 'vars.jsonnet';
|
|||||||
local endpoints = k.core.v1.endpoints;
|
local endpoints = k.core.v1.endpoints;
|
||||||
local endpointSubset = endpoints.subsetsType;
|
local endpointSubset = endpoints.subsetsType;
|
||||||
local endpointPort = endpointSubset.portsType;
|
local endpointPort = endpointSubset.portsType;
|
||||||
local Port = endpointPort.new() +
|
local Port = endpointPort.new()
|
||||||
endpointPort.withName(portName) +
|
+ endpointPort.withName(portName)
|
||||||
endpointPort.withPort(portNumber) +
|
+ endpointPort.withPort(portNumber)
|
||||||
endpointPort.withProtocol('TCP');
|
+ endpointPort.withProtocol('TCP');
|
||||||
|
|
||||||
local subset = endpointSubset.new() +
|
local subset = endpointSubset.new()
|
||||||
endpointSubset.withAddresses([
|
+ endpointSubset.withAddresses([
|
||||||
{ ip: IP }
|
{ ip: IP }
|
||||||
for IP in ips
|
for IP in ips
|
||||||
]) +
|
])
|
||||||
endpointSubset.withPorts(Port);
|
+ endpointSubset.withPorts(Port);
|
||||||
endpoints.new() +
|
endpoints.new()
|
||||||
endpoints.mixin.metadata.withName(name) +
|
+ endpoints.mixin.metadata.withName(name)
|
||||||
endpoints.mixin.metadata.withNamespace(namespace) +
|
+ endpoints.mixin.metadata.withNamespace(namespace)
|
||||||
endpoints.mixin.metadata.withLabels({ 'k8s-app': name }) +
|
+ endpoints.mixin.metadata.withLabels({ 'k8s-app': name })
|
||||||
endpoints.withSubsets(subset)
|
+ endpoints.withSubsets(subset)
|
||||||
),
|
),
|
||||||
|
|
||||||
// Creates ingress objects
|
// Creates ingress objects
|
||||||
@ -98,17 +97,17 @@ local vars = import 'vars.jsonnet';
|
|||||||
local ingressRule = ingress.mixin.spec.rulesType;
|
local ingressRule = ingress.mixin.spec.rulesType;
|
||||||
local httpIngressPath = ingressRule.mixin.http.pathsType;
|
local httpIngressPath = ingressRule.mixin.http.pathsType;
|
||||||
|
|
||||||
ingress.new() +
|
ingress.new()
|
||||||
ingress.mixin.metadata.withName(name) +
|
+ ingress.mixin.metadata.withName(name)
|
||||||
ingress.mixin.metadata.withNamespace(namespace) +
|
+ ingress.mixin.metadata.withNamespace(namespace)
|
||||||
ingress.mixin.spec.withRules(
|
+ ingress.mixin.spec.withRules(
|
||||||
ingressRule.new() +
|
ingressRule.new()
|
||||||
ingressRule.withHost(host) +
|
+ ingressRule.withHost(host)
|
||||||
ingressRule.mixin.http.withPaths(
|
+ ingressRule.mixin.http.withPaths(
|
||||||
httpIngressPath.new() +
|
httpIngressPath.new()
|
||||||
httpIngressPath.withPath(path) +
|
+ httpIngressPath.withPath(path)
|
||||||
httpIngressPath.mixin.backend.withServiceName(serviceName) +
|
+ httpIngressPath.mixin.backend.withServiceName(serviceName)
|
||||||
httpIngressPath.mixin.backend.withServicePort(servicePort)
|
+ httpIngressPath.mixin.backend.withServicePort(servicePort)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@ -122,16 +121,16 @@ local vars = import 'vars.jsonnet';
|
|||||||
local con =
|
local con =
|
||||||
container.new(name, image)
|
container.new(name, image)
|
||||||
+ (if cmd != null then container.withCommand(cmd) else {})
|
+ (if cmd != null then container.withCommand(cmd) else {})
|
||||||
+ container.withPorts(containerPort.newNamed(port, name+'-port'));
|
+ container.withPorts(containerPort.newNamed(port, name));
|
||||||
|
|
||||||
local c = [con];
|
local c = [con];
|
||||||
|
|
||||||
local d = deployment.new(name, 1, c, {'app': name}) +
|
local d = deployment.new(name, 1, c, {'app': name})
|
||||||
deployment.mixin.metadata.withNamespace(namespace) +
|
+ deployment.mixin.metadata.withNamespace(namespace)
|
||||||
deployment.mixin.metadata.withLabels({'app': name}) +
|
+ deployment.mixin.metadata.withLabels({'app': name})
|
||||||
deployment.mixin.spec.selector.withMatchLabels({'app': name}) +
|
+ deployment.mixin.spec.selector.withMatchLabels({'app': name})
|
||||||
deployment.mixin.spec.strategy.withType('RollingUpdate') +
|
+ deployment.mixin.spec.strategy.withType('RollingUpdate')
|
||||||
deployment.mixin.spec.template.spec.withRestartPolicy('Always');
|
+ deployment.mixin.spec.template.spec.withRestartPolicy('Always');
|
||||||
d
|
d
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -140,9 +139,9 @@ local vars = import 'vars.jsonnet';
|
|||||||
local servicePort = k.core.v1.service.mixin.spec.portsType;
|
local servicePort = k.core.v1.service.mixin.spec.portsType;
|
||||||
local p = servicePort.newNamed(name, port, port);
|
local p = servicePort.newNamed(name, port, port);
|
||||||
|
|
||||||
local s = service.new(name, {'app': name}, p) +
|
local s = service.new(name, {'app': name}, p)
|
||||||
service.mixin.metadata.withNamespace(namespace) +
|
+ service.mixin.metadata.withNamespace(namespace)
|
||||||
service.mixin.metadata.withLabels({'app': name});
|
+ service.mixin.metadata.withLabels({'app': name});
|
||||||
s
|
s
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -197,4 +196,45 @@ local vars = import 'vars.jsonnet';
|
|||||||
std.mergePatch(s, t)
|
std.mergePatch(s, t)
|
||||||
// s + t
|
// s + t
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
|
# Adds arguments to a container in a deployment
|
||||||
|
# args is an array of arguments in the format
|
||||||
|
# ["arg1","arg2",]
|
||||||
|
addArguments(deployment, container, args):: (
|
||||||
|
{spec+: {
|
||||||
|
template+: {
|
||||||
|
spec+: {
|
||||||
|
containers:
|
||||||
|
std.map(
|
||||||
|
function(c)
|
||||||
|
if c.name == container then
|
||||||
|
c { args+: args }
|
||||||
|
else c,
|
||||||
|
super.containers
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
),
|
||||||
|
|
||||||
|
# Adds environment variables to a container in a deployment
|
||||||
|
# envs is an array of environment variables in the format
|
||||||
|
# [{name: 'VARNAME', value: 'var_value'},{...},]
|
||||||
|
addEnviromnentVars(deployment, container, envs):: (
|
||||||
|
{spec+: {
|
||||||
|
template+: {
|
||||||
|
spec+: {
|
||||||
|
containers:
|
||||||
|
std.map(
|
||||||
|
function(c)
|
||||||
|
if c.name == container then
|
||||||
|
c { env+: envs }
|
||||||
|
else c,
|
||||||
|
super.containers
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
),
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user