From 1f070bae5678d78179bf3c96b856ea299d083668 Mon Sep 17 00:00:00 2001 From: yshah Date: Tue, 23 Sep 2025 09:47:12 +0000 Subject: [PATCH] Bug 2408 Fix for cluster creation using subnets in AWS Change-Id: Id17fc50337d79c3cf93907db035949a2534bad48 Signed-off-by: yshah --- osm_lcm/k8s.py | 53 +++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 28641986..3f7713a3 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -793,30 +793,35 @@ class ClusterLcm(GitOpsLcm): db_cluster["credentials"] = cluster_creds # Retrieve subnets - if db_cluster["vim_type"] == "aws": - generic_object = await self.odu.list_object( - api_group="ec2.aws.upbound.io", - api_plural="subnets", - api_version="v1beta1", - ) - private_subnet = [] - public_subnet = [] - for subnet in generic_object: - labels = subnet.get("metadata", {}).get("labels", {}) - status = subnet.get("status", {}).get("atProvider", {}) - # Extract relevant label values - cluster_label = labels.get("cluster") - access_label = labels.get("access") - subnet_id = status.get("id") - # Apply filtering - if cluster_label == db_cluster["name"] and subnet_id: - if access_label == "private": - private_subnet.append(subnet_id) - elif access_label == "public": - public_subnet.append(subnet_id) - # Update db_cluster - db_cluster["private_subnet"] = private_subnet - db_cluster["public_subnet"] = public_subnet + if op_params.get("private_subnet") and op_params.get("public_subnet"): + db_cluster["private_subnet"] = op_params["private_subnet"] + db_cluster["public_subnet"] = op_params["public_subnet"] + else: + if db_vim["vim_type"] == "aws": + generic_object = await self.odu.list_object( + api_group="ec2.aws.upbound.io", + api_plural="subnets", + api_version="v1beta1", + ) + private_subnet = [] + public_subnet = [] + for subnet in generic_object: + labels = subnet.get("metadata", {}).get("labels", {}) + status = subnet.get("status", {}).get("atProvider", {}) + # Extract relevant label values + cluster_label = labels.get("cluster") + access_label = labels.get("access") + subnet_id = status.get("id") + # Apply filtering + if cluster_label == db_cluster["name"] and subnet_id: + if access_label == "private": + private_subnet.append(subnet_id) + elif access_label == "public": + public_subnet.append(subnet_id) + # Update db_cluster + db_cluster["private_subnet"] = private_subnet + db_cluster["public_subnet"] = public_subnet + self.logger.info("DB cluster: {}".format(db_cluster)) # Register the cluster in k8sclusters collection db_register["credentials"] = cluster_creds -- 2.25.1