Skip to content

Commit

Permalink
*: Refactor to not mutate global objects
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
  • Loading branch information
brancz committed Jan 31, 2020
1 parent 14ecdd5 commit 3d5f095
Show file tree
Hide file tree
Showing 44 changed files with 1,181 additions and 989 deletions.
84 changes: 52 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,58 @@ Here's [example.jsonnet](example.jsonnet):
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;
local kt =
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
// (import 'kube-thanos/kube-thanos-pvc.libsonnet') + // Uncomment this line to enable PVCs
// (import 'kube-thanos/kube-thanos-receive.libsonnet') +
// (import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
// (import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
},
},
};
{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) }
// { ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) }
local t = (import 'kube-thanos/thanos.libsonnet');
local commonConfig = {
namespace:: 'thanos',
version:: '0.10.1',
image:: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
};
//local c = t.compactor + t.compactor.withServiceMonitor + commonConfig + {
// name:: 'thanos-compactor',
// replicas:: 1,
//};
//
//local re = t.receive + t.receive.withServiceMonitor + commonConfig + {
// name:: 'thanos-receive',
// replicas:: 3,
// replicationFactor:: 3,
//};
//
//local ru = t.ruler + t.ruler.withServiceMonitor + commonConfig + {
// name:: 'thanos-ruler',
// replicas:: 1,
//};
local s = t.store + t.store.withServiceMonitor + commonConfig + {
name:: 'thanos-store',
replicas:: 1,
};
local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
name:: 'thanos-query',
replicas:: 1,
stores:: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [s.service]
],
replicaLabels:: ['prometheus_replica'],
};
//local finalRu = ru {
// queriers:: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [q.service.metadata.name, q.service.metadata.namespace]],
//};
//{ ['thanos-compactor-' + name]: c[name] for name in std.objectFields(c) } +
//{ ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } +
//{ ['thanos-ruler-' + name]: finalRu[name] for name in std.objectFields(finalRu) } +
{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-querier-' + name]: q[name] for name in std.objectFields(q) }
```

And here's the [build.sh](build.sh) script (which uses `vendor/` to render all manifests in a json structure of `{filename: manifest-content}`):
Expand Down
101 changes: 57 additions & 44 deletions all.jsonnet
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;
local t = (import 'kube-thanos/thanos.libsonnet');

local kt =
(import 'kube-thanos/kube-thanos-compactor.libsonnet') +
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
(import 'kube-thanos/kube-thanos-store-pvc.libsonnet') +
(import 'kube-thanos/kube-thanos-receive.libsonnet') +
(import 'kube-thanos/kube-thanos-receive-pvc.libsonnet') +
(import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
(import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
(import 'kube-thanos/kube-thanos-bucket.libsonnet') +
(import 'kube-thanos/kube-thanos-ruler.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},

querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
pvc+:: {
size: '50Gi',
},
},
receive+: {
replicas:: 3,
pvc+:: {
size: '50Gi',
},
},
},
};

{ ['thanos-compactor-' + name]: kt.thanos.compactor[name] for name in std.objectFields(kt.thanos.compactor) } +
{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) } +
{ ['thanos-bucket-' + name]: kt.thanos.bucket[name] for name in std.objectFields(kt.thanos.bucket) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) } +
{ ['thanos-ruler-' + name]: kt.thanos.ruler[name] for name in std.objectFields(kt.thanos.ruler) }
local commonConfig = {
namespace:: 'thanos',
version:: '0.10.1',
image:: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
};

local b = t.bucket + commonConfig + {
name:: 'thanos-bucket',
replicas:: 1,
};

local c = t.compactor + t.compactor.withServiceMonitor + commonConfig + {
name:: 'thanos-compactor',
replicas:: 1,
};

local re = t.receive + t.receive.withPodDisruptionBudget + t.receive.withServiceMonitor + commonConfig + {
name:: 'thanos-receive',
replicas:: 3,
replicationFactor:: 3,
};

local ru = t.ruler + t.ruler.withServiceMonitor + commonConfig + {
name:: 'thanos-ruler',
replicas:: 1,
};

local s = t.store + t.store.withServiceMonitor + commonConfig + {
name:: 'thanos-store',
replicas:: 1,
};

local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
name:: 'thanos-query',
replicas:: 1,
stores:: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [re.service, ru.service, s.service]
],
replicaLabels:: ['prometheus_replica', 'ruler_replica'],
};

local finalRu = ru {
queriers:: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [q.service.metadata.name, q.service.metadata.namespace]],
};

{ ['thanos-bucket-' + name]: b[name] for name in std.objectFields(b) } +
{ ['thanos-compactor-' + name]: c[name] for name in std.objectFields(c) } +
{ ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } +
{ ['thanos-ruler-' + name]: finalRu[name] for name in std.objectFields(finalRu) } +
{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-querier-' + name]: q[name] for name in std.objectFields(q) }
72 changes: 46 additions & 26 deletions example.jsonnet
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
local sts = k.apps.v1.statefulSet;
local deployment = k.apps.v1.deployment;
local t = (import 'kube-thanos/thanos.libsonnet');

local kt =
(import 'kube-thanos/kube-thanos-querier.libsonnet') +
(import 'kube-thanos/kube-thanos-store.libsonnet') +
// (import 'kube-thanos/kube-thanos-pvc.libsonnet') + // Uncomment this line to enable PVCs
// (import 'kube-thanos/kube-thanos-receive.libsonnet') +
// (import 'kube-thanos/kube-thanos-sidecar.libsonnet') +
// (import 'kube-thanos/kube-thanos-servicemonitors.libsonnet') +
{
thanos+:: {
// This is just an example image, set what you need
image:: 'quay.io/thanos/thanos:v0.9.0',
objectStorageConfig+:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
local commonConfig = {
namespace:: 'thanos',
version:: '0.10.1',
image:: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig:: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
};

querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
},
},
};
//local c = t.compactor + t.compactor.withServiceMonitor + commonConfig + {
// name:: 'thanos-compactor',
// replicas:: 1,
//};
//
//local re = t.receive + t.receive.withServiceMonitor + commonConfig + {
// name:: 'thanos-receive',
// replicas:: 3,
// replicationFactor:: 3,
//};
//
//local ru = t.ruler + t.ruler.withServiceMonitor + commonConfig + {
// name:: 'thanos-ruler',
// replicas:: 1,
//};

{ ['thanos-querier-' + name]: kt.thanos.querier[name] for name in std.objectFields(kt.thanos.querier) } +
{ ['thanos-store-' + name]: kt.thanos.store[name] for name in std.objectFields(kt.thanos.store) }
// { ['thanos-receive-' + name]: kt.thanos.receive[name] for name in std.objectFields(kt.thanos.receive) }
local s = t.store + t.store.withServiceMonitor + commonConfig + {
name:: 'thanos-store',
replicas:: 1,
};

local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
name:: 'thanos-query',
replicas:: 1,
stores:: [
'dnssrv+_grpc._tcp.%s.%s.svc.cluster.local' % [service.metadata.name, service.metadata.namespace]
for service in [s.service]
],
replicaLabels:: ['prometheus_replica'],
};

//local finalRu = ru {
// queriers:: ['dnssrv+_http._tcp.%s.%s.svc.cluster.local' % [q.service.metadata.name, q.service.metadata.namespace]],
//};

//{ ['thanos-compactor-' + name]: c[name] for name in std.objectFields(c) } +
//{ ['thanos-receive-' + name]: re[name] for name in std.objectFields(re) } +
//{ ['thanos-ruler-' + name]: finalRu[name] for name in std.objectFields(finalRu) } +
{ ['thanos-store-' + name]: s[name] for name in std.objectFields(s) } +
{ ['thanos-querier-' + name]: q[name] for name in std.objectFields(q) }
18 changes: 13 additions & 5 deletions examples/all/manifests/thanos-bucket-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: thanos-bucket
app.kubernetes.io/component: thanos-bucket
app.kubernetes.io/instance: thanos-bucket
app.kubernetes.io/name: thanos
app.kubernetes.io/version: v0.10.1
name: thanos-bucket
namespace: monitoring
namespace: thanos
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: thanos-bucket
app.kubernetes.io/component: thanos-bucket
app.kubernetes.io/instance: thanos-bucket
app.kubernetes.io/name: thanos
template:
metadata:
labels:
app.kubernetes.io/name: thanos-bucket
app.kubernetes.io/component: thanos-bucket
app.kubernetes.io/instance: thanos-bucket
app.kubernetes.io/name: thanos
app.kubernetes.io/version: v0.10.1
spec:
containers:
- args:
Expand All @@ -26,7 +34,7 @@ spec:
secretKeyRef:
key: thanos.yaml
name: thanos-objectstorage
image: quay.io/thanos/thanos:v0.9.0
image: quay.io/thanos/thanos:v0.10.1
livenessProbe:
failureThreshold: 4
httpGet:
Expand Down
11 changes: 8 additions & 3 deletions examples/all/manifests/thanos-bucket-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: thanos-bucket
app.kubernetes.io/component: thanos-bucket
app.kubernetes.io/instance: thanos-bucket
app.kubernetes.io/name: thanos
app.kubernetes.io/version: v0.10.1
name: thanos-bucket
namespace: monitoring
namespace: thanos
spec:
ports:
- name: http
port: 8080
targetPort: http
selector:
app.kubernetes.io/name: thanos-bucket
app.kubernetes.io/component: thanos-bucket
app.kubernetes.io/instance: thanos-bucket
app.kubernetes.io/name: thanos
11 changes: 8 additions & 3 deletions examples/all/manifests/thanos-compactor-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/name: thanos-compactor
app.kubernetes.io/component: thanos-compactor
app.kubernetes.io/instance: thanos-compactor
app.kubernetes.io/name: thanos
app.kubernetes.io/version: v0.10.1
name: thanos-compactor
namespace: monitoring
namespace: thanos
spec:
ports:
- name: http
port: 10902
targetPort: http
selector:
app.kubernetes.io/name: thanos-compactor
app.kubernetes.io/component: thanos-compactor
app.kubernetes.io/instance: thanos-compactor
app.kubernetes.io/name: thanos
7 changes: 5 additions & 2 deletions examples/all/manifests/thanos-compactor-serviceMonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: thanos-compactor
namespace: monitoring
namespace: thanos
spec:
endpoints:
- port: http
selector:
matchLabels:
app.kubernetes.io/name: thanos-compactor
app.kubernetes.io/component: thanos-compactor
app.kubernetes.io/instance: thanos-compactor
app.kubernetes.io/name: thanos
app.kubernetes.io/version: v0.10.1
Loading

0 comments on commit 3d5f095

Please sign in to comment.