Skip to content

Commit dd0c958

Browse files
committed
Improve the Swarm template
+ Improve the firewall configuration + Give better names to the rules + Open internal UDP traffic + Simplify the http rule configuration + Automatically create subnetworks + Support Different machine types for workers/manager + Support Preemptible workers Signed-off-by: David Gageot <[email protected]>
1 parent 2605218 commit dd0c958

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

gcp/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ make revoke
2929
+ Monitoring
3030
+ Configure project
3131
+ Multiple managers
32-
+ Different machine types for workers and managers
3332
+ SSH keys
3433
+ Additional swarm properties
3534
+ Publish the templates
@@ -40,4 +39,3 @@ make revoke
4039
+ Have each worker increment a counter to be able to wait from outside
4140
+ Manager pool
4241
+ Diagnostics
43-
+ Option to use preemptible VMs

gcp/configuration/templates/firewall.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,39 @@ def GenerateConfig(context):
66
network = '$(ref.' + context.properties['network'] + '.selfLink)'
77

88
resources = [{
9-
'name': 'ssh',
9+
'name': 'allow-ssh',
1010
'type': 'compute.v1.firewall',
1111
'properties': {
1212
'network': network,
1313
'sourceRanges': ['0.0.0.0/0'],
1414
'allowed': [{
15-
'IPProtocol': 'TCP',
16-
'ports': [22]
15+
'IPProtocol': 'tcp',
16+
'ports': ['22']
1717
}]
1818
}
1919
},{
20-
'name': 'http',
20+
'name': 'allow-http',
2121
'type': 'compute.v1.firewall',
2222
'properties': {
2323
'network': network,
2424
'sourceRanges': ['0.0.0.0/0'],
2525
'allowed': [{
26-
'IPProtocol': 'TCP',
27-
'ports': [80]
28-
},{
29-
'IPProtocol': 'TCP',
30-
'ports': [443]
26+
'IPProtocol': 'tcp',
27+
'ports': ['80', '443']
3128
}]
3229
}
3330
},{
34-
'name': 'internal',
31+
'name': 'allow-internal',
3532
'type': 'compute.v1.firewall',
3633
'properties': {
3734
'network': network,
38-
'sourceTags': ['swarm'],
35+
'sourceRanges': ['10.128.0.0/9'],
3936
'allowed': [{
40-
'IPProtocol': 'TCP'
37+
'IPProtocol': 'tcp',
38+
"ports": ['0-65535']
39+
},{
40+
'IPProtocol': 'udp',
41+
"ports": ['0-65535']
4142
}]
4243
}
4344
}]

gcp/configuration/templates/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def GenerateConfig(context):
77
'name': context.env['name'],
88
'type': 'compute.v1.network',
99
'properties': {
10-
'IPv4Range': '10.0.0.1/16'
10+
'autoCreateSubnetworks': True
1111
}
1212
}]
1313
return {'resources': resources}

gcp/configuration/templates/swarm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
def GenerateConfig(context):
66
zone = context.properties['zone']
7-
machineType = context.properties['machineType']
7+
managerMachineType = context.properties['managerMachineType']
8+
workerMachineType = context.properties['workerMachineType']
9+
preemptible = context.properties['preemptible']
810
size = context.properties['size']
911

1012
resources = [{
@@ -15,7 +17,7 @@ def GenerateConfig(context):
1517
'type': 'templates/manager.py',
1618
'properties': {
1719
'zone': zone,
18-
'machineType': machineType,
20+
'machineType': managerMachineType,
1921
'image': '$(ref.docker.selfLink)',
2022
'network': 'swarm-network'
2123
}
@@ -24,7 +26,8 @@ def GenerateConfig(context):
2426
'type': 'templates/worker.py',
2527
'properties': {
2628
'zone': zone,
27-
'machineType': machineType,
29+
'machineType': workerMachineType,
30+
'preemptible': preemptible,
2831
'image': '$(ref.docker.selfLink)',
2932
'network': 'swarm-network',
3033
'managerIP': '$(ref.manager.internalIP)'

gcp/configuration/templates/swarm.py.schema

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ properties:
1616
default: europe-west1-d
1717
description: Zone
1818

19-
machineType:
19+
managerMachineType:
20+
type: string
21+
default: g1-small
22+
description: Manager machine type
23+
24+
workerMachineType:
2025
type: string
2126
default: g1-small
2227
description: Worker machine type
28+
29+
preemptible:
30+
type: boolean
31+
default: False
32+
description: Are workers preemptible?

gcp/configuration/templates/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def GenerateConfig(context):
88
project = context.env['project']
99
zone = context.properties['zone']
1010
machineType = context.properties['machineType']
11+
preemptible = context.properties['preemptible']
1112
image = context.properties['image']
1213
managerIP = context.properties['managerIP']
1314
network = '$(ref.' + context.properties['network'] + '.selfLink)'
@@ -65,7 +66,7 @@ def GenerateConfig(context):
6566
}]
6667
},
6768
'scheduling': {
68-
'preemptible': False,
69+
'preemptible': preemptible,
6970
'onHostMaintenance': 'TERMINATE',
7071
'automaticRestart': False
7172
},

0 commit comments

Comments
 (0)