Merge pull request #797 from kakkoyun/ksonnet_no_more_17

Remove ksonnet from prometheus-adapter/prometheus-adapter.libsonnet
This commit is contained in:
Paweł Krupa
2020-11-23 11:41:30 +01:00
committed by GitHub

View File

@@ -1,16 +1,9 @@
local k = import 'github.com/ksonnet/ksonnet-lib/ksonnet.beta.4/k.libsonnet';
{ {
_config+:: { _config+:: {
namespace: 'default', namespace: 'default',
versions+:: { versions+:: { prometheusAdapter: 'v0.8.2' },
prometheusAdapter: 'v0.8.2', imageRepos+:: { prometheusAdapter: 'directxman12/k8s-prometheus-adapter' },
},
imageRepos+:: {
prometheusAdapter: 'directxman12/k8s-prometheus-adapter',
},
prometheusAdapter+:: { prometheusAdapter+:: {
name: 'prometheus-adapter', name: 'prometheus-adapter',
@@ -24,46 +17,33 @@ local k = import 'github.com/ksonnet/ksonnet-lib/ksonnet.beta.4/k.libsonnet';
nodeQuery: 'sum(1 - irate(node_cpu_seconds_total{mode="idle"}[5m]) * on(namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:{<<.LabelMatchers>>}) by (<<.GroupBy>>)', nodeQuery: 'sum(1 - irate(node_cpu_seconds_total{mode="idle"}[5m]) * on(namespace, pod) group_left(node) node_namespace_pod:kube_pod_info:{<<.LabelMatchers>>}) by (<<.GroupBy>>)',
resources: { resources: {
overrides: { overrides: {
node: { node: { resource: 'node' },
resource: 'node' namespace: { resource: 'namespace' },
}, pod: { resource: 'pod' },
namespace: {
resource: 'namespace'
},
pod: {
resource: 'pod'
}, },
}, },
}, containerLabel: 'container',
containerLabel: 'container'
}, },
memory: { memory: {
containerQuery: 'sum(container_memory_working_set_bytes{<<.LabelMatchers>>,container!="POD",container!="",pod!=""}) by (<<.GroupBy>>)', containerQuery: 'sum(container_memory_working_set_bytes{<<.LabelMatchers>>,container!="POD",container!="",pod!=""}) by (<<.GroupBy>>)',
nodeQuery: 'sum(node_memory_MemTotal_bytes{job="node-exporter",<<.LabelMatchers>>} - node_memory_MemAvailable_bytes{job="node-exporter",<<.LabelMatchers>>}) by (<<.GroupBy>>)', nodeQuery: 'sum(node_memory_MemTotal_bytes{job="node-exporter",<<.LabelMatchers>>} - node_memory_MemAvailable_bytes{job="node-exporter",<<.LabelMatchers>>}) by (<<.GroupBy>>)',
resources: { resources: {
overrides: { overrides: {
instance: { instance: { resource: 'node' },
resource: 'node' namespace: { resource: 'namespace' },
}, pod: { resource: 'pod' },
namespace: {
resource: 'namespace'
},
pod: {
resource: 'pod'
}, },
}, },
}, containerLabel: 'container',
containerLabel: 'container'
}, },
window: '5m', window: '5m',
}, },
} },
}, },
}, },
prometheusAdapter+:: { prometheusAdapter+:: {
apiService: apiService: {
{
apiVersion: 'apiregistration.k8s.io/v1', apiVersion: 'apiregistration.k8s.io/v1',
kind: 'APIService', kind: 'APIService',
metadata: { metadata: {
@@ -82,14 +62,17 @@ local k = import 'github.com/ksonnet/ksonnet-lib/ksonnet.beta.4/k.libsonnet';
}, },
}, },
configMap: configMap: {
local configmap = k.core.v1.configMap; apiVersion: 'v1',
configmap.new('adapter-config', { 'config.yaml': std.manifestYamlDoc($._config.prometheusAdapter.config) }) + kind: 'ConfigMap',
metadata: {
name: 'adapter-config',
namespace: $._config.prometheusAdapter.namespace,
},
data: { 'config.yaml': std.manifestYamlDoc($._config.prometheusAdapter.config) },
},
configmap.mixin.metadata.withNamespace($._config.prometheusAdapter.namespace), serviceMonitor: {
serviceMonitor:
{
apiVersion: 'monitoring.coreos.com/v1', apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor', kind: 'ServiceMonitor',
metadata: { metadata: {
@@ -115,148 +98,180 @@ local k = import 'github.com/ksonnet/ksonnet-lib/ksonnet.beta.4/k.libsonnet';
}, },
}, },
service: service: {
local service = k.core.v1.service; apiVersion: 'v1',
local servicePort = k.core.v1.service.mixin.spec.portsType; kind: 'Service',
metadata: {
service.new( name: $._config.prometheusAdapter.name,
$._config.prometheusAdapter.name, namespace: $._config.prometheusAdapter.namespace,
$._config.prometheusAdapter.labels, labels: $._config.prometheusAdapter.labels,
servicePort.newNamed('https', 443, 6443), },
) + spec: {
service.mixin.metadata.withNamespace($._config.prometheusAdapter.namespace) + ports: [
service.mixin.metadata.withLabels($._config.prometheusAdapter.labels), { name: 'https', targetPort: 6443, port: 443 },
],
selector: $._config.prometheusAdapter.labels,
},
},
deployment: deployment:
local deployment = k.apps.v1.deployment; local c = {
local volume = deployment.mixin.spec.template.spec.volumesType; name: $._config.prometheusAdapter.name,
local container = deployment.mixin.spec.template.spec.containersType; image: $._config.imageRepos.prometheusAdapter + ':' + $._config.versions.prometheusAdapter,
local containerVolumeMount = container.volumeMountsType; args: [
local c =
container.new($._config.prometheusAdapter.name, $._config.imageRepos.prometheusAdapter + ':' + $._config.versions.prometheusAdapter) +
container.withArgs([
'--cert-dir=/var/run/serving-cert', '--cert-dir=/var/run/serving-cert',
'--config=/etc/adapter/config.yaml', '--config=/etc/adapter/config.yaml',
'--logtostderr=true', '--logtostderr=true',
'--metrics-relist-interval=1m', '--metrics-relist-interval=1m',
'--prometheus-url=' + $._config.prometheusAdapter.prometheusURL, '--prometheus-url=' + $._config.prometheusAdapter.prometheusURL,
'--secure-port=6443', '--secure-port=6443',
]) + ],
container.withPorts([{ containerPort: 6443 }]) + ports: [{ containerPort: 6443 }],
container.withVolumeMounts([ volumeMounts: [
containerVolumeMount.new('tmpfs', '/tmp'), { name: 'tmpfs', mountPath: '/tmp', readOnly: false },
containerVolumeMount.new('volume-serving-cert', '/var/run/serving-cert'), { name: 'volume-serving-cert', mountPath: '/var/run/serving-cert', readOnly: false },
containerVolumeMount.new('config', '/etc/adapter'), { name: 'config', mountPath: '/etc/adapter', readOnly: false },
],); ],
};
deployment.new($._config.prometheusAdapter.name, 1, c, $._config.prometheusAdapter.labels) + {
deployment.mixin.metadata.withNamespace($._config.prometheusAdapter.namespace) + apiVersion: 'apps/v1',
deployment.mixin.spec.selector.withMatchLabels($._config.prometheusAdapter.labels) + kind: 'Deployment',
deployment.mixin.spec.template.spec.withServiceAccountName($.prometheusAdapter.serviceAccount.metadata.name) + metadata: {
deployment.mixin.spec.template.spec.withNodeSelector({ 'kubernetes.io/os': 'linux' }) + name: $._config.prometheusAdapter.name,
deployment.mixin.spec.strategy.rollingUpdate.withMaxSurge(1) + namespace: $._config.prometheusAdapter.namespace,
deployment.mixin.spec.strategy.rollingUpdate.withMaxUnavailable(0) + },
deployment.mixin.spec.template.spec.withVolumes([ spec: {
volume.fromEmptyDir(name='tmpfs'), replicas: 1,
volume.fromEmptyDir(name='volume-serving-cert'), selector: { matchLabels: $._config.prometheusAdapter.labels },
strategy: {
rollingUpdate: {
maxSurge: 1,
maxUnavailable: 0,
},
},
template: {
metadata: { labels: $._config.prometheusAdapter.labels },
spec: {
containers: [c],
serviceAccountName: $.prometheusAdapter.serviceAccount.metadata.name,
nodeSelector: { 'kubernetes.io/os': 'linux' },
volumes: [
{ name: 'tmpfs', emptyDir: {} },
{ name: 'volume-serving-cert', emptyDir: {} },
{ name: 'config', configMap: { name: 'adapter-config' } }, { name: 'config', configMap: { name: 'adapter-config' } },
]), ],
},
},
},
},
serviceAccount: serviceAccount: {
local serviceAccount = k.core.v1.serviceAccount; apiVersion: 'v1',
kind: 'ServiceAccount',
metadata: {
name: $._config.prometheusAdapter.name,
namespace: $._config.prometheusAdapter.namespace,
},
},
serviceAccount.new($._config.prometheusAdapter.name) + clusterRole: {
serviceAccount.mixin.metadata.withNamespace($._config.prometheusAdapter.namespace), apiVersion: 'rbac.authorization.k8s.io/v1',
kind: 'ClusterRole',
metadata: {
name: $._config.prometheusAdapter.name,
},
rules: [{
apiGroups: [''],
resources: ['nodes', 'namespaces', 'pods', 'services'],
verbs: ['get', 'list', 'watch'],
}],
},
clusterRole: clusterRoleBinding: {
local clusterRole = k.rbac.v1.clusterRole; apiVersion: 'rbac.authorization.k8s.io/v1',
local policyRule = clusterRole.rulesType; kind: 'ClusterRoleBinding',
metadata: {
local rules = name: $._config.prometheusAdapter.name,
policyRule.new() + },
policyRule.withApiGroups(['']) + roleRef: {
policyRule.withResources(['nodes', 'namespaces', 'pods', 'services']) + apiGroup: 'rbac.authorization.k8s.io',
policyRule.withVerbs(['get', 'list', 'watch']); kind: 'ClusterRole',
name: $.prometheusAdapter.clusterRole.metadata.name,
clusterRole.new() + },
clusterRole.mixin.metadata.withName($._config.prometheusAdapter.name) + subjects: [{
clusterRole.withRules(rules),
clusterRoleBinding:
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding;
clusterRoleBinding.new() +
clusterRoleBinding.mixin.metadata.withName($._config.prometheusAdapter.name) +
clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') +
clusterRoleBinding.mixin.roleRef.withName($.prometheusAdapter.clusterRole.metadata.name) +
clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' }) +
clusterRoleBinding.withSubjects([{
kind: 'ServiceAccount', kind: 'ServiceAccount',
name: $.prometheusAdapter.serviceAccount.metadata.name, name: $.prometheusAdapter.serviceAccount.metadata.name,
namespace: $._config.prometheusAdapter.namespace, namespace: $._config.prometheusAdapter.namespace,
}]), }],
},
clusterRoleBindingDelegator: clusterRoleBindingDelegator: {
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding; apiVersion: 'rbac.authorization.k8s.io/v1',
kind: 'ClusterRoleBinding',
clusterRoleBinding.new() + metadata: {
clusterRoleBinding.mixin.metadata.withName('resource-metrics:system:auth-delegator') + name: 'resource-metrics:system:auth-delegator',
clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') + },
clusterRoleBinding.mixin.roleRef.withName('system:auth-delegator') + roleRef: {
clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' }) + apiGroup: 'rbac.authorization.k8s.io',
clusterRoleBinding.withSubjects([{ kind: 'ClusterRole',
name: 'system:auth-delegator',
},
subjects: [{
kind: 'ServiceAccount', kind: 'ServiceAccount',
name: $.prometheusAdapter.serviceAccount.metadata.name, name: $.prometheusAdapter.serviceAccount.metadata.name,
namespace: $._config.prometheusAdapter.namespace, namespace: $._config.prometheusAdapter.namespace,
}]), }],
},
clusterRoleServerResources: clusterRoleServerResources: {
local clusterRole = k.rbac.v1.clusterRole; apiVersion: 'rbac.authorization.k8s.io/v1',
local policyRule = clusterRole.rulesType; kind: 'ClusterRole',
metadata: {
name: 'resource-metrics-server-resources',
},
rules: [{
apiGroups: ['metrics.k8s.io'],
resources: ['*'],
verbs: ['*'],
}],
},
local rules = clusterRoleAggregatedMetricsReader: {
policyRule.new() + apiVersion: 'rbac.authorization.k8s.io/v1',
policyRule.withApiGroups(['metrics.k8s.io']) + kind: 'ClusterRole',
policyRule.withResources(['*']) + metadata: {
policyRule.withVerbs(['*']); name: 'system:aggregated-metrics-reader',
labels: {
'rbac.authorization.k8s.io/aggregate-to-admin': 'true',
'rbac.authorization.k8s.io/aggregate-to-edit': 'true',
'rbac.authorization.k8s.io/aggregate-to-view': 'true',
},
},
rules: [{
apiGroups: ['metrics.k8s.io'],
resources: ['pods', 'nodes'],
verbs: ['get', 'list', 'watch'],
}],
},
clusterRole.new() + roleBindingAuthReader: {
clusterRole.mixin.metadata.withName('resource-metrics-server-resources') + apiVersion: 'rbac.authorization.k8s.io/v1',
clusterRole.withRules(rules), kind: 'RoleBinding',
metadata: {
clusterRoleAggregatedMetricsReader: name: 'resource-metrics-auth-reader',
local clusterRole = k.rbac.v1.clusterRole; namespace: 'kube-system',
local policyRule = clusterRole.rulesType; },
roleRef: {
local rules = apiGroup: 'rbac.authorization.k8s.io',
policyRule.new() + kind: 'Role',
policyRule.withApiGroups(['metrics.k8s.io']) + name: 'extension-apiserver-authentication-reader',
policyRule.withResources(['pods', 'nodes']) + },
policyRule.withVerbs(['get','list','watch']); subjects: [{
clusterRole.new() +
clusterRole.mixin.metadata.withName('system:aggregated-metrics-reader') +
clusterRole.mixin.metadata.withLabels({
"rbac.authorization.k8s.io/aggregate-to-admin": "true",
"rbac.authorization.k8s.io/aggregate-to-edit": "true",
"rbac.authorization.k8s.io/aggregate-to-view": "true",
}) +
clusterRole.withRules(rules),
roleBindingAuthReader:
local roleBinding = k.rbac.v1.roleBinding;
roleBinding.new() +
roleBinding.mixin.metadata.withName('resource-metrics-auth-reader') +
roleBinding.mixin.metadata.withNamespace('kube-system') +
roleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') +
roleBinding.mixin.roleRef.withName('extension-apiserver-authentication-reader') +
roleBinding.mixin.roleRef.mixinInstance({ kind: 'Role' }) +
roleBinding.withSubjects([{
kind: 'ServiceAccount', kind: 'ServiceAccount',
name: $.prometheusAdapter.serviceAccount.metadata.name, name: $.prometheusAdapter.serviceAccount.metadata.name,
namespace: $._config.prometheusAdapter.namespace, namespace: $._config.prometheusAdapter.namespace,
}]), }],
},
}, },
} }