Skip to content

Commit a3eb4f0

Browse files
Deduplicate cluster creation
1 parent 256e36e commit a3eb4f0

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

codehub/cli/create.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from codehub.cli.helm.create import create_deploy
2121
from codehub.cli.helm.install import install_helm_chart
2222
from codehub.cli.helpers import get_cloud_dir, get_latest_deployment, read_yaml
23-
from codehub.cli.manage import wait_for_hub_to_get_ready, get_ip
23+
from codehub.cli.manage import wait_for_hub_to_get_ready
2424
import kubernetes.client.rest # Add this import for the exception handling
2525

2626

27-
def create_infrastructure(config: CreateConfig):
27+
def create_infrastructure(config: CreateConfig) -> DeployConfig:
2828
helm_dir, hub_dir, k8s_dir, cloud_dir = __create_deploy_structure(config.name)
2929

3030
setup_terraform(
@@ -38,31 +38,21 @@ def create_infrastructure(config: CreateConfig):
3838
)
3939
__create_k8s_resources(deploy_config)
4040

41-
return get_ip(config.name, k8s_dir)
41+
return deploy_config
4242

4343

44-
def create(config: CreateConfig):
45-
helm_dir, hub_dir, k8s_dir, cloud_dir = __create_deploy_structure(config.name)
46-
47-
setup_terraform(
48-
config=config,
49-
cloud_dir=cloud_dir,
50-
)
51-
52-
cloud_state = terraform_apply(cloud_dir=cloud_dir)
53-
deploy_config = DeployConfig(
54-
config.name, config.region, helm_dir, hub_dir, k8s_dir, cloud_state
55-
)
44+
def create(config: CreateConfig) -> DeployConfig:
45+
deploy_config = create_infrastructure(config)
5646
hub_config = HubConfig(config.admins)
5747

5848
__create_k8s_resources(deploy_config)
5949

6050
__create_deploy(deploy_config, hub_config)
6151
install_helm_chart(deploy_config, upgrade=False)
6252

63-
wait_for_hub_to_get_ready(k8s_dir)
53+
wait_for_hub_to_get_ready(deploy_config.k8s_dir)
6454

65-
return get_ip(config.name, k8s_dir)
55+
return deploy_config
6656

6757

6858
def upgrade(config: UpgradeConfig):

codehub/cli/entrypoint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def createcluster(name, admin, region, zone, machine_type):
4242
admins = [user.lower() for user in admin]
4343
config = CreateConfig(name, admins, region, zone, machine_type)
4444

45-
res = create(config)
45+
deploy_config = create(config)
46+
res = get_ip(name, deploy_config.k8s_dir)
4647

4748
logger.debug(f"{create.__module__}.{create.__name__} output:")
4849
logger.debug(res)
@@ -152,7 +153,8 @@ def createclusterinfra(name, region, zone, machine_type):
152153
admins = []
153154
config = CreateConfig(name, admins, region, zone, machine_type)
154155

155-
res = create_infrastructure(config)
156+
deploy_config = create_infrastructure(config)
157+
res = get_ip(name, deploy_config.k8s_dir)
156158

157159
logger.debug(f"{create.__module__}.{create.__name__} output:")
158160
logger.debug(res)

0 commit comments

Comments
 (0)