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 Feb 3, 2020
1 parent 14ecdd5 commit 26a6684
Show file tree
Hide file tree
Showing 43 changed files with 1,411 additions and 982 deletions.
112 changes: 82 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,90 @@ 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,
local t = (import 'kube-thanos/thanos.libsonnet');
local commonConfig = {
config+:: {
namespace: 'thanos',
version: '0.10.1',
image: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '10Gi',
},
},
},
},
};
{ ['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 b = t.bucket + commonConfig + {
// config+:: {
// name: 'thanos-bucket',
// replicas: 1,
// },
//};
//
//local c = t.compactor + t.compactor.withVolumeClaimTemplate + t.compactor.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-compactor',
// replicas: 1,
// },
//};
//
//local re = t.receive + t.receive.withVolumeClaimTemplate + t.receive.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-receive',
// replicas: 1,
// replicationFactor: 1,
// },
//};
//
//local ru = t.ruler + t.ruler.withVolumeClaimTemplate + t.ruler.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-ruler',
// replicas: 1,
// },
//};
local s = t.store + t.store.withVolumeClaimTemplate + t.store.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-store',
replicas: 1,
},
};
local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
config+:: {
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', 'ruler_replica'],
},
};
//local finalRu = ru {
// config+:: {
// 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) }
```

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
121 changes: 80 additions & 41 deletions all.jsonnet
Original file line number Diff line number Diff line change
@@ -1,48 +1,87 @@
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',
local commonConfig = {
config+:: {
namespace: 'thanos',
version: '0.10.1',
image: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '10Gi',
},
},
},
},
};

{ ['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 b = t.bucket + commonConfig + {
config+:: {
name: 'thanos-bucket',
replicas: 1,
},
};

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

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

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

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

local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
config+:: {
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 {
config+:: {
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) }
102 changes: 77 additions & 25 deletions example.jsonnet
Original file line number Diff line number Diff line change
@@ -1,35 +1,87 @@
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',
},

querier+: {
replicas:: 3,
},
store+: {
replicas:: 1,
local commonConfig = {
config+:: {
namespace: 'thanos',
version: '0.10.1',
image: 'quay.io/thanos/thanos:v0.10.1',
objectStorageConfig: {
name: 'thanos-objectstorage',
key: 'thanos.yaml',
},
volumeClaimTemplate: {
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: '10Gi',
},
},
},
},
};
},
};

//local b = t.bucket + commonConfig + {
// config+:: {
// name: 'thanos-bucket',
// replicas: 1,
// },
//};
//
//local c = t.compactor + t.compactor.withVolumeClaimTemplate + t.compactor.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-compactor',
// replicas: 1,
// },
//};
//
//local re = t.receive + t.receive.withVolumeClaimTemplate + t.receive.withServiceMonitor + commonConfig + {
// config+:: {
// name: 'thanos-receive',
// replicas: 1,
// replicationFactor: 1,
// },
//};
//
//local ru = t.ruler + t.ruler.withVolumeClaimTemplate + t.ruler.withServiceMonitor + commonConfig + {
// config+:: {
// 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.withVolumeClaimTemplate + t.store.withServiceMonitor + commonConfig + {
config+:: {
name: 'thanos-store',
replicas: 1,
},
};

local q = t.querier + t.querier.withServiceMonitor + commonConfig + {
config+:: {
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', 'ruler_replica'],
},
};

//local finalRu = ru {
// config+:: {
// 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) }
Loading

0 comments on commit 26a6684

Please sign in to comment.