Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse vpc for multiple rosa hcp #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 43 additions & 36 deletions libs/platforms/rosa/hypershift/hypershift.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _create_vpcs(self, vpcs_to_create):
myenv["TF_VAR_cluster_name_seed"] = self.environment[
"cluster_name_seed"
]
myenv["TF_VAR_cluster_count"] = str(self.environment["cluster_count"])
myenv["TF_VAR_cluster_count"] = str(vpcs_to_create)
myenv["TF_VAR_aws_region"] = self.environment["aws"]["region"]
apply_code, apply_out, apply_err = self.utils.subprocess_exec(
"terraform apply --auto-approve",
Expand Down Expand Up @@ -190,9 +190,9 @@ def _create_vpcs(self, vpcs_to_create):
json_output["outputs"]["cluster-private-subnets"]["value"]
)
if (
number_of_vpcs != self.environment["cluster_count"]
or number_of_public != self.environment["cluster_count"]
or number_of_private != self.environment["cluster_count"]
number_of_vpcs != vpcs_to_create
or number_of_public != vpcs_to_create
or number_of_private != vpcs_to_create
):
self.logging.info(
"Required Clusters: %d" % self.environment["cluster_count"]
Expand All @@ -204,42 +204,49 @@ def _create_vpcs(self, vpcs_to_create):
self.logging.info(
"Number of Public Subnets: %d" % number_of_public
)
self.logging.info(
"Number of Clusters per VPC: %d" % self.environment["clusters_per_vpc"]
)
self.logging.warning(
"Try %d: Not all resources has been created. retring in 15 seconds"
% trying
)
time.sleep(15)
else:
for cluster in range(self.environment["cluster_count"]):
vpc_id = json_output["outputs"]["vpc-id"]["value"][cluster]
public_subnets = json_output["outputs"][
"cluster-public-subnets"
]["value"][cluster]
private_subnets = json_output["outputs"][
"cluster-private-subnets"
]["value"][cluster]
if len(public_subnets) != 3 or len(private_subnets) != 3:
self.logging.warning(
"Try: %d. Number of public subnets of VPC %s: %d (required: 3)"
% (trying, vpc_id, len(public_subnets))
)
self.logging.warning(
"Try: %d. Number of private subnets of VPC %s: %d (required: 3)"
% (trying, vpc_id, len(private_subnets))
)
self.logging.warning(
"Try: %d: Not all subnets created, retring in 15 seconds"
% trying
)
time.sleep(15)
else:
self.logging.debug(
"VPC ID: %s, Public Subnet: %s, Private Subnet: %s"
% (vpc_id, public_subnets, private_subnets)
)
subnets = ",".join(public_subnets)
subnets = subnets + "," + ",".join(private_subnets)
vpcs.append((vpc_id, subnets))
# preparing vpcs dict with network and subnet details
for cluster in range(vpcs_to_create):
# internal loop iterates over number of cluster per vpc
# if cluster_per_pvc is set to 2, first 2 clusters share the same VPC
for itr in range(self.environment["clusters_per_vpc"]):
vpc_id = json_output["outputs"]["vpc-id"]["value"][cluster]
public_subnets = json_output["outputs"][
"cluster-public-subnets"
]["value"][cluster]
private_subnets = json_output["outputs"][
"cluster-private-subnets"
]["value"][cluster]
if len(public_subnets) != 3 or len(private_subnets) != 3:
self.logging.warning(
"Try: %d. Number of public subnets of VPC %s: %d (required: 3)"
% (trying, vpc_id, len(public_subnets))
)
self.logging.warning(
"Try: %d. Number of private subnets of VPC %s: %d (required: 3)"
% (trying, vpc_id, len(private_subnets))
)
self.logging.warning(
"Try: %d: Not all subnets created, retring in 15 seconds"
% trying
)
time.sleep(15)
else:
self.logging.debug(
"VPC ID: %s, Public Subnet: %s, Private Subnet: %s"
% (vpc_id, public_subnets, private_subnets)
)
subnets = ",".join(public_subnets)
subnets = subnets + "," + ",".join(private_subnets)
vpcs.append((vpc_id, subnets))
return vpcs
else:
self.logging.warning(
Expand Down Expand Up @@ -441,8 +448,8 @@ def create_cluster(self, platform, cluster_name):
self.logging.debug("Output directory set to %s" % cluster_info["path"])
cluster_cmd = ["rosa", "create", "cluster", "--cluster-name", cluster_name, "--replicas", str(cluster_info["workers"]), "--hosted-cp", "--sts", "--mode", "auto", "-y", "--output", "json", "--oidc-config-id", platform.environment["oidc_config_id"], "--region", platform.environment["aws"]["region"]]
if platform.environment["create_vpcs"]:
self.logging.debug(platform.environment["vpcs"][(cluster_info["index"] - 1) % len(platform.environment["vpcs"])])
cluster_info["vpc"] = platform.environment["vpcs"][(cluster_info["index"] - 1) % len(platform.environment["vpcs"])]
self.logging.debug(platform.environment["vpcs"][(cluster_info["index"])])
cluster_info["vpc"] = platform.environment["vpcs"][(cluster_info["index"])]
cluster_cmd.append("--subnet-ids")
cluster_cmd.append(cluster_info["vpc"][1])
if "shard_id" in platform.environment:
Expand Down
Loading