44import json
55from typing import Optional
66from codehub .cli .gcp .terraform import (
7- TerraformOutput ,
87 setup_terraform ,
98 terraform_apply ,
109 terraform_output ,
1110)
1211from distutils .dir_util import copy_tree
13- from codehub .cli .config import STRUCTURE , CreateConfig , OAuthConfig
12+ from codehub .cli .config import STRUCTURE , CreateConfig , DeployConfig , OAuthConfig
1413from codehub .cli .gcp .helpers import authenticate_k8s_GKE
1514from codehub .cli .k8s .create import create_k8s_resources
1615from codehub .cli .helm .create import create_deploy
2120
2221
2322def create_infrastructure (config : CreateConfig ):
24- _ , _ , k8s_dir , cloud_dir = __create_deploy_structure (config .name )
23+ helm_dir , hub_dir , k8s_dir , cloud_dir = __create_deploy_structure (config .name )
2524
2625 setup_terraform (
2726 config = config ,
2827 cloud_dir = cloud_dir ,
2928 )
3029
3130 cloud_state = terraform_apply (cloud_dir = cloud_dir )
32- __create_k8s_resources (
33- config .name ,
34- deploy_dir = k8s_dir ,
35- nfs_name = cloud_state .nfs_name ,
36- nfs_ip = cloud_state .nfs_ip ,
31+ deploy_config = DeployConfig (
32+ config .name , config .region , helm_dir , hub_dir , k8s_dir , cloud_state
3733 )
34+ __create_k8s_resources (deploy_config )
3835
3936 return get_ip (config .name , k8s_dir )
4037
@@ -48,19 +45,14 @@ def create(config: CreateConfig):
4845 )
4946
5047 cloud_state = terraform_apply (cloud_dir = cloud_dir )
51- __create_k8s_resources (
52- config .name ,
53- deploy_dir = k8s_dir ,
54- nfs_name = cloud_state .nfs_name ,
55- nfs_ip = cloud_state .nfs_ip ,
48+ deploy_config = DeployConfig (
49+ config .name , config .region , helm_dir , hub_dir , k8s_dir , cloud_state
5650 )
5751
52+ __create_k8s_resources (deploy_config )
53+
5854 __install_helm_chart (
59- config .name ,
60- region = config .region ,
61- helm_deploy_dir = helm_dir ,
62- hub_deploy_dir = hub_dir ,
63- cloud_state = cloud_state ,
55+ deploy_config ,
6456 admins = config .admins ,
6557 )
6658
@@ -77,16 +69,13 @@ def upgrade(name, admins, https=None, oauth_config: Optional[OAuthConfig] = None
7769 )
7870 cloud_state = terraform_output (cloud_dir = cloud_dir )
7971
80- last_helm_install = read_yaml (os .path .join (old_deploy_dir , "helm" , "chart.yaml" ))[
81- "install "
72+ region = read_yaml (os .path .join (old_deploy_dir , "helm" , "chart.yaml" ))[ "install" ] [
73+ "region "
8274 ]
75+ deploy_config = DeployConfig (name , region , helm_dir , hub_dir , k8s_dir , cloud_state )
8376
8477 __upgrade_helm_chart (
85- name ,
86- region = last_helm_install ["region" ],
87- helm_deploy_dir = helm_dir ,
88- hub_deploy_dir = hub_dir ,
89- cloud_state = cloud_state ,
78+ deploy_config ,
9079 admins = admins ,
9180 https = https ,
9281 oauth_config = oauth_config ,
@@ -130,10 +119,10 @@ def __upgrade_deploy_structure(name, old_deploy_dir):
130119 return helm_dir , hub_dir , k8s_dir , cloud_dir
131120
132121
133- def __create_k8s_resources (name , deploy_dir , nfs_name , nfs_ip ):
134- authenticate_k8s_GKE (name )
122+ def __create_k8s_resources (deploy_config : DeployConfig ):
123+ authenticate_k8s_GKE (deploy_config . name )
135124 try :
136- create_k8s_resources (deploy_dir , nfs_name , nfs_ip )
125+ create_k8s_resources (deploy_config )
137126 except kubernetes .client .rest .ApiException as e :
138127 logger = logging .getLogger (__name__ )
139128 # If the error is due to a resource already existing, we can continue
@@ -145,52 +134,31 @@ def __create_k8s_resources(name, deploy_dir, nfs_name, nfs_ip):
145134
146135
147136def __install_helm_chart (
148- name ,
149- region ,
150- helm_deploy_dir ,
151- hub_deploy_dir ,
152- cloud_state : TerraformOutput ,
137+ deploy_config : DeployConfig ,
153138 admins ,
154139):
155- __create_deploy (name , helm_deploy_dir , hub_deploy_dir , cloud_state , admins )
156- install_helm_chart (
157- name ,
158- region = region ,
159- helm_deploy_dir = helm_deploy_dir ,
160- hub_deploy_dir = hub_deploy_dir ,
161- )
140+ __create_deploy (deploy_config , admins )
141+ install_helm_chart (deploy_config )
162142
163143
164144def __upgrade_helm_chart (
165- name ,
166- region ,
167- helm_deploy_dir ,
168- hub_deploy_dir ,
169- cloud_state : TerraformOutput ,
145+ deploy_config : DeployConfig ,
170146 admins ,
171147 https = None ,
172148 oauth_config : Optional [OAuthConfig ] = None ,
173149):
174150 __create_deploy (
175- name ,
176- helm_deploy_dir ,
177- hub_deploy_dir ,
178- cloud_state = cloud_state ,
151+ deploy_config ,
179152 admins = admins ,
180153 https = https ,
181154 oauth_config = oauth_config ,
182155 )
183156
184- upgrade_helm_chart (
185- name , region , helm_deploy_dir = helm_deploy_dir , hub_deploy_dir = hub_deploy_dir
186- )
157+ upgrade_helm_chart (deploy_config )
187158
188159
189160def __create_deploy (
190- name ,
191- helm_deploy_dir ,
192- hub_deploy_dir ,
193- cloud_state : TerraformOutput ,
161+ deploy_config : DeployConfig ,
194162 admins ,
195163 https = None ,
196164 oauth_config : Optional [OAuthConfig ] = None ,
@@ -200,12 +168,9 @@ def __create_deploy(
200168 contact_email = json .loads (f .read ())["client_email" ]
201169
202170 create_deploy (
203- name ,
171+ deploy_config ,
204172 contact_email = contact_email ,
205173 admins = admins ,
206- helm_deploy_dir = helm_deploy_dir ,
207- hub_deploy_dir = hub_deploy_dir ,
208- cloud_state = cloud_state ,
209174 https = https ,
210175 oauth_config = oauth_config ,
211176 )
0 commit comments