Merge pull request #1072 from dgrisonnet/platform-patch

Allow configuring the platform used directly instead of having to use a patch
This commit is contained in:
Paweł Krupa
2021-04-09 14:29:34 +02:00
committed by GitHub
14 changed files with 85 additions and 66 deletions

View File

@@ -361,57 +361,28 @@ Jsonnet is a turing complete language, any logic can be reflected in it. It also
### Cluster Creation Tools ### Cluster Creation Tools
A common example is that not all Kubernetes clusters are created exactly the same way, meaning the configuration to monitor them may be slightly different. For [kubeadm](examples/jsonnet-snippets/kubeadm.jsonnet), [bootkube](examples/jsonnet-snippets/bootkube.jsonnet), [kops](examples/jsonnet-snippets/kops.jsonnet) and [kubespray](examples/jsonnet-snippets/kubespray.jsonnet) clusters there are mixins available to easily configure these: A common example is that not all Kubernetes clusters are created exactly the same way, meaning the configuration to monitor them may be slightly different. For the following clusters there are mixins available to easily configure them:
kubeadm: * aws
* bootkube
* eks
* gke
* kops-coredns
* kubeadm
* kubespray
[embedmd]:# (examples/jsonnet-snippets/kubeadm.jsonnet) These mixins are selectable via the `platform` field of kubePrometheus:
[embedmd]:# (examples/jsonnet-snippets/platform.jsonnet)
```jsonnet ```jsonnet
(import 'kube-prometheus/main.libsonnet') + (import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kubeadm.libsonnet') {
``` values+:: {
kubePrometheus+: {
bootkube: platform: 'example-platform',
},
[embedmd]:# (examples/jsonnet-snippets/bootkube.jsonnet) },
```jsonnet }
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/bootkube.libsonnet')
```
kops:
[embedmd]:# (examples/jsonnet-snippets/kops.jsonnet)
```jsonnet
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kops.libsonnet')
```
kops with CoreDNS:
If your kops cluster is using CoreDNS, there is an additional mixin to import.
[embedmd]:# (examples/jsonnet-snippets/kops-coredns.jsonnet)
```jsonnet
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kops.libsonnet') +
(import 'kube-prometheus/platforms/kops-coredns.libsonnet')
```
kubespray:
[embedmd]:# (examples/jsonnet-snippets/kubespray.jsonnet)
```jsonnet
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kubespray.libsonnet')
```
aws:
[embedmd]:# (examples/jsonnet-snippets/aws.jsonnet)
```jsonnet
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/aws.libsonnet')
``` ```
### Internal Registry ### Internal Registry

View File

@@ -7,12 +7,14 @@ One fatal issue that can occur is that you run out of IP addresses in your eks c
You can monitor the `awscni` using kube-promethus with : You can monitor the `awscni` using kube-promethus with :
[embedmd]:# (../examples/eks-cni-example.jsonnet) [embedmd]:# (../examples/eks-cni-example.jsonnet)
```jsonnet ```jsonnet
local kp = (import 'kube-prometheus/main.libsonnet') + local kp = (import 'kube-prometheus/main.libsonnet') + {
(import 'kube-prometheus/platforms/eks.libsonnet') + {
values+:: { values+:: {
common+: { common+: {
namespace: 'monitoring', namespace: 'monitoring',
}, },
kubePrometheus+: {
platform: 'eks',
},
}, },
kubernetesControlPlane+: { kubernetesControlPlane+: {
prometheusRuleEksCNI+: { prometheusRuleEksCNI+: {

View File

@@ -1,9 +1,11 @@
local kp = (import 'kube-prometheus/main.libsonnet') + local kp = (import 'kube-prometheus/main.libsonnet') + {
(import 'kube-prometheus/platforms/eks.libsonnet') + {
values+:: { values+:: {
common+: { common+: {
namespace: 'monitoring', namespace: 'monitoring',
}, },
kubePrometheus+: {
platform: 'eks',
},
}, },
kubernetesControlPlane+: { kubernetesControlPlane+: {
prometheusRuleEksCNI+: { prometheusRuleEksCNI+: {

View File

@@ -1,2 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/aws.libsonnet')

View File

@@ -1,2 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/bootkube.libsonnet')

View File

@@ -1,3 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kops.libsonnet') +
(import 'kube-prometheus/platforms/kops-coredns.libsonnet')

View File

@@ -1,2 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kops.libsonnet')

View File

@@ -1,2 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kubeadm.libsonnet')

View File

@@ -1,2 +0,0 @@
(import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kubespray.libsonnet')

View File

@@ -0,0 +1,8 @@
(import 'kube-prometheus/main.libsonnet') +
{
values+:: {
kubePrometheus+: {
platform: 'example-platform',
},
},
}

View File

@@ -1,6 +1,5 @@
local kp = local kp =
(import 'kube-prometheus/main.libsonnet') + (import 'kube-prometheus/main.libsonnet') +
(import 'kube-prometheus/platforms/kubeadm.libsonnet') +
// Note that NodePort type services is likely not a good idea for your production use case, it is only used for demonstration purposes here. // Note that NodePort type services is likely not a good idea for your production use case, it is only used for demonstration purposes here.
(import 'kube-prometheus/addons/node-ports.libsonnet') + (import 'kube-prometheus/addons/node-ports.libsonnet') +
{ {
@@ -19,6 +18,9 @@ local kp =
}, },
}, },
}, },
kubePrometheus+: {
platform: 'kubeadm',
},
}, },
// For simplicity, each of the following values for 'externalUrl': // For simplicity, each of the following values for 'externalUrl':

View File

@@ -9,6 +9,8 @@ local prometheusAdapter = import './components/prometheus-adapter.libsonnet';
local prometheusOperator = import './components/prometheus-operator.libsonnet'; local prometheusOperator = import './components/prometheus-operator.libsonnet';
local prometheus = import './components/prometheus.libsonnet'; local prometheus = import './components/prometheus.libsonnet';
local platformPatch = import './platforms/platforms.libsonnet';
{ {
// using `values` as this is similar to helm // using `values` as this is similar to helm
values:: { values:: {
@@ -104,6 +106,7 @@ local prometheus = import './components/prometheus.libsonnet';
kubePrometheus: { kubePrometheus: {
namespace: $.values.common.namespace, namespace: $.values.common.namespace,
mixin+: { ruleLabels: $.values.common.ruleLabels }, mixin+: { ruleLabels: $.values.common.ruleLabels },
platform: null,
}, },
}, },
@@ -125,4 +128,4 @@ local prometheus = import './components/prometheus.libsonnet';
}, },
}, },
}, },
} } + platformPatch

View File

@@ -0,0 +1,3 @@
# Adding a new platform specific configuration
Adding a new platform specific configuration requires to update the [README](../../../README.md#cluster-creation-tools) and the [platforms.jsonnet](./platform.jsonnet) file by adding the platform to the list of existing ones. This allow the new platform to be discoverable and easily configurable by the users.

View File

@@ -0,0 +1,41 @@
local platforms = {
aws: import './aws.libsonnet',
bootkube: import './bootkube.libsonnet',
gke: import './gke.libsonnet',
eks: import './eks.libsonnet',
kops: import './kops.libsonnet',
kops_coredns: (import './kops.libsonnet') + (import './kops-coredns.libsonnet'),
kubeadm: import './kubeadm.libsonnet',
kubespray: import './kubespray.libsonnet',
};
// platformPatch returns the platform specific patch associated to the given
// platform.
local platformPatch(p) = if p != null && std.objectHas(platforms, p) then platforms[p] else {};
{
// initialize the object to prevent "Indexed object has no field" lint errors
local p = {
alertmanager: {},
blackboxExporter: {},
grafana: {},
kubeStateMetrics: {},
nodeExporter: {},
prometheus: {},
prometheusAdapter: {},
prometheusOperator: {},
kubernetesControlPlane: {},
kubePrometheus: {},
} + platformPatch($.values.kubePrometheus.platform),
alertmanager+: p.alertmanager,
blackboxExporter+: p.blackboxExporter,
grafana+: p.grafana,
kubeStateMetrics+: p.kubeStateMetrics,
nodeExporter+: p.nodeExporter,
prometheus+: p.prometheus,
prometheusAdapter+: p.prometheusAdapter,
prometheusOperator+: p.prometheusOperator,
kubernetesControlPlane+: p.kubernetesControlPlane,
kubePrometheus+: p.kubePrometheus,
}