Skip to content

Commit

Permalink
Merge pull request #1475 from paulfantom/fields-convention
Browse files Browse the repository at this point in the history
jsonnet: establish convention for components default fields
  • Loading branch information
ArthurSens authored Nov 3, 2021
2 parents 33b58ae + 9c959ba commit 31d86b7
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 77 deletions.
12 changes: 7 additions & 5 deletions jsonnet/kube-prometheus/components/alertmanager.libsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local defaults = {
local defaults = self,
namespace: error 'must provide namespace',
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
namespace:: error 'must provide namespace',
image: error 'must provide image',
version: error 'must provide version',
resources: {
Expand All @@ -18,9 +20,9 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
name: error 'must provide name',
reloaderPort: 8080,
config: {
name:: error 'must provide name',
reloaderPort:: 8080,
config:: {
global: {
resolve_timeout: '5m',
},
Expand Down Expand Up @@ -59,7 +61,7 @@ local defaults = {
],
},
replicas: 3,
mixin: {
mixin:: {
ruleLabels: {},
_config: {
alertmanagerName: '{{ $labels.namespace }}/{{ $labels.pod}}',
Expand Down
24 changes: 13 additions & 11 deletions jsonnet/kube-prometheus/components/blackbox-exporter.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ local krp = import './kube-rbac-proxy.libsonnet';

local defaults = {
local defaults = self,
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide version',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image:: error 'must provide version',
resources:: {
requests: { cpu: '10m', memory: '20Mi' },
limits: { cpu: '20m', memory: '40Mi' },
},
Expand All @@ -20,13 +22,13 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
configmapReloaderImage: error 'must provide version',
kubeRbacProxyImage: error 'must provide kubeRbacProxyImage',
configmapReloaderImage:: error 'must provide version',
kubeRbacProxyImage:: error 'must provide kubeRbacProxyImage',

port: 9115,
internalPort: 19115,
replicas: 1,
modules: {
port:: 9115,
internalPort:: 19115,
replicas:: 1,
modules:: {
http_2xx: {
prober: 'http',
http: {
Expand Down Expand Up @@ -81,7 +83,7 @@ local defaults = {
},
},
},
privileged:
privileged::
local icmpModules = [self.modules[m] for m in std.objectFields(self.modules) if self.modules[m].prober == 'icmp'];
std.length(icmpModules) > 0,
};
Expand Down
14 changes: 8 additions & 6 deletions jsonnet/kube-prometheus/components/grafana.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ local kubernetesGrafana = import 'github.com/brancz/kubernetes-grafana/grafana/g

local defaults = {
local defaults = self,
name: 'grafana',
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide image',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
name:: 'grafana',
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image:: error 'must provide image',
resources:: {
requests: { cpu: '100m', memory: '100Mi' },
limits: { cpu: '200m', memory: '200Mi' },
},
Expand All @@ -21,7 +23,7 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
prometheusName: error 'must provide prometheus name',
prometheusName:: error 'must provide prometheus name',
};

function(params)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local relabelings = import '../addons/dropping-deprecated-metrics-relabelings.libsonnet';

local defaults = {
namespace: error 'must provide namespace',
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
namespace:: error 'must provide namespace',
commonLabels:: {
'app.kubernetes.io/name': 'kube-prometheus',
'app.kubernetes.io/part-of': 'kube-prometheus',
},
mixin: {
mixin:: {
ruleLabels: {},
_config: {
cadvisorSelector: 'job="kubelet", metrics_path="/metrics/cadvisor"',
Expand All @@ -22,7 +24,7 @@ local defaults = {
hostNetworkInterfaceSelector: 'device!~"veth.+"',
},
},
kubeProxy: false,
kubeProxy:: false,
};

function(params) {
Expand Down
16 changes: 9 additions & 7 deletions jsonnet/kube-prometheus/components/kube-rbac-proxy.libsonnet
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
local defaults = {
namespace: error 'must provide namespace',
image: error 'must provide image',
ports: error 'must provide ports',
secureListenAddress: error 'must provide secureListenAddress',
upstream: error 'must provide upstream',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
namespace:: error 'must provide namespace',
image:: error 'must provide image',
ports:: error 'must provide ports',
secureListenAddress:: error 'must provide secureListenAddress',
upstream:: error 'must provide upstream',
resources:: {
requests: { cpu: '10m', memory: '20Mi' },
limits: { cpu: '20m', memory: '40Mi' },
},
tlsCipherSuites: [
tlsCipherSuites:: [
'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256', // required by h2: http://golang.org/cl/30721
'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256', // required by h2: http://golang.org/cl/30721

Expand Down
22 changes: 12 additions & 10 deletions jsonnet/kube-prometheus/components/kube-state-metrics.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ local krp = import './kube-rbac-proxy.libsonnet';

local defaults = {
local defaults = self,
name: 'kube-state-metrics',
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide version',
kubeRbacProxyImage: error 'must provide kubeRbacProxyImage',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
name:: 'kube-state-metrics',
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image:: error 'must provide version',
kubeRbacProxyImage:: error 'must provide kubeRbacProxyImage',
resources:: {
requests: { cpu: '10m', memory: '190Mi' },
limits: { cpu: '100m', memory: '250Mi' },
},

kubeRbacProxyMain: {
kubeRbacProxyMain:: {
resources+: {
limits+: { cpu: '40m' },
requests+: { cpu: '20m' },
},
},
scrapeInterval: '30s',
scrapeTimeout: '30s',
scrapeInterval:: '30s',
scrapeTimeout:: '30s',
commonLabels:: {
'app.kubernetes.io/name': defaults.name,
'app.kubernetes.io/version': defaults.version,
Expand All @@ -31,7 +33,7 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
mixin: {
mixin:: {
ruleLabels: {},
_config: {
kubeStateMetricsSelector: 'job="' + defaults.name + '"',
Expand Down
22 changes: 12 additions & 10 deletions jsonnet/kube-prometheus/components/node-exporter.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ local krp = import './kube-rbac-proxy.libsonnet';

local defaults = {
local defaults = self,
name: 'node-exporter',
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide version',
kubeRbacProxyImage: error 'must provide kubeRbacProxyImage',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
name:: 'node-exporter',
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image:: error 'must provide version',
kubeRbacProxyImage:: error 'must provide kubeRbacProxyImage',
resources:: {
requests: { cpu: '102m', memory: '180Mi' },
limits: { cpu: '250m', memory: '180Mi' },
},
listenAddress: '127.0.0.1',
filesystemMountPointsExclude: '^/(dev|proc|sys|var/lib/docker/.+|var/lib/kubelet/pods/.+)($|/)',
port: 9100,
listenAddress:: '127.0.0.1',
filesystemMountPointsExclude:: '^/(dev|proc|sys|var/lib/docker/.+|var/lib/kubelet/pods/.+)($|/)',
port:: 9100,
commonLabels:: {
'app.kubernetes.io/name': defaults.name,
'app.kubernetes.io/version': defaults.version,
Expand All @@ -25,7 +27,7 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
mixin: {
mixin:: {
ruleLabels: {},
_config: {
nodeExporterSelector: 'job="' + defaults.name + '"',
Expand Down
24 changes: 13 additions & 11 deletions jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
local defaults = {
local defaults = self,
name: 'prometheus-adapter',
namespace: error 'must provide namespace',
version: error 'must provide version',
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
name:: 'prometheus-adapter',
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image: error 'must provide image',
resources: {
resources:: {
requests: { cpu: '102m', memory: '180Mi' },
limits: { cpu: '250m', memory: '180Mi' },
},
replicas: 2,
listenAddress: '127.0.0.1',
port: 9100,
replicas:: 2,
listenAddress:: '127.0.0.1',
port:: 9100,
commonLabels:: {
'app.kubernetes.io/name': 'prometheus-adapter',
'app.kubernetes.io/version': defaults.version,
Expand All @@ -24,14 +26,14 @@ local defaults = {
},
// Default range intervals are equal to 4 times the default scrape interval.
// This is done in order to follow Prometheus rule of thumb with irate().
rangeIntervals: {
rangeIntervals:: {
kubelet: '4m',
nodeExporter: '4m',
windowsExporter: '4m',
},

prometheusURL: error 'must provide prometheusURL',
config: {
prometheusURL:: error 'must provide prometheusURL',
config:: {
resourceRules: {
cpu: {
containerQuery: |||
Expand Down Expand Up @@ -95,7 +97,7 @@ local defaults = {
window: '5m',
},
},
tlsCipherSuites: [
tlsCipherSuites:: [
'TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305',
'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305',
'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256',
Expand Down
18 changes: 10 additions & 8 deletions jsonnet/kube-prometheus/components/prometheus-operator.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ local prometheusOperator = import 'github.com/prometheus-operator/prometheus-ope

local defaults = {
local defaults = self,
name: 'prometheus-operator',
namespace: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide image',
kubeRbacProxyImage: error 'must provide kubeRbacProxyImage',
configReloaderImage: error 'must provide config reloader image',
resources: {
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
name:: 'prometheus-operator',
namespace:: error 'must provide namespace',
version:: error 'must provide version',
image:: error 'must provide image',
kubeRbacProxyImage:: error 'must provide kubeRbacProxyImage',
configReloaderImage:: error 'must provide config reloader image',
resources:: {
limits: { cpu: '200m', memory: '200Mi' },
requests: { cpu: '100m', memory: '100Mi' },
},
Expand All @@ -24,7 +26,7 @@ local defaults = {
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
mixin: {
mixin:: {
ruleLabels: {
role: 'alert-rules',
prometheus: defaults.name,
Expand Down
15 changes: 9 additions & 6 deletions jsonnet/kube-prometheus/components/prometheus.libsonnet
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
local defaults = {
local defaults = self,
namespace: error 'must provide namespace',
// Convention: Top-level fields related to CRDs are public, other fields are hidden
// If there is no CRD for the component, everything is hidden in defaults.
namespace:: error 'must provide namespace',
version: error 'must provide version',
image: error 'must provide image',
resources: {
requests: { memory: '400Mi' },
},

name: error 'must provide name',
alertmanagerName: error 'must provide alertmanagerName',
namespaces: ['default', 'kube-system', defaults.namespace],
name:: error 'must provide name',
//TODO: remove alertmanagerName and convert to plain 'alerting' object
alertmanagerName:: error 'must provide alertmanagerName',
namespaces:: ['default', 'kube-system', defaults.namespace],
replicas: 2,
externalLabels: {},
enableFeatures: [],
Expand All @@ -25,7 +28,7 @@ local defaults = {
if !std.setMember(labelName, ['app.kubernetes.io/version'])
} + { prometheus: defaults.name },
ruleSelector: {},
mixin: {
mixin:: {
ruleLabels: {},
_config: {
prometheusSelector: 'job="prometheus-' + defaults.name + '",namespace="' + defaults.namespace + '"',
Expand All @@ -35,7 +38,7 @@ local defaults = {
},
},
thanos: null,
reloaderPort: 8080,
reloaderPort:: 8080,
};


Expand Down

0 comments on commit 31d86b7

Please sign in to comment.