1
- local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet' ;
2
-
3
1
{
4
2
local tq = self ,
5
3
@@ -28,30 +26,28 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
28
26
},
29
27
30
28
service:
31
- local service = k.core.v1.service;
32
- local ports = service.mixin.spec.portsType;
33
-
34
- service.new(
35
- tq.config.name,
36
- tq.config.podLabelSelector,
37
- [
38
- ports.newNamed('grpc' , 10901 , 'grpc' ),
39
- ports.newNamed('http' , 9090 , 'http' ),
40
- ]
41
- ) +
42
- service.mixin.metadata.withNamespace(tq.config.namespace) +
43
- service.mixin.metadata.withLabels(tq.config.commonLabels),
29
+ {
30
+ apiVersion: 'v1' ,
31
+ kind: 'Service' ,
32
+ metadata: {
33
+ name: tq.config.name,
34
+ namespace: tq.config.namespace,
35
+ labels: tq.config.commonLabels,
36
+ },
37
+ spec: {
38
+ ports: [
39
+ { name: 'grpc' , targetPort: 'grpc' , port: 10901 },
40
+ { name: 'http' , targetPort: 'http' , port: 9090 },
41
+ ],
42
+ selector: tq.config.podLabelSelector,
43
+ },
44
+ },
44
45
45
46
deployment:
46
- local deployment = k.apps.v1.deployment;
47
- local container = deployment.mixin.spec.template.spec.containersType;
48
- local affinity = deployment.mixin.spec.template.spec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecutionType;
49
- local matchExpression = affinity.mixin.podAffinityTerm.labelSelector.matchExpressionsType;
50
-
51
- local c =
52
- container.new('thanos-query' , tq.config.image) +
53
- container.withTerminationMessagePolicy('FallbackToLogsOnError' ) +
54
- container.withArgs([
47
+ local c = {
48
+ name: 'thanos-query' ,
49
+ image: tq.config.image,
50
+ args: [
55
51
'query' ,
56
52
'--log.level=' + tq.config.logLevel,
57
53
'--grpc-address=0.0.0.0:%d' % tq.service.spec.ports[0 ].port,
@@ -62,41 +58,60 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
62
58
] + [
63
59
'--store=%s' % store
64
60
for store in tq.config.stores
65
- ]) +
66
- container.withPorts([
67
- { name: 'grpc' , containerPort: tq.service.spec.ports[0 ].port },
68
- { name: 'http' , containerPort: tq.service.spec.ports[1 ].port },
69
- ]) +
70
- container.mixin.livenessProbe +
71
- container.mixin.livenessProbe.withPeriodSeconds(30 ) +
72
- container.mixin.livenessProbe.withFailureThreshold(4 ) +
73
- container.mixin.livenessProbe.httpGet.withPort(tq.service.spec.ports[1 ].port) +
74
- container.mixin.livenessProbe.httpGet.withScheme('HTTP' ) +
75
- container.mixin.livenessProbe.httpGet.withPath('/-/healthy' ) +
76
- container.mixin.readinessProbe +
77
- container.mixin.readinessProbe.withPeriodSeconds(5 ) +
78
- container.mixin.readinessProbe.withFailureThreshold(20 ) +
79
- container.mixin.readinessProbe.httpGet.withPort(tq.service.spec.ports[1 ].port) +
80
- container.mixin.readinessProbe.httpGet.withScheme('HTTP' ) +
81
- container.mixin.readinessProbe.httpGet.withPath('/-/ready' );
82
-
83
- deployment.new(tq.config.name, tq.config.replicas, c, tq.config.commonLabels) +
84
- deployment.mixin.metadata.withNamespace(tq.config.namespace) +
85
- deployment.mixin.metadata.withLabels(tq.config.commonLabels) +
86
- deployment.mixin.spec.selector.withMatchLabels(tq.config.podLabelSelector) +
87
- deployment.mixin.spec.template.spec.withTerminationGracePeriodSeconds(120 ) +
88
- deployment.mixin.spec.template.spec.affinity.podAntiAffinity.withPreferredDuringSchedulingIgnoredDuringExecution([
89
- affinity.new() +
90
- affinity.withWeight(100 ) +
91
- affinity.mixin.podAffinityTerm.withNamespaces(tq.config.namespace) +
92
- affinity.mixin.podAffinityTerm.withTopologyKey('kubernetes.io/hostname' ) +
93
- affinity.mixin.podAffinityTerm.labelSelector.withMatchExpressions([
94
- matchExpression.new() +
95
- matchExpression.withKey('app.kubernetes.io/name' ) +
96
- matchExpression.withOperator('In' ) +
97
- matchExpression.withValues([tq.deployment.metadata.labels['app.kubernetes.io/name' ]]),
98
- ]),
99
- ]),
61
+ ],
62
+ ports: [
63
+ { name: port.name, containerPort: port.port }
64
+ for port in tq.service.spec.ports
65
+ ],
66
+ livenessProbe: { failureThreshold: 4 , periodSeconds: 30 , httpGet: {
67
+ scheme: 'HTTP' ,
68
+ port: tq.service.spec.ports[1 ].port,
69
+ path: '/-/healthy' ,
70
+ } },
71
+ readinessProbe: { failureThreshold: 20 , periodSeconds: 5 , httpGet: {
72
+ scheme: 'HTTP' ,
73
+ port: tq.service.spec.ports[1 ].port,
74
+ path: '/-/ready' ,
75
+ } },
76
+ terminationMessagePolicy: 'FallbackToLogsOnError' ,
77
+ };
78
+
79
+ {
80
+ apiVersion: 'apps/v1' ,
81
+ kind: 'Deployment' ,
82
+ metadata: {
83
+ name: tq.config.name,
84
+ namespace: tq.config.namespace,
85
+ labels: tq.config.commonLabels,
86
+ },
87
+ spec: {
88
+ replicas: tq.config.replicas,
89
+ selector: { matchLabels: tq.config.podLabelSelector },
90
+ template: {
91
+ metadata: {
92
+ labels: tq.config.commonLabels,
93
+ },
94
+ spec: {
95
+ containers: [c],
96
+ terminationGracePeriodSeconds: 120 ,
97
+ affinity: { podAntiAffinity: {
98
+ preferredDuringSchedulingIgnoredDuringExecution: [{
99
+ podAffinityTerm: {
100
+ namespaces: [tq.config.namespace],
101
+ topologyKey: 'kubernetes.io/hostname' ,
102
+ labelSelector: { matchExpressions: [{
103
+ key: 'app.kubernetes.io/name' ,
104
+ operator: 'In' ,
105
+ values: [tq.deployment.metadata.labels['app.kubernetes.io/name' ]],
106
+ }] },
107
+ },
108
+ weight: 100 ,
109
+ }],
110
+ } },
111
+ },
112
+ },
113
+ },
114
+ },
100
115
101
116
withServiceMonitor:: {
102
117
local tq = self ,
0 commit comments