Skip to content

Commit

Permalink
[IMP] argocd_deployer: Added new domain computation to application set.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGigSolutions committed Mar 21, 2024
1 parent 7eeb16c commit 54e3489
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
2 changes: 2 additions & 0 deletions argocd_deployer/data/application_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<field name="branch">main</field>
<field name="repository_directory">/home/tarteo/repo</field>
<field name="instances_directory">instances</field>
<field name="domain_format">%(application_name)s.curq.k8s.onestein.eu</field>
<field name="subdomain_format">%(subdomain)s.%(application_name)s.curq.k8s.onestein.eu</field>
</record>
</odoo>
16 changes: 7 additions & 9 deletions argocd_deployer/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def get_value(self, key, default=""):
kv_pair = self.value_ids.filtered(lambda v: v.key == key)
return kv_pair and kv_pair.value or default


def has_tag(self, key):
self.ensure_one()
return bool(self.tag_ids.filtered(lambda t: t.key == key))
Expand All @@ -65,17 +64,12 @@ def format_domain(self, subdomain=None):
@return: formatted domain
"""
self.ensure_one()
config_parameter_sudo = self.env["ir.config_parameter"].sudo()
values = {"application_name": self.name}
if subdomain:
domain_format = config_parameter_sudo.get_param(
"argocd.application_subdomain_format"
)
domain_format = self.application_set_id.subdomain_format
values["subdomain"] = subdomain
else:
domain_format = config_parameter_sudo.get_param(
"argocd.application_domain_format"
)
domain_format = self.application_set_id.domain_format
return domain_format % values

@api.depends("config")
Expand All @@ -93,6 +87,10 @@ def _render_description(self):
raise_if_not_found=False,
)

@staticmethod
def _get_domain(helm):
return helm.get("domain") or helm.get("globals", {}).get("domain")

def get_urls(self):
self.ensure_one()
urls = []
Expand All @@ -101,7 +99,7 @@ def get_urls(self):

config = yaml.load(self.config, Loader=Loader)
helm = yaml.load(config["helm"], Loader=Loader)
urls.append(("https://%s" % helm["domain"], "Odoo"))
urls.append(("https://%s" % self._get_domain(helm), "Odoo"))
for tag in self.tag_ids.filtered(lambda t: t.domain_yaml_path):
yaml_path = tag.domain_yaml_path.split(".")
domain = helm
Expand Down
15 changes: 14 additions & 1 deletion argocd_deployer/models/application_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ class ApplicationSet(models.Model):
required=True,
help="Folder inside the repository in which to store the application YAML files.",
)
domain_format = fields.Char(
required=True,
help="The domain format used to build the domain for the deployment.",
)
subdomain_format = fields.Char(
required=True,
help="The domain format used to build the domain for the deployment.",
)

_sql_constraints = [
("application_set_name_unique", "unique(name)", "Already exists")
("application_set_name_unique", "unique(name)", "Already exists"),
(
"app_set_unique",
"unique(repository_url, branch, instances_directory)",
"Another app set is already linked to this repository, branch and instances folder.",
),
]

def _get_repository_directory(self, allow_create=True):
Expand Down
10 changes: 5 additions & 5 deletions argocd_deployer/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def test_get_urls(self):
"argocd_deployer.demo_curq_basis_application_template"
),
"tag_ids": [
self.ref("argocd_deployer.demo_matomo_server_application_tag")
self.ref("argocd_deployer.demo_matomo_server_application_tag"),
],
}
)
app.render_config()
urls = app.get_urls()
expected_urls = [
urls = {url for url in app.get_urls()}
expected_urls = {
("https://myapp.curq.k8s.onestein.eu", "Odoo"),
("https://matomo.myapp.curq.k8s.onestein.eu", "Matomo Server"),
]
self.assertEqual(urls, expected_urls)
}
self.assertEqual(expected_urls, urls)

app.tag_ids = [Command.clear()]
app.render_config()
Expand Down
23 changes: 21 additions & 2 deletions argocd_deployer/views/application_set_view.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="application_set_form" model="ir.ui.view">
<field name="model">argocd.application.set</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="repository_url"/>
<field name="branch"/>
<field name="repository_directory"/>
<field name="instances_directory"/>
<field name="domain_format"/>
<field name="subdomain_format"/>
</group>
</sheet>
</form>
</field>
</record>

<record id="application_set_tree" model="ir.ui.view">
<field name="model">argocd.application.set</field>
<field name="arch" type="xml">
<tree editable="bottom">
<tree>
<field name="name"/>
<field name="repository_url"/>
<field name="branch"/>
Expand All @@ -17,6 +36,6 @@
<field name="name">App. Sets</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">argocd.application.set</field>
<field name="view_mode">tree</field>
<field name="view_mode">tree,form</field>
</record>
</odoo>

0 comments on commit 54e3489

Please sign in to comment.