Skip to content

Commit

Permalink
[IMP] create_domain function to use the subdomain
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Nov 29, 2024
1 parent 4734ff8 commit ccd331c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions argocd_deployer/models/application_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ def create_domain(
i = 0
best_available = False
while not best_available:
i_as_str = str(i)
for domain in domains:
domain_name = domain
if i:
domain_name += i_as_str
domain_levels = domain_name.split(".")
domain_levels[0] += str(i)
domain_name = ".".join(domain_levels)
search_domain = [("name", "=", domain_name)]
if scope_unique:
search_domain += [("scope", "=", scope)]
Expand Down
26 changes: 26 additions & 0 deletions argocd_deployer/tests/test_application_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,29 @@ def test_create_domain(self):
"myapp",
"Scope unique domain should still be available in different scope",
)

def test_subdomain(self):
argocd_application_domain = self.env["argocd.application.domain"]
domain = argocd_application_domain.create_domain(
self.app_2, "myapp.saas.com", scope="website"
)
self.assertEqual(domain, "myapp.saas.com")
domain = argocd_application_domain.create_domain(
self.app_1, "myapp.saas.com", scope="website"
)
self.assertEqual(domain, "myapp1.saas.com", "it should change the subdomain")

domain = argocd_application_domain.create_domain(
self.app_1, "myapp.saas.com", scope="matomo"
)
self.assertEqual(domain, "myapp2.saas.com", "it should change the subdomain")

domain = argocd_application_domain.create_domain(
self.app_1, "nosub", scope="haystack"
)
self.assertEqual(domain, "nosub")

domain = argocd_application_domain.create_domain(
self.app_2, "nosub", scope="haystack"
)
self.assertEqual(domain, "nosub1")

0 comments on commit ccd331c

Please sign in to comment.