-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy path__main__.py
57 lines (46 loc) · 2.33 KB
/
__main__.py
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
import pulumi
from ingress_controller_image import IngressControllerImage
from ingress_controller_image_builder_args import IngressControllerImageBuilderArgs
from ingress_controller_image_puller_args import IngressControllerImagePullerArgs
from nginx_plus_args import NginxPlusArgs
DEFAULT_KIC = "nginx/nginx-ingress:2.4.2"
stack_name = pulumi.get_stack()
project_name = pulumi.get_project()
config = pulumi.Config('kic')
image_origin = config.get('image_origin')
if not image_origin:
pulumi.log.info('kic:image_origin not specified, defaulting to: repository')
image_origin = 'registry'
make_target = config.get('make_target')
kic_src_url = config.get('src_url')
always_rebuild = config.get_bool('always_rebuild')
plus_config = config.get_object('nginx_plus')
if plus_config:
nginx_plus_args = NginxPlusArgs(key_path=plus_config.get('kic:key_path'),
cert_path=plus_config.get('kic:cert_path'))
else:
nginx_plus_args = None
# Below is a crucial fork in logic where if 'source' is specified, we build the
# KIC container image from source code. If 'registry' is specified, we pull an
# existing image from a container registry.
#
# In the case of the registry workflow, authentication (login or certs) need to
# be configured before this script is ran.
if image_origin == 'source':
image_args = IngressControllerImageBuilderArgs(make_target=make_target,
kic_src_url=kic_src_url,
always_rebuild=always_rebuild,
nginx_plus_args=nginx_plus_args)
# Download KIC source code, run `make`, and build Docker images
ingress_image = IngressControllerImage(name='nginx-ingress-controller',
kic_image_args=image_args)
elif image_origin == 'registry':
if not config.get('image_name'):
image_args = IngressControllerImagePullerArgs(image_name=DEFAULT_KIC)
else:
image_args = IngressControllerImagePullerArgs(image_name=config.get('image_name'))
ingress_image = IngressControllerImage(name='nginx-ingress-controller',
kic_image_args=image_args)
else:
raise RuntimeError(f'unknown image_origin: {image_origin}')
pulumi.export('ingress_image', ingress_image)