Skip to content

Commit 7ae09ac

Browse files
authored
ref(config): Adding auto-excluded control region (#79)
* ref(config): Adding auto-excluded control region * Adding comment, touch ups * Bumping version
1 parent 6ddc943 commit 7ae09ac

File tree

9 files changed

+812
-5
lines changed

9 files changed

+812
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You'll need [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler
1616

1717
```sh
1818
jb init
19-
jb install https://github.com/getsentry/gocd-jsonnet.git/libs@v2.12.0
19+
jb install https://github.com/getsentry/gocd-jsonnet.git/libs@v2.14.0
2020
```
2121

2222
## Build

libs/getsentry.libsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
's4s',
99
'de',
1010
'us',
11+
// 'control' is excluded by default and must be explicitly included
12+
'control',
1113
'customer-1',
1214
'customer-2',
1315
'customer-4',

libs/pipedream.libsonnet

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,28 @@ local pipeline_to_array(pipeline) =
241241
{
242242
// render will generate the trigger pipeline and all the region pipelines.
243243
render(pipedream_config, pipeline_fn)::
244-
// Filter out any regions that are listed in the `exclude_regions`
245-
// attribute.
244+
// Regions that are excluded by default and must be explicitly included
245+
local default_excluded_regions = ['control'];
246+
247+
local is_excluded_region = function(region, config)
248+
std.objectHas(config, 'exclude_regions') && std.length(std.find(region, config.exclude_regions)) > 0;
249+
250+
local is_included_region = function(region, config)
251+
std.objectHas(config, 'include_regions') && std.length(std.find(region, config.include_regions)) > 0;
252+
253+
local is_default_excluded_region = function(region)
254+
std.length(std.find(region, default_excluded_regions)) > 0;
255+
256+
local should_include_region = function(region, config)
257+
!is_excluded_region(region, config) && (!is_default_excluded_region(region) || is_included_region(region, config));
258+
259+
// Filter out any regions that are listed in the `exclude_regions` attribute.
246260
local regions_to_render = std.filter(
247-
function(r) !std.objectHas(pipedream_config, 'exclude_regions') || std.length(std.find(r, pipedream_config.exclude_regions)) == 0,
261+
function(region) should_include_region(region, pipedream_config),
248262
getsentry.prod_regions,
249263
);
250264
local test_regions_to_render = std.filter(
251-
function(r) !std.objectHas(pipedream_config, 'exclude_regions') || std.length(std.find(r, pipedream_config.exclude_regions)) == 0,
265+
function(region) should_include_region(region, pipedream_config),
252266
getsentry.test_regions,
253267
);
254268

test/pipedream.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,180 @@ test("ensure exclude regions removes regions with trigger pipeline", async (t) =
207207
);
208208
});
209209

210+
test("ensure include regions adds regions without trigger pipeline", async (t) => {
211+
const got = await render_fixture("pipedream/include-regions.jsonnet", false);
212+
213+
t.deepEqual(Object.keys(got.pipelines).sort(), [
214+
"deploy-example-control",
215+
"deploy-example-customer-1",
216+
"deploy-example-customer-2",
217+
"deploy-example-customer-4",
218+
"deploy-example-customer-7",
219+
"deploy-example-de",
220+
"rollback-example",
221+
]);
222+
223+
// Ensure de has just the repo material
224+
const de = got.pipelines["deploy-example-de"];
225+
t.deepEqual(de.materials, {
226+
example_repo: {
227+
branch: "master",
228+
destination: "example",
229+
git: "git@github.com:getsentry/example.git",
230+
shallow_clone: true,
231+
},
232+
});
233+
234+
// Ensure control is included
235+
const control = got.pipelines["deploy-example-control"];
236+
t.deepEqual(control.materials, {
237+
"deploy-example-de-pipeline-complete": {
238+
pipeline: "deploy-example-de",
239+
stage: "pipeline-complete",
240+
},
241+
example_repo: {
242+
branch: "master",
243+
destination: "example",
244+
git: "git@github.com:getsentry/example.git",
245+
shallow_clone: true,
246+
},
247+
});
248+
249+
// Ensure customer-1 depends on control
250+
const c1 = got.pipelines["deploy-example-customer-1"];
251+
t.deepEqual(c1.materials, {
252+
"deploy-example-control-pipeline-complete": {
253+
pipeline: "deploy-example-control",
254+
stage: "pipeline-complete",
255+
},
256+
example_repo: {
257+
branch: "master",
258+
destination: "example",
259+
git: "git@github.com:getsentry/example.git",
260+
shallow_clone: true,
261+
},
262+
});
263+
264+
// Ensure customer-2 has pipeline material too
265+
const c2 = got.pipelines["deploy-example-customer-2"];
266+
t.deepEqual(c2.materials, {
267+
"deploy-example-customer-1-pipeline-complete": {
268+
pipeline: "deploy-example-customer-1",
269+
stage: "pipeline-complete",
270+
},
271+
example_repo: {
272+
branch: "master",
273+
destination: "example",
274+
git: "git@github.com:getsentry/example.git",
275+
shallow_clone: true,
276+
},
277+
});
278+
279+
// Ensure rollback has the expected rollback pipelines
280+
const r = got.pipelines["rollback-example"];
281+
const allPipelines = r.environment_variables["ALL_PIPELINE_FLAGS"];
282+
const regionPipelines = r.environment_variables["REGION_PIPELINE_FLAGS"];
283+
t.deepEqual(
284+
allPipelines,
285+
"--pipeline=deploy-example-de --pipeline=deploy-example-control --pipeline=deploy-example-customer-1 --pipeline=deploy-example-customer-2 --pipeline=deploy-example-customer-4 --pipeline=deploy-example-customer-7",
286+
);
287+
t.deepEqual(
288+
regionPipelines,
289+
"--pipeline=deploy-example-de --pipeline=deploy-example-control --pipeline=deploy-example-customer-1 --pipeline=deploy-example-customer-2 --pipeline=deploy-example-customer-4 --pipeline=deploy-example-customer-7",
290+
);
291+
});
292+
293+
test("ensure include regions adds regions with trigger pipeline", async (t) => {
294+
const got = await render_fixture(
295+
"pipedream/include-regions-no-autodeploy.jsonnet",
296+
false,
297+
);
298+
299+
t.deepEqual(Object.keys(got.pipelines).sort(), [
300+
"deploy-example",
301+
"deploy-example-control",
302+
"deploy-example-customer-1",
303+
"deploy-example-customer-2",
304+
"deploy-example-customer-4",
305+
"deploy-example-customer-7",
306+
"deploy-example-de",
307+
"rollback-example",
308+
]);
309+
310+
// Ensure de has just the repo material
311+
const de = got.pipelines["deploy-example-de"];
312+
t.deepEqual(de.materials, {
313+
"deploy-example-pipeline-complete": {
314+
pipeline: "deploy-example",
315+
stage: "pipeline-complete",
316+
},
317+
example_repo: {
318+
branch: "master",
319+
destination: "example",
320+
git: "git@github.com:getsentry/example.git",
321+
shallow_clone: true,
322+
},
323+
});
324+
325+
// Ensure control is included
326+
const control = got.pipelines["deploy-example-control"];
327+
t.deepEqual(control.materials, {
328+
"deploy-example-de-pipeline-complete": {
329+
pipeline: "deploy-example-de",
330+
stage: "pipeline-complete",
331+
},
332+
example_repo: {
333+
branch: "master",
334+
destination: "example",
335+
git: "git@github.com:getsentry/example.git",
336+
shallow_clone: true,
337+
},
338+
});
339+
340+
// Ensure customer-1 depends on control
341+
const c1 = got.pipelines["deploy-example-customer-1"];
342+
t.deepEqual(c1.materials, {
343+
"deploy-example-control-pipeline-complete": {
344+
pipeline: "deploy-example-control",
345+
stage: "pipeline-complete",
346+
},
347+
example_repo: {
348+
branch: "master",
349+
destination: "example",
350+
git: "git@github.com:getsentry/example.git",
351+
shallow_clone: true,
352+
},
353+
});
354+
355+
// Ensure customer-2 has pipeline material too
356+
const c2 = got.pipelines["deploy-example-customer-2"];
357+
t.deepEqual(c2.materials, {
358+
"deploy-example-customer-1-pipeline-complete": {
359+
pipeline: "deploy-example-customer-1",
360+
stage: "pipeline-complete",
361+
},
362+
example_repo: {
363+
branch: "master",
364+
destination: "example",
365+
git: "git@github.com:getsentry/example.git",
366+
shallow_clone: true,
367+
},
368+
});
369+
370+
// Ensure rollback has the expected rollback pipelines
371+
const r = got.pipelines["rollback-example"];
372+
const allPipelines = r.environment_variables["ALL_PIPELINE_FLAGS"];
373+
const regionPipelines = r.environment_variables["REGION_PIPELINE_FLAGS"];
374+
t.deepEqual(
375+
allPipelines,
376+
"--pipeline=deploy-example-de --pipeline=deploy-example-control --pipeline=deploy-example-customer-1 --pipeline=deploy-example-customer-2 --pipeline=deploy-example-customer-4 --pipeline=deploy-example-customer-7 --pipeline=deploy-example",
377+
);
378+
t.deepEqual(
379+
regionPipelines,
380+
"--pipeline=deploy-example-de --pipeline=deploy-example-control --pipeline=deploy-example-customer-1 --pipeline=deploy-example-customer-2 --pipeline=deploy-example-customer-4 --pipeline=deploy-example-customer-7",
381+
);
382+
});
383+
210384
test("error for invalid final rollback stage", async (t) => {
211385
const err = t.throws(() =>
212386
get_fixture_content(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local pipedream = import '../../../../libs/pipedream.libsonnet';
2+
3+
local pipedream_config = {
4+
name: 'example',
5+
auto_deploy: false,
6+
include_regions: ['control'],
7+
exclude_regions: ['s4s', 'us'],
8+
materials: {
9+
init_repo: {
10+
git: 'git@github.com:getsentry/init.git',
11+
branch: 'master',
12+
destination: 'init',
13+
},
14+
},
15+
rollback: {
16+
material_name: 'example_repo',
17+
stage: 'example_stage',
18+
elastic_profile_id: 'example_profile',
19+
},
20+
};
21+
22+
local sample = {
23+
pipeline(region):: {
24+
region: region,
25+
materials: {
26+
example_repo: {
27+
git: 'git@github.com:getsentry/example.git',
28+
shallow_clone: true,
29+
branch: 'master',
30+
destination: 'example',
31+
},
32+
},
33+
stages: [
34+
{
35+
example_stage: {},
36+
},
37+
],
38+
},
39+
};
40+
41+
pipedream.render(pipedream_config, sample.pipeline)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local pipedream = import '../../../../libs/pipedream.libsonnet';
2+
3+
local pipedream_config = {
4+
name: 'example',
5+
include_regions: ['control'],
6+
exclude_regions: ['s4s', 'us'],
7+
materials: {
8+
init_repo: {
9+
git: 'git@github.com:getsentry/init.git',
10+
branch: 'master',
11+
destination: 'init',
12+
},
13+
},
14+
rollback: {
15+
material_name: 'example_repo',
16+
stage: 'example_stage',
17+
elastic_profile_id: 'example_profile',
18+
},
19+
};
20+
21+
local sample = {
22+
pipeline(region):: {
23+
region: region,
24+
materials: {
25+
example_repo: {
26+
git: 'git@github.com:getsentry/example.git',
27+
shallow_clone: true,
28+
branch: 'master',
29+
destination: 'example',
30+
},
31+
},
32+
stages: [
33+
{
34+
example_stage: {},
35+
},
36+
],
37+
},
38+
};
39+
40+
pipedream.render(pipedream_config, sample.pipeline)

test/testdata/goldens/getsentry/regions.jsonnet_output-files.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"s4s",
44
"de",
55
"us",
6+
"control",
67
"customer-1",
78
"customer-2",
89
"customer-4",

0 commit comments

Comments
 (0)