teraslice 2.17.2 → 3.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib/cluster/services/api.js +5 -8
- package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/index.js +1 -1
- package/dist/src/lib/cluster/services/cluster/index.js +0 -4
- package/dist/src/lib/cluster/services/execution.js +1 -1
- package/dist/src/lib/cluster/services/jobs.js +12 -8
- package/dist/src/lib/config/schemas/system.js +1 -1
- package/dist/src/lib/utils/api_utils.js +1 -41
- package/dist/src/lib/workers/helpers/worker-shutdown.js +4 -19
- package/dist/test/utils/api_utils-spec.js +1 -62
- package/package.json +11 -12
- package/dist/src/lib/cluster/services/cluster/backends/kubernetes/index.js +0 -192
- package/dist/src/lib/cluster/services/cluster/backends/kubernetes/k8s.js +0 -481
- package/dist/src/lib/cluster/services/cluster/backends/kubernetes/k8sResource.js +0 -414
- package/dist/src/lib/cluster/services/cluster/backends/kubernetes/k8sState.js +0 -59
- package/dist/src/lib/cluster/services/cluster/backends/kubernetes/utils.js +0 -43
- package/dist/test/lib/cluster/services/cluster/backends/kubernetes/k8s-spec.js +0 -316
- package/dist/test/lib/cluster/services/cluster/backends/kubernetes/k8sResource-spec.js +0 -795
- package/dist/test/lib/cluster/services/cluster/backends/kubernetes/k8sState-multicluster-spec.js +0 -67
- package/dist/test/lib/cluster/services/cluster/backends/kubernetes/k8sState-spec.js +0 -84
- package/dist/test/lib/cluster/services/cluster/backends/kubernetes/utils-spec.js +0 -132
|
@@ -1,795 +0,0 @@
|
|
|
1
|
-
import yaml from 'js-yaml';
|
|
2
|
-
import { debugLogger } from '@terascope/utils';
|
|
3
|
-
import { K8sResource } from '../../../../../../../src/lib/cluster/services/cluster/backends/kubernetes/k8sResource.js';
|
|
4
|
-
describe('k8sResource', () => {
|
|
5
|
-
const logger = debugLogger('k8sResource');
|
|
6
|
-
let execution;
|
|
7
|
-
let terasliceConfig;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
terasliceConfig = {
|
|
10
|
-
shutdown_timeout: 60000,
|
|
11
|
-
assets_directory: '',
|
|
12
|
-
assets_volume: '',
|
|
13
|
-
name: 'ts-dev1',
|
|
14
|
-
env_vars: {
|
|
15
|
-
FOO: 'bar',
|
|
16
|
-
EXAMPLE: 'test'
|
|
17
|
-
},
|
|
18
|
-
kubernetes_image: 'teraslice:k8sdev',
|
|
19
|
-
kubernetes_namespace: 'ts-dev1',
|
|
20
|
-
kubernetes_image_pull_secret: ''
|
|
21
|
-
};
|
|
22
|
-
execution = {
|
|
23
|
-
name: 'example-data-generator-job',
|
|
24
|
-
workers: 2,
|
|
25
|
-
job_id: '7ba9afb0-417a-4936-adc5-b15e31d1edd1',
|
|
26
|
-
ex_id: 'e76a0278-d9bc-4d78-bf14-431bcd97528c',
|
|
27
|
-
env_vars: {
|
|
28
|
-
FOO: 'baz'
|
|
29
|
-
}
|
|
30
|
-
// slicer_port: 45680,
|
|
31
|
-
// slicer_hostname: 'teraslice-execution-controller-e76a0278-d9bc-4d78-bf14-431bcd97'
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
describe('worker deployment', () => {
|
|
35
|
-
it('has valid resource object.', () => {
|
|
36
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
37
|
-
expect(kr.resource.kind).toBe('Deployment');
|
|
38
|
-
expect(kr.resource.spec.replicas).toBe(2);
|
|
39
|
-
expect(kr.resource.metadata.name).toBe('ts-wkr-example-data-generator-job-7ba9afb0-417a');
|
|
40
|
-
// The following properties should be absent in the default case
|
|
41
|
-
// Note: This tests that both affinity and podAntiAffinity are absent
|
|
42
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('affinity');
|
|
43
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('imagePullSecrets');
|
|
44
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('priorityClassName');
|
|
45
|
-
// Configmaps should be mounted on all workers
|
|
46
|
-
expect(kr.resource.spec.template.spec.volumes[0]).toEqual(yaml.load(`
|
|
47
|
-
name: config
|
|
48
|
-
configMap:
|
|
49
|
-
name: ts-dev1-worker
|
|
50
|
-
items:
|
|
51
|
-
- key: teraslice.yaml
|
|
52
|
-
path: teraslice.yaml`));
|
|
53
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[0])
|
|
54
|
-
.toEqual(yaml.load(`
|
|
55
|
-
mountPath: /app/config
|
|
56
|
-
name: config`));
|
|
57
|
-
});
|
|
58
|
-
it('has valid resource object when terasliceConfig has kubernetes_image_pull_secret.', () => {
|
|
59
|
-
terasliceConfig.kubernetes_image_pull_secret = 'teraslice-image-pull-secret';
|
|
60
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
61
|
-
expect(kr.resource.spec.template.spec.imagePullSecrets[0]).toEqual(yaml.load(`
|
|
62
|
-
name: teraslice-image-pull-secret`));
|
|
63
|
-
});
|
|
64
|
-
it('has podAntiAffinity when terasliceConfig has kubernetes_worker_antiaffinity true.', () => {
|
|
65
|
-
terasliceConfig.kubernetes_worker_antiaffinity = true;
|
|
66
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
67
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.affinity));
|
|
68
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
69
|
-
podAntiAffinity:
|
|
70
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
71
|
-
- weight: 1
|
|
72
|
-
podAffinityTerm:
|
|
73
|
-
labelSelector:
|
|
74
|
-
matchExpressions:
|
|
75
|
-
- key: app.kubernetes.io/name
|
|
76
|
-
operator: In
|
|
77
|
-
values:
|
|
78
|
-
- teraslice
|
|
79
|
-
- key: app.kubernetes.io/instance
|
|
80
|
-
operator: In
|
|
81
|
-
values:
|
|
82
|
-
- ts-dev1
|
|
83
|
-
topologyKey: kubernetes.io/hostname`));
|
|
84
|
-
});
|
|
85
|
-
it('has valid resource object with volumes when terasliceConfig has assets_director and assets_volume.', () => {
|
|
86
|
-
terasliceConfig.assets_directory = '/assets';
|
|
87
|
-
terasliceConfig.assets_volume = 'asset-volume';
|
|
88
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
89
|
-
expect(kr.resource.spec.replicas).toBe(2);
|
|
90
|
-
expect(kr.resource.metadata.name).toBe('ts-wkr-example-data-generator-job-7ba9afb0-417a');
|
|
91
|
-
// The following properties should be absent in the default case
|
|
92
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('affinity');
|
|
93
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('imagePullSecrets');
|
|
94
|
-
expect(kr.resource.spec.template.spec.volumes[0]).toEqual(yaml.load(`
|
|
95
|
-
name: config
|
|
96
|
-
configMap:
|
|
97
|
-
name: ts-dev1-worker
|
|
98
|
-
items:
|
|
99
|
-
- key: teraslice.yaml
|
|
100
|
-
path: teraslice.yaml`));
|
|
101
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[0])
|
|
102
|
-
.toEqual(yaml.load(`
|
|
103
|
-
mountPath: /app/config
|
|
104
|
-
name: config`));
|
|
105
|
-
// Now check for the assets volume
|
|
106
|
-
expect(kr.resource.spec.template.spec.volumes[1]).toEqual(yaml.load(`
|
|
107
|
-
name: asset-volume
|
|
108
|
-
persistentVolumeClaim:
|
|
109
|
-
claimName: asset-volume`));
|
|
110
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[1])
|
|
111
|
-
.toEqual(yaml.load(`
|
|
112
|
-
name: asset-volume
|
|
113
|
-
mountPath: /assets`));
|
|
114
|
-
});
|
|
115
|
-
it('has valid resource object with volumes when execution has a single job volume', () => {
|
|
116
|
-
execution.volumes = [
|
|
117
|
-
{ name: 'teraslice-data1', path: '/data' }
|
|
118
|
-
];
|
|
119
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
120
|
-
// First check the configMap volumes, which should be present on all
|
|
121
|
-
// deployments
|
|
122
|
-
expect(kr.resource.spec.template.spec.volumes[0]).toEqual(yaml.load(`
|
|
123
|
-
name: config
|
|
124
|
-
configMap:
|
|
125
|
-
name: ts-dev1-worker
|
|
126
|
-
items:
|
|
127
|
-
- key: teraslice.yaml
|
|
128
|
-
path: teraslice.yaml`));
|
|
129
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[0])
|
|
130
|
-
.toEqual(yaml.load(`
|
|
131
|
-
mountPath: /app/config
|
|
132
|
-
name: config`));
|
|
133
|
-
// Now check for the volume added via config
|
|
134
|
-
expect(kr.resource.spec.template.spec.volumes[1]).toEqual(yaml.load(`
|
|
135
|
-
name: teraslice-data1
|
|
136
|
-
persistentVolumeClaim:
|
|
137
|
-
claimName: teraslice-data1`));
|
|
138
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[1])
|
|
139
|
-
.toEqual(yaml.load(`
|
|
140
|
-
name: teraslice-data1
|
|
141
|
-
mountPath: /data`));
|
|
142
|
-
});
|
|
143
|
-
it('has valid resource object with volumes when execution has two job volumes', () => {
|
|
144
|
-
execution.volumes = [
|
|
145
|
-
{ name: 'teraslice-data1', path: '/data' },
|
|
146
|
-
{ name: 'tmp', path: '/tmp' }
|
|
147
|
-
];
|
|
148
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
149
|
-
// Now check for the volumes added via job
|
|
150
|
-
expect(kr.resource.spec.template.spec.volumes[1]).toEqual(yaml.load(`
|
|
151
|
-
name: teraslice-data1
|
|
152
|
-
persistentVolumeClaim:
|
|
153
|
-
claimName: teraslice-data1`));
|
|
154
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[1])
|
|
155
|
-
.toEqual(yaml.load(`
|
|
156
|
-
name: teraslice-data1
|
|
157
|
-
mountPath: /data`));
|
|
158
|
-
expect(kr.resource.spec.template.spec.volumes[2]).toEqual(yaml.load(`
|
|
159
|
-
name: tmp
|
|
160
|
-
persistentVolumeClaim:
|
|
161
|
-
claimName: tmp`));
|
|
162
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[2])
|
|
163
|
-
.toEqual(yaml.load(`
|
|
164
|
-
name: tmp
|
|
165
|
-
mountPath: /tmp`));
|
|
166
|
-
});
|
|
167
|
-
it('does not have memory/cpu limits/requests when not set in config or execution', () => {
|
|
168
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
169
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
170
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
171
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).not.toBeDefined();
|
|
172
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
173
|
-
expect(envArray).not.toContain('NODE_OPTIONS');
|
|
174
|
-
});
|
|
175
|
-
it('has memory and cpu limits and requests when set on terasliceConfig', () => {
|
|
176
|
-
terasliceConfig.cpu = 1;
|
|
177
|
-
terasliceConfig.memory = 2147483648;
|
|
178
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
179
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
180
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
181
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
182
|
-
requests:
|
|
183
|
-
memory: 2147483648
|
|
184
|
-
cpu: 1
|
|
185
|
-
limits:
|
|
186
|
-
memory: 2147483648
|
|
187
|
-
cpu: 1`));
|
|
188
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
189
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
190
|
-
expect(nodeOptions.value).toEqual('--max-old-space-size=1843');
|
|
191
|
-
});
|
|
192
|
-
it('has the ability to set custom env', () => {
|
|
193
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
194
|
-
// NOTE: the env var merge happens in _setResources(), which is
|
|
195
|
-
// somewhat out of place.
|
|
196
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
197
|
-
const foo = envArray.find((i) => i.name === 'FOO');
|
|
198
|
-
const example = envArray.find((i) => i.name === 'EXAMPLE');
|
|
199
|
-
expect(foo.value).toEqual('baz');
|
|
200
|
-
expect(example.value).toEqual('test');
|
|
201
|
-
});
|
|
202
|
-
it('execution resources override terasliceConfig resources', () => {
|
|
203
|
-
execution.cpu = 2;
|
|
204
|
-
execution.memory = 1073741824;
|
|
205
|
-
terasliceConfig.cpu = 1;
|
|
206
|
-
terasliceConfig.memory = 2147483648;
|
|
207
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
208
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
209
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
210
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
211
|
-
requests:
|
|
212
|
-
memory: 1073741824
|
|
213
|
-
cpu: 2
|
|
214
|
-
limits:
|
|
215
|
-
memory: 1073741824
|
|
216
|
-
cpu: 2`));
|
|
217
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
218
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
219
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=922');
|
|
220
|
-
});
|
|
221
|
-
it('execution cpu overrides terasliceConfig cpu while terasliceConfig memory gets applied', () => {
|
|
222
|
-
execution.cpu = 2;
|
|
223
|
-
terasliceConfig.cpu = 1;
|
|
224
|
-
terasliceConfig.memory = 2147483648;
|
|
225
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
226
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
227
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
228
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
229
|
-
requests:
|
|
230
|
-
memory: 2147483648
|
|
231
|
-
cpu: 2
|
|
232
|
-
limits:
|
|
233
|
-
memory: 2147483648
|
|
234
|
-
cpu: 2`));
|
|
235
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
236
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
237
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=1843');
|
|
238
|
-
});
|
|
239
|
-
it('has memory and cpu limits and requests when set on execution', () => {
|
|
240
|
-
execution.cpu = 1;
|
|
241
|
-
execution.memory = 2147483648;
|
|
242
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
243
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
244
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
245
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
246
|
-
requests:
|
|
247
|
-
memory: 2147483648
|
|
248
|
-
cpu: 1
|
|
249
|
-
limits:
|
|
250
|
-
memory: 2147483648
|
|
251
|
-
cpu: 1`));
|
|
252
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
253
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
254
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=1843');
|
|
255
|
-
});
|
|
256
|
-
it('has separate memory and cpu limits and requests when set on execution', () => {
|
|
257
|
-
execution.resources_requests_cpu = 1;
|
|
258
|
-
execution.resources_limits_cpu = 2;
|
|
259
|
-
execution.resources_requests_memory = 2147483648;
|
|
260
|
-
execution.resources_limits_memory = 3147483648;
|
|
261
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
262
|
-
expect(kr.resource.metadata.labels['teraslice.terascope.io/exId'])
|
|
263
|
-
.toEqual('e76a0278-d9bc-4d78-bf14-431bcd97528c');
|
|
264
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
265
|
-
requests:
|
|
266
|
-
memory: 2147483648
|
|
267
|
-
cpu: 1
|
|
268
|
-
limits:
|
|
269
|
-
memory: 3147483648
|
|
270
|
-
cpu: 2`));
|
|
271
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
272
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
273
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=2702');
|
|
274
|
-
});
|
|
275
|
-
it('has memory limits and requests when set on execution', () => {
|
|
276
|
-
execution.memory = 2147483648;
|
|
277
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
278
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
279
|
-
requests:
|
|
280
|
-
memory: 2147483648
|
|
281
|
-
limits:
|
|
282
|
-
memory: 2147483648`));
|
|
283
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
284
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
285
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=1843');
|
|
286
|
-
});
|
|
287
|
-
it('has cpu limits and requests when set on execution', () => {
|
|
288
|
-
execution.cpu = 1;
|
|
289
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
290
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
291
|
-
requests:
|
|
292
|
-
cpu: 1
|
|
293
|
-
limits:
|
|
294
|
-
cpu: 1`));
|
|
295
|
-
});
|
|
296
|
-
it('has scratch volume when ephemeral_storage is set true on execution', () => {
|
|
297
|
-
execution.ephemeral_storage = true;
|
|
298
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
299
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts)
|
|
300
|
-
.toEqual([
|
|
301
|
-
{ mountPath: '/app/config', name: 'config' },
|
|
302
|
-
{ name: 'ephemeral-volume', mountPath: '/ephemeral0' }
|
|
303
|
-
]);
|
|
304
|
-
});
|
|
305
|
-
it('does not have scratch volume when ephemeral_storage is set false on execution', () => {
|
|
306
|
-
execution.ephemeral_storage = false;
|
|
307
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
308
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts)
|
|
309
|
-
.toEqual([{ mountPath: '/app/config', name: 'config' }]);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
describe('worker deployments with targets', () => {
|
|
313
|
-
it('does not have affinity or toleration properties when targets equals [].', () => {
|
|
314
|
-
execution.targets = [];
|
|
315
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
316
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('affinity');
|
|
317
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('toleration');
|
|
318
|
-
});
|
|
319
|
-
it('has valid resource object with affinity when execution has one target without constraint', () => {
|
|
320
|
-
execution.targets = [
|
|
321
|
-
{ key: 'zone', value: 'west' }
|
|
322
|
-
];
|
|
323
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
324
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
325
|
-
nodeAffinity:
|
|
326
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
327
|
-
nodeSelectorTerms:
|
|
328
|
-
- matchExpressions:
|
|
329
|
-
- key: zone
|
|
330
|
-
operator: In
|
|
331
|
-
values:
|
|
332
|
-
- west`));
|
|
333
|
-
});
|
|
334
|
-
it('has valid resource object with correct affinities when execution has one target and kubernetes_worker_antiaffinity is set', () => {
|
|
335
|
-
execution.targets = [
|
|
336
|
-
{ key: 'zone', value: 'west' }
|
|
337
|
-
];
|
|
338
|
-
terasliceConfig.kubernetes_worker_antiaffinity = true;
|
|
339
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
340
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
341
|
-
nodeAffinity:
|
|
342
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
343
|
-
nodeSelectorTerms:
|
|
344
|
-
- matchExpressions:
|
|
345
|
-
- key: zone
|
|
346
|
-
operator: In
|
|
347
|
-
values:
|
|
348
|
-
- west
|
|
349
|
-
podAntiAffinity:
|
|
350
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
351
|
-
- weight: 1
|
|
352
|
-
podAffinityTerm:
|
|
353
|
-
labelSelector:
|
|
354
|
-
matchExpressions:
|
|
355
|
-
- key: app.kubernetes.io/name
|
|
356
|
-
operator: In
|
|
357
|
-
values:
|
|
358
|
-
- teraslice
|
|
359
|
-
- key: app.kubernetes.io/instance
|
|
360
|
-
operator: In
|
|
361
|
-
values:
|
|
362
|
-
- ts-dev1
|
|
363
|
-
topologyKey: kubernetes.io/hostname`));
|
|
364
|
-
});
|
|
365
|
-
it('has valid resource object with affinity when execution has one required target', () => {
|
|
366
|
-
execution.targets = [
|
|
367
|
-
{ key: 'zone', value: 'west', constraint: 'required' }
|
|
368
|
-
];
|
|
369
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
370
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
371
|
-
nodeAffinity:
|
|
372
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
373
|
-
nodeSelectorTerms:
|
|
374
|
-
- matchExpressions:
|
|
375
|
-
- key: zone
|
|
376
|
-
operator: In
|
|
377
|
-
values:
|
|
378
|
-
- west`));
|
|
379
|
-
});
|
|
380
|
-
it('has valid resource object with affinity when execution has two required targets', () => {
|
|
381
|
-
execution.targets = [
|
|
382
|
-
{ key: 'zone', value: 'west', constraint: 'required' },
|
|
383
|
-
{ key: 'region', value: '42', constraint: 'required' }
|
|
384
|
-
];
|
|
385
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
386
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
387
|
-
nodeAffinity:
|
|
388
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
389
|
-
nodeSelectorTerms:
|
|
390
|
-
- matchExpressions:
|
|
391
|
-
- key: zone
|
|
392
|
-
operator: In
|
|
393
|
-
values:
|
|
394
|
-
- west
|
|
395
|
-
- key: region
|
|
396
|
-
operator: In
|
|
397
|
-
values:
|
|
398
|
-
- "42"`));
|
|
399
|
-
});
|
|
400
|
-
it('has valid resource object with affinity when execution has one preferred target', () => {
|
|
401
|
-
execution.targets = [
|
|
402
|
-
{ key: 'zone', value: 'west', constraint: 'preferred' }
|
|
403
|
-
];
|
|
404
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
405
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
406
|
-
nodeAffinity:
|
|
407
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
408
|
-
- weight: 1
|
|
409
|
-
preference:
|
|
410
|
-
matchExpressions:
|
|
411
|
-
- key: zone
|
|
412
|
-
operator: In
|
|
413
|
-
values:
|
|
414
|
-
- west`));
|
|
415
|
-
});
|
|
416
|
-
it('has valid resource object with affinity when execution has two preferred targets', () => {
|
|
417
|
-
execution.targets = [
|
|
418
|
-
{ key: 'zone', value: 'west', constraint: 'preferred' },
|
|
419
|
-
{ key: 'region', value: 'texas', constraint: 'preferred' }
|
|
420
|
-
];
|
|
421
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
422
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
423
|
-
nodeAffinity:
|
|
424
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
425
|
-
- weight: 1
|
|
426
|
-
preference:
|
|
427
|
-
matchExpressions:
|
|
428
|
-
- key: zone
|
|
429
|
-
operator: In
|
|
430
|
-
values:
|
|
431
|
-
- west
|
|
432
|
-
- weight: 1
|
|
433
|
-
preference:
|
|
434
|
-
matchExpressions:
|
|
435
|
-
- key: region
|
|
436
|
-
operator: In
|
|
437
|
-
values:
|
|
438
|
-
- texas`));
|
|
439
|
-
});
|
|
440
|
-
it('has valid resource object with tolerance when execution has one accepted target', () => {
|
|
441
|
-
execution.targets = [
|
|
442
|
-
{ key: 'zone', value: 'west', constraint: 'accepted' }
|
|
443
|
-
];
|
|
444
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
445
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.tolerations));
|
|
446
|
-
expect(kr.resource.spec.template.spec.tolerations).toEqual(yaml.load(`
|
|
447
|
-
- key: zone
|
|
448
|
-
operator: Equal
|
|
449
|
-
value: west
|
|
450
|
-
effect: NoSchedule`));
|
|
451
|
-
});
|
|
452
|
-
it('has valid resource object with tolerance when execution has two accepted targets', () => {
|
|
453
|
-
execution.targets = [
|
|
454
|
-
{ key: 'zone', value: 'west', constraint: 'accepted' },
|
|
455
|
-
{ key: 'region', value: 'texas', constraint: 'accepted' }
|
|
456
|
-
];
|
|
457
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
458
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.tolerations));
|
|
459
|
-
expect(kr.resource.spec.template.spec.tolerations).toEqual(yaml.load(`
|
|
460
|
-
- key: zone
|
|
461
|
-
operator: Equal
|
|
462
|
-
value: west
|
|
463
|
-
effect: NoSchedule
|
|
464
|
-
- key: region
|
|
465
|
-
operator: Equal
|
|
466
|
-
value: texas
|
|
467
|
-
effect: NoSchedule`));
|
|
468
|
-
});
|
|
469
|
-
it('has valid resource object with required and preferred affinity when execution has both', () => {
|
|
470
|
-
execution.targets = [
|
|
471
|
-
{ key: 'zone', value: 'west', constraint: 'required' },
|
|
472
|
-
{ key: 'region', value: 'texas', constraint: 'preferred' }
|
|
473
|
-
];
|
|
474
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
475
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.tolerations));
|
|
476
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
477
|
-
nodeAffinity:
|
|
478
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
479
|
-
nodeSelectorTerms:
|
|
480
|
-
- matchExpressions:
|
|
481
|
-
- key: zone
|
|
482
|
-
operator: In
|
|
483
|
-
values:
|
|
484
|
-
- west
|
|
485
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
486
|
-
- weight: 1
|
|
487
|
-
preference:
|
|
488
|
-
matchExpressions:
|
|
489
|
-
- key: region
|
|
490
|
-
operator: In
|
|
491
|
-
values:
|
|
492
|
-
- texas`));
|
|
493
|
-
});
|
|
494
|
-
it('has valid resource object with affinity and tolerations when execution has two of each', () => {
|
|
495
|
-
execution.targets = [
|
|
496
|
-
{ key: 'zone', value: 'west', constraint: 'required' },
|
|
497
|
-
{ key: 'region', value: '42', constraint: 'required' },
|
|
498
|
-
{ key: 'zone', value: 'west', constraint: 'preferred' },
|
|
499
|
-
{ key: 'region', value: 'texas', constraint: 'preferred' },
|
|
500
|
-
{ key: 'zone', value: 'west', constraint: 'accepted' },
|
|
501
|
-
{ key: 'region', value: 'texas', constraint: 'accepted' }
|
|
502
|
-
];
|
|
503
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
504
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
505
|
-
nodeAffinity:
|
|
506
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
507
|
-
nodeSelectorTerms:
|
|
508
|
-
- matchExpressions:
|
|
509
|
-
- key: zone
|
|
510
|
-
operator: In
|
|
511
|
-
values:
|
|
512
|
-
- west
|
|
513
|
-
- key: region
|
|
514
|
-
operator: In
|
|
515
|
-
values:
|
|
516
|
-
- "42"
|
|
517
|
-
preferredDuringSchedulingIgnoredDuringExecution:
|
|
518
|
-
- weight: 1
|
|
519
|
-
preference:
|
|
520
|
-
matchExpressions:
|
|
521
|
-
- key: zone
|
|
522
|
-
operator: In
|
|
523
|
-
values:
|
|
524
|
-
- west
|
|
525
|
-
- weight: 1
|
|
526
|
-
preference:
|
|
527
|
-
matchExpressions:
|
|
528
|
-
- key: region
|
|
529
|
-
operator: In
|
|
530
|
-
values:
|
|
531
|
-
- texas`));
|
|
532
|
-
expect(kr.resource.spec.template.spec.tolerations).toEqual(yaml.load(`
|
|
533
|
-
- key: zone
|
|
534
|
-
operator: Equal
|
|
535
|
-
value: west
|
|
536
|
-
effect: NoSchedule
|
|
537
|
-
- key: region
|
|
538
|
-
operator: Equal
|
|
539
|
-
value: texas
|
|
540
|
-
effect: NoSchedule`));
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
describe('worker deployments with job labels', () => {
|
|
544
|
-
it('generates k8s resources with labels', () => {
|
|
545
|
-
execution.labels = {
|
|
546
|
-
key1: 'value1',
|
|
547
|
-
key2: 'value2'
|
|
548
|
-
};
|
|
549
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
550
|
-
// console.log(yaml.dump(kr.resource));
|
|
551
|
-
expect(kr.resource.metadata.labels['job.teraslice.terascope.io/key1']).toEqual('value1');
|
|
552
|
-
expect(kr.resource.metadata.labels['job.teraslice.terascope.io/key2']).toEqual('value2');
|
|
553
|
-
});
|
|
554
|
-
it('generates valid k8s resources with keys containing forbidden characters', () => {
|
|
555
|
-
execution.labels = {
|
|
556
|
-
'key 1': 'value1',
|
|
557
|
-
'key2%': 'value2',
|
|
558
|
-
abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij1234: 'value3',
|
|
559
|
-
};
|
|
560
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
561
|
-
// console.log(yaml.dump(kr.resource));
|
|
562
|
-
expect(kr.resource.metadata.labels['job.teraslice.terascope.io/key-1']).toEqual('value1');
|
|
563
|
-
expect(kr.resource.metadata.labels['job.teraslice.terascope.io/key2-']).toEqual('value2');
|
|
564
|
-
expect(kr.resource.metadata.labels['job.teraslice.terascope.io/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij123']).toEqual('value3');
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
describe('teraslice job with one valid external_ports set', () => {
|
|
568
|
-
it('generates k8s worker deployment with containerPort on container', () => {
|
|
569
|
-
execution.external_ports = [9090];
|
|
570
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
571
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.containers[0].ports));
|
|
572
|
-
expect(kr.resource.spec.template.spec.containers[0].ports)
|
|
573
|
-
.toEqual([
|
|
574
|
-
{ containerPort: 45680 },
|
|
575
|
-
{ containerPort: 9090 }
|
|
576
|
-
]);
|
|
577
|
-
});
|
|
578
|
-
it('generates k8s execution controller job with containerPort on container', () => {
|
|
579
|
-
execution.external_ports = [9090];
|
|
580
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
581
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.containers[0].ports));
|
|
582
|
-
expect(kr.resource.spec.template.spec.containers[0].ports)
|
|
583
|
-
.toEqual([
|
|
584
|
-
{ containerPort: 45680 },
|
|
585
|
-
{ containerPort: 9090 }
|
|
586
|
-
]);
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
describe('teraslice job with two valid external_ports set', () => {
|
|
590
|
-
it('generates k8s worker deployment with containerPort on container', () => {
|
|
591
|
-
execution.external_ports = [
|
|
592
|
-
9090,
|
|
593
|
-
{ name: 'metrics', port: 9091 }
|
|
594
|
-
];
|
|
595
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
596
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.containers[0].ports));
|
|
597
|
-
expect(kr.resource.spec.template.spec.containers[0].ports)
|
|
598
|
-
.toEqual([
|
|
599
|
-
{ containerPort: 45680 },
|
|
600
|
-
{ containerPort: 9090 },
|
|
601
|
-
{ name: 'metrics', containerPort: 9091 }
|
|
602
|
-
]);
|
|
603
|
-
});
|
|
604
|
-
it('generates k8s execution controller job with containerPort on container', () => {
|
|
605
|
-
execution.external_ports = [9090, 9091];
|
|
606
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
607
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.containers[0].ports));
|
|
608
|
-
expect(kr.resource.spec.template.spec.containers[0].ports)
|
|
609
|
-
.toEqual([
|
|
610
|
-
{ containerPort: 45680 },
|
|
611
|
-
{ containerPort: 9090 },
|
|
612
|
-
{ containerPort: 9091 }
|
|
613
|
-
]);
|
|
614
|
-
});
|
|
615
|
-
});
|
|
616
|
-
describe('execution_controller job', () => {
|
|
617
|
-
it('has valid resource object.', () => {
|
|
618
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
619
|
-
expect(kr.resource.kind).toBe('Job');
|
|
620
|
-
expect(kr.resource.metadata.name).toBe('ts-exc-example-data-generator-job-7ba9afb0-417a');
|
|
621
|
-
// The following properties should be absent in the default case
|
|
622
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('affinity');
|
|
623
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('imagePullSecrets');
|
|
624
|
-
expect(kr.resource.spec.template.spec).not.toHaveProperty('priorityClassName');
|
|
625
|
-
// Configmaps should be mounted on all workers
|
|
626
|
-
expect(kr.resource.spec.template.spec.volumes[0]).toEqual(yaml.load(`
|
|
627
|
-
name: config
|
|
628
|
-
configMap:
|
|
629
|
-
name: ts-dev1-worker
|
|
630
|
-
items:
|
|
631
|
-
- key: teraslice.yaml
|
|
632
|
-
path: teraslice.yaml`));
|
|
633
|
-
expect(kr.resource.spec.template.spec.containers[0].volumeMounts[0])
|
|
634
|
-
.toEqual(yaml.load(`
|
|
635
|
-
mountPath: /app/config
|
|
636
|
-
name: config`));
|
|
637
|
-
});
|
|
638
|
-
it('has memory and cpu limits and requests when set on terasliceConfig', () => {
|
|
639
|
-
terasliceConfig.cpu_execution_controller = 1;
|
|
640
|
-
terasliceConfig.memory_execution_controller = 2147483648;
|
|
641
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
642
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
643
|
-
requests:
|
|
644
|
-
memory: 2147483648
|
|
645
|
-
cpu: 1
|
|
646
|
-
limits:
|
|
647
|
-
memory: 2147483648
|
|
648
|
-
cpu: 1`));
|
|
649
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
650
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
651
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=1843');
|
|
652
|
-
});
|
|
653
|
-
it('execution resources override terasliceConfig resources', () => {
|
|
654
|
-
execution.cpu_execution_controller = 2;
|
|
655
|
-
execution.memory_execution_controller = 1073741824;
|
|
656
|
-
terasliceConfig.cpu_execution_controller = 1;
|
|
657
|
-
terasliceConfig.memory_execution_controller = 2147483648;
|
|
658
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
659
|
-
expect(kr.resource.spec.template.spec.containers[0].resources).toEqual(yaml.load(`
|
|
660
|
-
requests:
|
|
661
|
-
memory: 1073741824
|
|
662
|
-
cpu: 2
|
|
663
|
-
limits:
|
|
664
|
-
memory: 1073741824
|
|
665
|
-
cpu: 2`));
|
|
666
|
-
const envArray = kr.resource.spec.template.spec.containers[0].env;
|
|
667
|
-
const nodeOptions = envArray.find((i) => i.name === 'NODE_OPTIONS');
|
|
668
|
-
expect(nodeOptions?.value).toEqual('--max-old-space-size=922');
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
describe('worker deployment with different combinations of job names', () => {
|
|
672
|
-
test.each([
|
|
673
|
-
['aa', 'ts-wkr-aa-7ba9afb0-417a'],
|
|
674
|
-
['00', 'ts-wkr-a0-7ba9afb0-417a'],
|
|
675
|
-
['a', 'ts-wkr-a-7ba9afb0-417a'],
|
|
676
|
-
['0', 'ts-wkr-a-7ba9afb0-417a'],
|
|
677
|
-
['-job-', 'ts-wkr-ajob0-7ba9afb0-417a'],
|
|
678
|
-
['-JOB-', 'ts-wkr-ajob0-7ba9afb0-417a'],
|
|
679
|
-
['teraslice-JOB-name', 'ts-wkr-teraslice-job-name-7ba9afb0-417a']
|
|
680
|
-
])('when Job Name is %s the k8s worker name is: %s', (jobName, k8sName) => {
|
|
681
|
-
execution.name = jobName;
|
|
682
|
-
const kr = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
683
|
-
expect(kr.resource.metadata.name).toBe(k8sName);
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
describe('teraslice config with execution_controller_targets set', () => {
|
|
687
|
-
it('generates execution controller job with toleration and affinity', () => {
|
|
688
|
-
terasliceConfig.execution_controller_targets = [
|
|
689
|
-
{ key: 'key1', value: 'value1' },
|
|
690
|
-
{ key: 'key2', value: 'value2' }
|
|
691
|
-
];
|
|
692
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
693
|
-
expect(kr.resource.kind).toBe('Job');
|
|
694
|
-
expect(kr.resource.metadata.name).toBe('ts-exc-example-data-generator-job-7ba9afb0-417a');
|
|
695
|
-
expect(kr.resource.spec.template.spec).toHaveProperty('affinity');
|
|
696
|
-
expect(kr.resource.spec.template.spec).toHaveProperty('tolerations');
|
|
697
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
698
|
-
nodeAffinity:
|
|
699
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
700
|
-
nodeSelectorTerms:
|
|
701
|
-
- matchExpressions:
|
|
702
|
-
- key: key1
|
|
703
|
-
operator: In
|
|
704
|
-
values:
|
|
705
|
-
- value1
|
|
706
|
-
- key: key2
|
|
707
|
-
operator: In
|
|
708
|
-
values:
|
|
709
|
-
- value2`));
|
|
710
|
-
expect(kr.resource.spec.template.spec.tolerations).toEqual(yaml.load(`
|
|
711
|
-
- key: key1
|
|
712
|
-
operator: Equal
|
|
713
|
-
value: value1
|
|
714
|
-
effect: NoSchedule
|
|
715
|
-
- key: key2
|
|
716
|
-
operator: Equal
|
|
717
|
-
value: value2
|
|
718
|
-
effect: NoSchedule`));
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
describe('teraslice config with execution_controller_targets and job targets set', () => {
|
|
722
|
-
it('generates execution controller job with toleration and affinity and targets', () => {
|
|
723
|
-
terasliceConfig.execution_controller_targets = [
|
|
724
|
-
{ key: 'key1', value: 'value1' },
|
|
725
|
-
];
|
|
726
|
-
execution.targets = [
|
|
727
|
-
{ key: 'zone', value: 'west' },
|
|
728
|
-
{ key: 'region', value: 'texas', constraint: 'accepted' }
|
|
729
|
-
];
|
|
730
|
-
const kr = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
731
|
-
expect(kr.resource.kind).toBe('Job');
|
|
732
|
-
expect(kr.resource.metadata.name).toBe('ts-exc-example-data-generator-job-7ba9afb0-417a');
|
|
733
|
-
expect(kr.resource.spec.template.spec).toHaveProperty('affinity');
|
|
734
|
-
expect(kr.resource.spec.template.spec).toHaveProperty('tolerations');
|
|
735
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.affinity));
|
|
736
|
-
expect(kr.resource.spec.template.spec.affinity).toEqual(yaml.load(`
|
|
737
|
-
nodeAffinity:
|
|
738
|
-
requiredDuringSchedulingIgnoredDuringExecution:
|
|
739
|
-
nodeSelectorTerms:
|
|
740
|
-
- matchExpressions:
|
|
741
|
-
- key: zone
|
|
742
|
-
operator: In
|
|
743
|
-
values:
|
|
744
|
-
- west
|
|
745
|
-
- key: key1
|
|
746
|
-
operator: In
|
|
747
|
-
values:
|
|
748
|
-
- value1`));
|
|
749
|
-
// console.log(yaml.dump(kr.resource.spec.template.spec.tolerations));
|
|
750
|
-
expect(kr.resource.spec.template.spec.tolerations).toEqual(yaml.load(`
|
|
751
|
-
- key: region
|
|
752
|
-
operator: Equal
|
|
753
|
-
value: texas
|
|
754
|
-
effect: NoSchedule
|
|
755
|
-
- key: key1
|
|
756
|
-
operator: Equal
|
|
757
|
-
value: value1
|
|
758
|
-
effect: NoSchedule`));
|
|
759
|
-
});
|
|
760
|
-
});
|
|
761
|
-
describe('teraslice config with kubernetes_priority_class_name set', () => {
|
|
762
|
-
it('generates execution controller job with priorityClassName in pod spec', () => {
|
|
763
|
-
execution.stateful = true;
|
|
764
|
-
terasliceConfig.kubernetes_priority_class_name = 'testPriorityClass';
|
|
765
|
-
const krWorker = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
766
|
-
expect(krWorker.resource.kind).toBe('Deployment');
|
|
767
|
-
expect(krWorker.resource.spec.template.spec).toHaveProperty('priorityClassName');
|
|
768
|
-
expect(krWorker.resource.spec.template.spec.priorityClassName).toEqual('testPriorityClass');
|
|
769
|
-
expect(krWorker.resource.spec.template.metadata.labels['job-property.teraslice.terascope.io/stateful']).toEqual('true');
|
|
770
|
-
const krExporter = new K8sResource('jobs', 'execution_controller', terasliceConfig, execution, logger);
|
|
771
|
-
expect(krExporter.resource.kind).toBe('Job');
|
|
772
|
-
expect(krExporter.resource.metadata.name).toBe('ts-exc-example-data-generator-job-7ba9afb0-417a');
|
|
773
|
-
expect(krExporter.resource.spec.template.spec).toHaveProperty('priorityClassName');
|
|
774
|
-
expect(krExporter.resource.spec.template.spec.priorityClassName).toEqual('testPriorityClass');
|
|
775
|
-
expect(krExporter.resource.spec.template.metadata.labels['job-property.teraslice.terascope.io/stateful']).toEqual('true');
|
|
776
|
-
});
|
|
777
|
-
});
|
|
778
|
-
describe('teraslice config with kubernetes_overrides_enabled set false', () => {
|
|
779
|
-
it('generates pods without overlay in pod .spec', () => {
|
|
780
|
-
execution.pod_spec_override = { initContainers: [] };
|
|
781
|
-
terasliceConfig.kubernetes_overrides_enabled = false;
|
|
782
|
-
const krWorker = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
783
|
-
expect(krWorker.resource.spec.template.spec).not.toHaveProperty('initContainers');
|
|
784
|
-
});
|
|
785
|
-
});
|
|
786
|
-
describe('teraslice config with kubernetes_overrides_enabled set true', () => {
|
|
787
|
-
it('generates pods with overlay in pod .spec', () => {
|
|
788
|
-
execution.pod_spec_override = { initContainers: [] };
|
|
789
|
-
terasliceConfig.kubernetes_overrides_enabled = true;
|
|
790
|
-
const krWorker = new K8sResource('deployments', 'worker', terasliceConfig, execution, logger);
|
|
791
|
-
expect(krWorker.resource.spec.template.spec).toHaveProperty('initContainers');
|
|
792
|
-
});
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
//# sourceMappingURL=k8sResource-spec.js.map
|