2019-08-08 22:09:53 +02:00
|
|
|
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
2019-09-27 00:02:33 +02:00
|
|
|
local utils = import 'utils.libsonnet';
|
2018-12-12 18:18:00 +01:00
|
|
|
|
2019-02-27 13:28:00 +01:00
|
|
|
{
|
2018-12-12 18:18:00 +01:00
|
|
|
_config+:: {
|
|
|
|
namespace: 'monitoring',
|
2019-03-22 19:23:23 +01:00
|
|
|
|
|
|
|
versions+:: {
|
|
|
|
armExporter: 'latest',
|
|
|
|
},
|
|
|
|
|
|
|
|
imageRepos+:: {
|
|
|
|
armExporter: 'carlosedp/arm_exporter',
|
|
|
|
},
|
2018-12-12 18:18:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
armExporter+:: {
|
2019-04-23 17:03:34 +02:00
|
|
|
clusterRoleBinding:
|
|
|
|
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding;
|
|
|
|
|
|
|
|
clusterRoleBinding.new() +
|
|
|
|
clusterRoleBinding.mixin.metadata.withName('arm-exporter') +
|
|
|
|
clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') +
|
|
|
|
clusterRoleBinding.mixin.roleRef.withName('arm-exporter') +
|
|
|
|
clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' }) +
|
|
|
|
clusterRoleBinding.withSubjects([{ kind: 'ServiceAccount', name: 'arm-exporter', namespace: $._config.namespace }]),
|
|
|
|
|
|
|
|
clusterRole:
|
|
|
|
local clusterRole = k.rbac.v1.clusterRole;
|
|
|
|
local policyRule = clusterRole.rulesType;
|
|
|
|
|
|
|
|
local authenticationRole = policyRule.new() +
|
|
|
|
policyRule.withApiGroups(['authentication.k8s.io']) +
|
|
|
|
policyRule.withResources([
|
|
|
|
'tokenreviews',
|
|
|
|
]) +
|
|
|
|
policyRule.withVerbs(['create']);
|
|
|
|
|
|
|
|
local authorizationRole = policyRule.new() +
|
|
|
|
policyRule.withApiGroups(['authorization.k8s.io']) +
|
|
|
|
policyRule.withResources([
|
|
|
|
'subjectaccessreviews',
|
|
|
|
]) +
|
|
|
|
policyRule.withVerbs(['create']);
|
|
|
|
|
|
|
|
local rules = [authenticationRole, authorizationRole];
|
|
|
|
|
|
|
|
clusterRole.new() +
|
|
|
|
clusterRole.mixin.metadata.withName('arm-exporter') +
|
|
|
|
clusterRole.withRules(rules),
|
|
|
|
|
|
|
|
serviceAccount:
|
|
|
|
local serviceAccount = k.core.v1.serviceAccount;
|
|
|
|
|
|
|
|
serviceAccount.new('arm-exporter') +
|
|
|
|
serviceAccount.mixin.metadata.withNamespace($._config.namespace),
|
|
|
|
|
2018-12-12 18:18:00 +01:00
|
|
|
daemonset:
|
|
|
|
local daemonset = k.apps.v1beta2.daemonSet;
|
|
|
|
local container = daemonset.mixin.spec.template.spec.containersType;
|
|
|
|
local containerPort = container.portsType;
|
2019-02-27 17:18:13 +01:00
|
|
|
local containerEnv = container.envType;
|
2018-12-12 18:18:00 +01:00
|
|
|
|
|
|
|
local podLabels = { 'k8s-app': 'arm-exporter' };
|
|
|
|
|
|
|
|
local armExporter =
|
|
|
|
container.new('arm-exporter', $._config.imageRepos.armExporter + ':' + $._config.versions.armExporter) +
|
2019-02-27 17:18:13 +01:00
|
|
|
container.withCommand([
|
|
|
|
'/bin/rpi_exporter',
|
|
|
|
'--web.listen-address=127.0.0.1:9243',
|
|
|
|
]) +
|
2019-02-01 14:43:22 +01:00
|
|
|
container.mixin.resources.withRequests({ cpu: '50m', memory: '50Mi' }) +
|
|
|
|
container.mixin.resources.withLimits({ cpu: '100m', memory: '100Mi' });
|
2019-02-27 17:18:13 +01:00
|
|
|
|
|
|
|
local ip = containerEnv.fromFieldPath('IP', 'status.podIP');
|
2018-12-12 18:18:00 +01:00
|
|
|
local proxy =
|
|
|
|
container.new('kube-rbac-proxy', $._config.imageRepos.kubeRbacProxy + ':' + $._config.versions.kubeRbacProxy) +
|
|
|
|
container.withArgs([
|
2019-02-27 17:18:13 +01:00
|
|
|
'--secure-listen-address=$(IP):9243',
|
2018-12-12 18:18:00 +01:00
|
|
|
'--upstream=http://127.0.0.1:9243/',
|
2019-04-23 17:03:34 +02:00
|
|
|
'--tls-cipher-suites=' + std.join(',', $._config.tlsCipherSuites),
|
2018-12-12 18:18:00 +01:00
|
|
|
]) +
|
|
|
|
container.withPorts(containerPort.new(9243) + containerPort.withHostPort(9243) + containerPort.withName('https')) +
|
|
|
|
container.mixin.resources.withRequests({ cpu: '10m', memory: '20Mi' }) +
|
2019-02-27 17:18:13 +01:00
|
|
|
container.mixin.resources.withLimits({ cpu: '20m', memory: '40Mi' }) +
|
|
|
|
container.withEnv([ip]);
|
2018-12-12 18:18:00 +01:00
|
|
|
local c = [armExporter, proxy];
|
|
|
|
|
|
|
|
daemonset.new() +
|
|
|
|
daemonset.mixin.metadata.withName('arm-exporter') +
|
|
|
|
daemonset.mixin.metadata.withNamespace($._config.namespace) +
|
|
|
|
daemonset.mixin.metadata.withLabels(podLabels) +
|
|
|
|
daemonset.mixin.spec.selector.withMatchLabels(podLabels) +
|
|
|
|
daemonset.mixin.spec.template.metadata.withLabels(podLabels) +
|
2019-02-05 19:54:41 +01:00
|
|
|
daemonset.mixin.spec.template.spec.withNodeSelector({ 'beta.kubernetes.io/arch': 'arm64' }) +
|
2019-04-23 17:03:34 +02:00
|
|
|
daemonset.mixin.spec.template.spec.withServiceAccountName('arm-exporter') +
|
2018-12-12 18:18:00 +01:00
|
|
|
daemonset.mixin.spec.template.spec.withContainers(c),
|
2019-09-27 00:02:33 +02:00
|
|
|
|
2018-12-12 18:18:00 +01:00
|
|
|
serviceMonitor:
|
2019-09-27 00:02:33 +02:00
|
|
|
utils.newServiceMonitorHTTPS('arm-exporter',
|
|
|
|
$._config.namespace,
|
|
|
|
{'k8s-app': 'arm-exporter'},
|
|
|
|
$._config.namespace,
|
|
|
|
'https',
|
|
|
|
'https',
|
|
|
|
'/var/run/secrets/kubernetes.io/serviceaccount/token',
|
|
|
|
),
|
2018-12-12 18:18:00 +01:00
|
|
|
|
|
|
|
service:
|
|
|
|
local service = k.core.v1.service;
|
|
|
|
local servicePort = k.core.v1.service.mixin.spec.portsType;
|
|
|
|
|
|
|
|
local armExporterPort = servicePort.newNamed('https', 9243, 'https');
|
|
|
|
|
|
|
|
service.new('arm-exporter', $.armExporter.daemonset.spec.selector.matchLabels, armExporterPort) +
|
|
|
|
service.mixin.metadata.withNamespace($._config.namespace) +
|
|
|
|
service.mixin.metadata.withLabels({ 'k8s-app': 'arm-exporter' }) +
|
|
|
|
service.mixin.spec.withClusterIp('None'),
|
|
|
|
},
|
2019-03-13 22:44:01 +01:00
|
|
|
}
|