Skip to content

Commit

Permalink
[INFRA-2155] Bringing back functionality to create HZ
Browse files Browse the repository at this point in the history
  • Loading branch information
vitali-federau-fivestars committed Nov 22, 2023
1 parent 48ed3cb commit b35578a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions aladdin/lib/aws/dns_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ def fill_hostedzone(
):
cluster_domain_name = cluster_domain_name or ClusterRules().cluster_domain_name
namespace_domain_name = namespace_domain_name or ClusterRules().namespace_domain_name
namespace_hosted_zone = get_hostedzone(
boto_session, namespace_domain_name
) or create_hostedzone(boto_session, namespace_domain_name)

# Get the namespace hosted zone, raise an error if not found
namespace_hosted_zone = get_hostedzone(boto_session, namespace_domain_name)
if namespace_hosted_zone is None:
raise KeyError("Hosted zone for [%s] not found" % namespace_domain_name)

# Get the cluster hosted zone, raise an error if not found
cluster_hosted_zone = get_hostedzone(boto_session, cluster_domain_name)
if cluster_hosted_zone is None:
raise KeyError("Route 53 for [%s] not found" % cluster_domain_name)
raise KeyError("route 53 for [%s] not found" % cluster_domain_name)

dns_nameservers = get_ns_from_hostedzone(boto_session, namespace_hosted_zone)

Expand Down Expand Up @@ -51,6 +48,24 @@ def get_hostedzone(boto_session, dns_name) -> str:
return hostedzone_id


def create_hostedzone(boto_session, dns_name) -> str:
log = logging.getLogger(__name__)
route53 = boto_session.client("route53")

ref = "aladdin_generated_{:%Y%m%d_%H%M%S}".format(datetime.now())

log.info("Hosted zone %s created", dns_name)

log.info("Creating hosted zone : %s", dns_name)
create_res = route53.create_hosted_zone(
Name=dns_name,
CallerReference=ref,
HostedZoneConfig=dict(Comment="Generated by aladdin", PrivateZone=False),
)

return create_res["HostedZone"]["Id"]


def get_ns_from_hostedzone(boto_session, hostedzone_id):
route53 = boto_session.client("route53")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aladdin"
version = "1.25.15.3"
version = "1.25.15.2"
description = ""
authors = ["Fivestars <dev@fivestars.com>"]
include = [
Expand Down

0 comments on commit b35578a

Please sign in to comment.