forked from nginxinc/kic-reference-architectures
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
104 lines (87 loc) · 3.15 KB
/
Copy path__main__.py
File metadata and controls
104 lines (87 loc) · 3.15 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
import pulumi
import os
import pulumi_kubernetes as k8s
from kic_util import pulumi_config
from pulumi_kubernetes.helm.v3 import Release, ReleaseArgs, RepositoryOptsArgs
# We need the kubeconfig and cluster name.
config = pulumi.Config('kubernetes')
cluster_name = config.require('cluster_name')
context_name = config.require('context_name')
kubeconfig = config.require('kubeconfig')
# Function to add namespace
def add_namespace(obj):
obj['metadata']['namespace'] = 'nfsvols'
def pulumi_kube_project_name():
script_dir = os.path.dirname(os.path.abspath(__file__))
kube_project_path = os.path.join(script_dir, '..', 'common')
return pulumi_config.get_pulumi_project_name(kube_project_path)
stack_name = pulumi.get_stack()
project_name = pulumi.get_project()
kube_project_name = pulumi_kube_project_name()
pulumi_user = pulumi_config.get_pulumi_user()
kube_stack_ref_id = f"{pulumi_user}/{kube_project_name}/{stack_name}"
kube_stack_ref = pulumi.StackReference(kube_stack_ref_id)
k8s_provider = k8s.Provider(resource_name=f'ingress-controller', kubeconfig=kubeconfig)
ns = k8s.core.v1.Namespace(resource_name='nfsvols',
metadata={'name': 'nfsvols'},
opts=pulumi.ResourceOptions(provider=k8s_provider))
config = pulumi.Config('nfsvols')
chart_name = config.get('chart_name')
if not chart_name:
chart_name = 'nfs-subdir-external-provisioner'
chart_version = config.get('chart_version')
if not chart_version:
chart_version = '4.0.14'
helm_repo_name = config.get('helm_repo_name')
if not helm_repo_name:
helm_repo_name = 'nfs-subdir-external-provisioner'
helm_repo_url = config.get('helm_repo_url')
if not helm_repo_url:
helm_repo_url = 'https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner'
nfsserver = config.require('nfsserver')
nfspath = config.require('nfspath')
nfsopts = '{nolock,nfsvers=3}'
#
# Allow the user to set timeout per helm chart; otherwise
# we default to 5 minutes.
#
helm_timeout = config.get_int('helm_timeout')
if not helm_timeout:
helm_timeout = 300
nfsvols_release_args = ReleaseArgs(
chart=chart_name,
repository_opts=RepositoryOptsArgs(
repo=helm_repo_url
),
version=chart_version,
namespace=ns.metadata.name,
# Values from Chart's parameters specified hierarchically,
values={
"storageClass": {
"defaultClass": True
},
"nfs": {
"server": nfsserver,
"path": nfspath,
"mountOptions": [
"nolock",
"nfsvers=3"
]
}
},
# User configurable timeout
timeout=helm_timeout,
# By default, Release resource will wait till all created resources
# are available. Set this to true to skip waiting on resources being
# available.
skip_await=False,
cleanup_on_fail=True,
# Provide a name for our release
name="nfsvols",
# Lint the chart before installing
lint=True,
# Force update if required
force_update=True)
nfsvols_release = Release("nfsvols", args=nfsvols_release_args)
nfsvols_status = nfsvols_release.status
pulumi.export('nfsvols_status', pulumi.Output.unsecret(nfsvols_status))