Skip to content

Commit

Permalink
[ADD] Multi master application set support
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Jun 13, 2024
1 parent d0c405b commit c101f81
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
3 changes: 1 addition & 2 deletions argocd_deployer/data/application_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<field name="deployment_directory">application_sets</field>
<field name="template_id" ref="application_set_template_master"/>
<field name="namespace_prefix_id" ref="argocd_deployer.namespace_prefix_application_set"/>
<field name="is_master">True</field>
</record>
<record id="application_set_default" model="argocd.application.set">
<field name="name">default</field>
Expand All @@ -22,6 +21,6 @@
<field name="subdomain_format">%(subdomain)s.%(application_name)s.curq.k8s.onestein.eu</field>
<field name="template_id" ref="application_set_template_default"/>
<field name="namespace_prefix_id" ref="argocd_deployer.namespace_prefix_flavoured_odoo"/>
<field name="is_master">False</field>
<field name="master_application_set_id" ref="argocd_deployer.application_set_master"/>
</record>
</odoo>
45 changes: 28 additions & 17 deletions argocd_deployer/models/application_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,48 @@ class ApplicationSet(models.Model):
]
is_master = fields.Boolean(
default=False,
compute="_compute_is_master",
store=True,
help="Indicates that this is the master application set. "
"This set must be manually installed in ArgoCD. There can only be a "
"single master set. Application sets deployed in CURQ are deployed in "
"This set must be manually installed in ArgoCD. "
"Application sets deployed in CURQ are deployed in "
"the master set.",
)
is_destroying = fields.Boolean(compute="_compute_is_destroying")
application_ids = fields.One2many(
"argocd.application", inverse_name="application_set_id"
)
master_application_set_id = fields.Many2one(comodel_name="argocd.application.set")

@api.constrains("deployment_directory")
def _check_deployment_directory(self):
if not self.deployment_directory:
raise ValidationError("Deployment directory is required.")
if self.deployment_directory[-1] == "/":
raise ValidationError("Deployment directories should not end with '/'.")

@api.constrains("is_master")
def _check_is_master_deployment(self):
@api.constrains("repository_directory")
def _check_unique_repository_directory(self):
if not self.is_master:
return
other_masters = (
self.env["argocd.application.set"].search(
[
("is_master", "=", True),
("repository_directory", "=", self.repository_directory),
]
)
- self
)
if other_masters:
raise ValidationError("There can be only one master application set.")
raise ValidationError(
"Master application set with the same `Repository Directory` exists."
)

@api.depends("master_application_set_id")
def _compute_is_master(self):
for app_set in self:
app_set.is_master = not bool(app_set.master_application_set_id)

@api.constrains("deployment_directory")
def _check_deployment_directory(self):
if not self.deployment_directory:
raise ValidationError("Deployment directory is required.")
if self.deployment_directory[-1] == "/":
raise ValidationError("Deployment directories should not end with '/'.")

@api.constrains("name")
def _constrain_name(self):
Expand All @@ -116,9 +127,9 @@ def _create_path_or_error(path, directory_name, path_does_not_exist_action):
else:
raise NotImplementedError("Path does not exist.")

@api.model
def _get_master_repository_directory(self, path_does_not_exist_action="create"):
master = self.env.ref("argocd_deployer.application_set_master")
self.ensure_one()
master = self.master_application_set_id or self
path = os.path.join(
master.repository_directory,
master.branch,
Expand All @@ -128,10 +139,10 @@ def _get_master_repository_directory(self, path_does_not_exist_action="create"):
)
return path

@api.model
def _get_master_deployment_directory(self, path_does_not_exist_action="create"):
"""Return the directory the master application set lives."""
master = self.env.ref("argocd_deployer.application_set_master")
self.ensure_one()
master = self.master_application_set_id or self
path = os.path.join(
self._get_master_repository_directory(path_does_not_exist_action),
master.deployment_directory,
Expand Down Expand Up @@ -240,7 +251,7 @@ def _get_repository(self):
return Repo.clone_from(self.repository_url, directory)

def _get_branch(self):
return self.env.ref("argocd_deployer.application_set_master").branch
return self.master_application_set_id.branch or self.branch

def _format_commit_message(self, message):
return message % self.name
Expand Down
3 changes: 2 additions & 1 deletion argocd_deployer/views/application_set_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
<field name="deployment_directory" attrs="{'readonly': [('is_deployed', '=', True)]}"/>
</group>
<group id="group_local_install" string="Local install">
<field name="is_master" attrs="{'readonly': [('is_deployed', '=', True)]}"/>
<field name="master_application_set_id" attrs="{'readonly': [('is_deployed', '=', True)]}"/>
<field name="is_master" />
<field name="repository_directory" attrs="{'readonly': [('is_deployed', '=', True)]}"/>
</group>
<group name="group_applications" string="Applications">
Expand Down

0 comments on commit c101f81

Please sign in to comment.