|
2 | 2 | import os |
3 | 3 | import logging |
4 | 4 | import json |
5 | | -from typing import Optional |
6 | 5 | from codehub.cli.gcp.terraform import ( |
7 | 6 | setup_terraform, |
8 | 7 | terraform_apply, |
9 | 8 | terraform_output, |
10 | 9 | ) |
11 | 10 | from distutils.dir_util import copy_tree |
12 | | -from codehub.cli.config import STRUCTURE, CreateConfig, DeployConfig, OAuthConfig |
| 11 | +from codehub.cli.config import ( |
| 12 | + STRUCTURE, |
| 13 | + CreateConfig, |
| 14 | + DeployConfig, |
| 15 | + HubConfig, |
| 16 | + UpgradeConfig, |
| 17 | +) |
13 | 18 | from codehub.cli.gcp.helpers import authenticate_k8s_GKE |
14 | 19 | from codehub.cli.k8s.create import create_k8s_resources |
15 | 20 | from codehub.cli.helm.create import create_deploy |
@@ -48,39 +53,40 @@ def create(config: CreateConfig): |
48 | 53 | deploy_config = DeployConfig( |
49 | 54 | config.name, config.region, helm_dir, hub_dir, k8s_dir, cloud_state |
50 | 55 | ) |
| 56 | + hub_config = HubConfig(config.admins) |
51 | 57 |
|
52 | 58 | __create_k8s_resources(deploy_config) |
53 | 59 |
|
54 | | - __create_deploy(deploy_config, admins=config.admins) |
| 60 | + __create_deploy(deploy_config, hub_config) |
55 | 61 | install_helm_chart(deploy_config, upgrade=False) |
56 | 62 |
|
57 | 63 | wait_for_hub_to_get_ready(k8s_dir) |
58 | 64 |
|
59 | 65 | return get_ip(config.name, k8s_dir) |
60 | 66 |
|
61 | 67 |
|
62 | | -def upgrade(name, admins, https=None, oauth_config: Optional[OAuthConfig] = None): |
63 | | - old_deploy_dir = get_latest_deployment(name=name) |
| 68 | +def upgrade(config: UpgradeConfig): |
| 69 | + old_deploy_dir = get_latest_deployment(config.name) |
64 | 70 |
|
65 | 71 | helm_dir, hub_dir, k8s_dir, cloud_dir = __upgrade_deploy_structure( |
66 | | - name, old_deploy_dir |
| 72 | + config.name, old_deploy_dir |
67 | 73 | ) |
68 | 74 | cloud_state = terraform_output(cloud_dir=cloud_dir) |
69 | 75 |
|
70 | 76 | region = read_yaml(os.path.join(old_deploy_dir, "helm", "chart.yaml"))["install"][ |
71 | 77 | "region" |
72 | 78 | ] |
73 | | - deploy_config = DeployConfig(name, region, helm_dir, hub_dir, k8s_dir, cloud_state) |
| 79 | + deploy_config = DeployConfig( |
| 80 | + config.name, region, helm_dir, hub_dir, k8s_dir, cloud_state |
| 81 | + ) |
74 | 82 |
|
75 | 83 | __create_deploy( |
76 | 84 | deploy_config, |
77 | | - admins=admins, |
78 | | - https=https, |
79 | | - oauth_config=oauth_config, |
| 85 | + config.hub_config, |
80 | 86 | ) |
81 | 87 | install_helm_chart(deploy_config, upgrade=True) |
82 | 88 |
|
83 | | - authenticate_k8s_GKE(name) |
| 89 | + authenticate_k8s_GKE(config.name) |
84 | 90 | wait_for_hub_to_get_ready(k8s_dir) |
85 | 91 |
|
86 | 92 |
|
@@ -134,18 +140,9 @@ def __create_k8s_resources(deploy_config: DeployConfig): |
134 | 140 |
|
135 | 141 | def __create_deploy( |
136 | 142 | deploy_config: DeployConfig, |
137 | | - admins, |
138 | | - https=None, |
139 | | - oauth_config: Optional[OAuthConfig] = None, |
| 143 | + hub_config: HubConfig, |
140 | 144 | ): |
141 | | - contact_email = None |
142 | 145 | with open(STRUCTURE["secrets"]["gcp"]["sa"], "rt") as f: |
143 | | - contact_email = json.loads(f.read())["client_email"] |
| 146 | + hub_config.contact_email = json.loads(f.read())["client_email"] |
144 | 147 |
|
145 | | - create_deploy( |
146 | | - deploy_config, |
147 | | - contact_email=contact_email, |
148 | | - admins=admins, |
149 | | - https=https, |
150 | | - oauth_config=oauth_config, |
151 | | - ) |
| 148 | + create_deploy(deploy_config, hub_config) |
0 commit comments