forked from tidepool-org/development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiltfile.gateway
More file actions
170 lines (138 loc) · 6.12 KB
/
Tiltfile.gateway
File metadata and controls
170 lines (138 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
load('./Tiltfile.global', 'getAbsoluteDir', 'getNested', 'getConfig', 'getHelmValuesFile', 'getHelmOverridesFile', 'isShutdown')
allow_k8s_contexts('kind-admin@mk')
### Config Start ###
tidepool_helm_values_file = getHelmValuesFile()
tidepool_helm_overrides_file = getHelmOverridesFile()
config = getConfig()
watch_file(tidepool_helm_values_file)
watch_file(tidepool_helm_overrides_file)
local_helm_chart_dir = './local/charts'
absolute_gloo_chart_dir = getAbsoluteDir(local_helm_chart_dir)
gloo_helm_template_cmd = 'helm template --namespace default '
local_downloads_dir = getAbsoluteDir('./local/downloads')
is_shutdown = isShutdown()
gloo_version = '1.4.4'
gloo_archive_name = 'gloo-{}.tgz'.format(gloo_version)
gloo_helm_url = 'https://storage.googleapis.com/solo-public-helm/charts/{}'.format(gloo_archive_name)
### Config End ###
### Main Start ###
def main():
if not is_shutdown:
extractGlooGatewayCharts()
provisionClusterRoleBindings()
provisionConfigMaps()
provisionCRDs()
provisionGlooGateway()
# Back out of actual provisioning for debugging purposes by uncommenting below
# fail('NOT YET ;)')
### Main End ###
### Extract Gloo Charts Start ###
def extractGlooGatewayCharts():
local('mkdir -p {}'.format(local_downloads_dir))
chart = '{}/{}'.format(local_downloads_dir, gloo_archive_name)
exists = False
for chart in listdir(local_downloads_dir):
if chart.find(gloo_archive_name) >= 0:
exists = True
break
if exists == False:
local('cd {} && curl -O {}'.format(local_downloads_dir, gloo_helm_url))
local('mkdir -p {}'.format(absolute_gloo_chart_dir))
local('tar -xzf {} -C {}'.format(chart, absolute_gloo_chart_dir));
### Extract Gloo Charts End ###
### Custom Resource Definitions Start ###
def provisionCRDs():
crds_filename_map = {
'authconfig': 'auth_config',
'gateway': 'gateway',
'proxy': 'proxy',
'routetable': 'route_table',
'settings': 'settings',
'upstreamgroup': 'upstream_group',
'upstream': 'upstream',
'virtualservice': 'virtual_service',
}
gloo_crds = listdir('{}/gloo/crds'.format(absolute_gloo_chart_dir))
print(gloo_crds);
for crd in crds_filename_map.keys():
createdCRD = local('kubectl get crd {crd} --ignore-not-found'.format(
crd = crd
))
if not createdCRD:
for template in gloo_crds:
if template.find(crds_filename_map[crd]) >= 0:
local('kubectl --namespace=default apply --validate=0 --force -f {template}'.format(
template=template,
))
### Custom Resource Definitions End ###
### Cluster Role Bindings Start ###
def provisionClusterRoleBindings():
serviceaccounts_filename_map = {
'discovery': 'discovery-service-account',
'gateway': 'gateway-service-account',
'gateway-proxy': 'gateway-proxy-service-account',
'gloo': 'gloo-service-account',
}
gloo_templates = listdir('{}/gloo/templates'.format(absolute_gloo_chart_dir))
for serviceaccount in serviceaccounts_filename_map.keys():
createdServiceAccount = local('kubectl get serviceaccount {serviceaccount} --ignore-not-found'.format(
serviceaccount = serviceaccount
))
if not createdServiceAccount:
for template in gloo_templates:
if template.find(serviceaccounts_filename_map[serviceaccount]) >= 0:
local('{templateCmd} -s {template} -f {baseConfig} -f {overridesFile} {chartDir}/gloo -g | kubectl --namespace=default apply --validate=0 --force -f -'.format(
chartDir=absolute_gloo_chart_dir,
templateCmd=gloo_helm_template_cmd,
baseConfig=tidepool_helm_values_file,
overridesFile=tidepool_helm_overrides_file,
template=template.replace('{}/gloo/'.format(absolute_gloo_chart_dir), ""),
))
clusterrolebinding = local('kubectl get clusterrolebinding {serviceaccount}-admin --ignore-not-found'.format(
serviceaccount = serviceaccount
))
if not clusterrolebinding:
local('kubectl create clusterrolebinding {serviceaccount}-admin --clusterrole cluster-admin --serviceaccount=default:{serviceaccount} --validate=0'.format(
serviceaccount = serviceaccount
))
### Cluster Role Bindings End ###
### Config Maps Start ###
def provisionConfigMaps():
configmaps_filename_map = {
'gateway-proxy': 'gateway-proxy-configmap',
}
required_configmaps = configmaps_filename_map.keys()
gloo_templates = listdir('{}/gloo/templates'.format(absolute_gloo_chart_dir))
# Skip configmaps already available on cluster
existing_configmaps = str(local("kubectl get --ignore-not-found configmaps -o=jsonpath='{.items[].metadata.name}'")).split()
for existing_configmap in existing_configmaps:
if ','.join(required_configmaps).find(existing_configmap) >= 0:
required_configmaps.remove(existing_configmap)
for configmap in required_configmaps:
for template in gloo_templates:
if template.find(configmaps_filename_map[configmap]) >= 0:
local('{templateCmd} -s {template} -f {baseConfig} -f {overridesFile} {chartDir}/gloo -g | kubectl --namespace=default apply --validate=0 --force -f -'.format(
chartDir=absolute_gloo_chart_dir,
templateCmd=gloo_helm_template_cmd,
baseConfig=tidepool_helm_values_file,
overridesFile=tidepool_helm_overrides_file,
template=template.replace('{}/gloo/'.format(absolute_gloo_chart_dir), ""),
))
### Config Maps End ###
### Gloo Gateway Start ###
def provisionGlooGateway():
for template in listdir('{}/gloo/templates'.format(absolute_gloo_chart_dir)):
if template.find('service-account') >= 0 or template.find('gateway-proxy-configmap') >= 0:
local('rm {}'.format(template))
k8s_yaml(local('{templateCmd} -f {baseConfig} -f {overridesFile} {chartDir}/gloo'.format(
chartDir=absolute_gloo_chart_dir,
templateCmd=gloo_helm_template_cmd,
baseConfig=tidepool_helm_values_file,
overridesFile=tidepool_helm_overrides_file,
)))
# Expose the gateway proxy on a host port
gateway_port_forwards = getNested(config,'gateway-proxy.portForwards', ['3000'])
k8s_resource('gateway-proxy', port_forwards=gateway_port_forwards)
### Gloo Gateway End ###
# Unleash the beast
main()