Skip to content

Commit

Permalink
Merge branch '16.0' into 16.0-project-snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap authored May 2, 2024
2 parents abeeef6 + 0134f3e commit 6a9a13e
Show file tree
Hide file tree
Showing 98 changed files with 8,958 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ jobs:
run: oca_init_test_database
env:
ADDONS_DIR: .,oca,third-party
EXCLUDE: mail_tracking,website_sale_subscription_restrict_cart,l10n_nl_rgs,l10n_nl_rgs_account_financial_report,l10n_nl_rgs_asset,l10n_nl_rgs_mis_report,connector_jira_servicedesk,connector_jira,account_statement_import_file_reconcile_oca,membership_subscription_prorate_variable_period,membership_subscription,membership_prorate,web_leaflet_technical,website_cache_control,account_reconcile_oca,membership_variable_period,base_user_role,account_invoice_constraint_chronology,queue_job,auth_signup_verify_email,base_municipality,argocd_capacity,membership_prorate_variable_period,argocd_website,l10n_nl_account_tax_unece,auditlog,product_contract,subscription_oca,account_banking_mandate_contact,account_banking_sepa_credit_transfer,hr_expense_remove_mobile_link,website_sale_analytics_matomo,mrp_multi_level,mrp_planned_order_matrix,mrp_warehouse_calendar,partner_country_default_nl,partner_external_map,base_menu_visibility_restriction,partner_firstname,password_security,contract,l10n_nl_tax_statement,l10n_nl_xaf_auditfile_export,mass_mailing_partner,mis_builder,website_local_font,helpdesk_mgmt,base_vat_optional_vies,mis_builder_budget
EXCLUDE: mail_tracking,website_sale_subscription_restrict_cart,l10n_nl_rgs,l10n_nl_rgs_account_financial_report,l10n_nl_rgs_asset,l10n_nl_rgs_mis_report,connector_jira_servicedesk,connector_jira,account_statement_import_file_reconcile_oca,membership_subscription_prorate_variable_period,membership_subscription,membership_prorate,web_leaflet_technical,website_cache_control,account_reconcile_oca,membership_variable_period,base_user_role,account_invoice_constraint_chronology,queue_job,auth_signup_verify_email,base_municipality,argocd_capacity,membership_prorate_variable_period,argocd_website,l10n_nl_account_tax_unece,auditlog,product_contract,subscription_oca,account_banking_mandate_contact,account_banking_sepa_credit_transfer,hr_expense_remove_mobile_link,website_sale_analytics_matomo,mrp_multi_level,mrp_planned_order_matrix,mrp_warehouse_calendar,partner_country_default_nl,partner_external_map,base_menu_visibility_restriction,partner_firstname,password_security,contract,l10n_nl_tax_statement,l10n_nl_xaf_auditfile_export,mass_mailing_partner,mis_builder,website_local_font,helpdesk_mgmt,base_vat_optional_vies,mis_builder_budget,nextcloud_odoo_sync
ODOO_VERSION: "16.0"
- name: Run tests
run: oca_run_tests
env:
ADDONS_DIR: .,oca,third-party
EXCLUDE: mail_tracking,website_sale_subscription_restrict_cart,l10n_nl_rgs,l10n_nl_rgs_account_financial_report,l10n_nl_rgs_asset,l10n_nl_rgs_mis_report,connector_jira_servicedesk,connector_jira,account_statement_import_file_reconcile_oca,membership_subscription_prorate_variable_period,membership_subscription,membership_prorate,web_leaflet_technical,website_cache_control,account_reconcile_oca,membership_variable_period,base_user_role,account_invoice_constraint_chronology,queue_job,auth_signup_verify_email,base_municipality,argocd_capacity,membership_prorate_variable_period,argocd_website,l10n_nl_account_tax_unece,auditlog,product_contract,subscription_oca,account_banking_mandate_contact,account_banking_sepa_credit_transfer,hr_expense_remove_mobile_link,website_sale_analytics_matomo,mrp_multi_level,mrp_planned_order_matrix,mrp_warehouse_calendar,partner_country_default_nl,partner_external_map,base_menu_visibility_restriction,partner_firstname,password_security,contract,l10n_nl_tax_statement,l10n_nl_xaf_auditfile_export,mass_mailing_partner,mis_builder,website_local_font,helpdesk_mgmt,base_vat_optional_vies,mis_builder_budget
EXCLUDE: mail_tracking,website_sale_subscription_restrict_cart,l10n_nl_rgs,l10n_nl_rgs_account_financial_report,l10n_nl_rgs_asset,l10n_nl_rgs_mis_report,connector_jira_servicedesk,connector_jira,account_statement_import_file_reconcile_oca,membership_subscription_prorate_variable_period,membership_subscription,membership_prorate,web_leaflet_technical,website_cache_control,account_reconcile_oca,membership_variable_period,base_user_role,account_invoice_constraint_chronology,queue_job,auth_signup_verify_email,base_municipality,argocd_capacity,membership_prorate_variable_period,argocd_website,l10n_nl_account_tax_unece,auditlog,product_contract,subscription_oca,account_banking_mandate_contact,account_banking_sepa_credit_transfer,hr_expense_remove_mobile_link,website_sale_analytics_matomo,mrp_multi_level,mrp_planned_order_matrix,mrp_warehouse_calendar,partner_country_default_nl,partner_external_map,base_menu_visibility_restriction,partner_firstname,password_security,contract,l10n_nl_tax_statement,l10n_nl_xaf_auditfile_export,mass_mailing_partner,mis_builder,website_local_font,helpdesk_mgmt,base_vat_optional_vies,mis_builder_budget,nextcloud_odoo_sync
ODOO_VERSION: "16.0"
- name: Prepare report
run: coverage xml -o coverage.xml --data-file .coverage
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ exclude: |
readme/.*\.(rst|md)$|
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)|
# Emesa: prevent "not used from manifest" for indirectly loaded test data
custom/addons/([^/]+)/test_data/
# Temporary modules
nextcloud_odoo_sync/
default_language_version:
python: python3
node: "16.17.0"
Expand Down
4 changes: 0 additions & 4 deletions argocd_deployer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ System parameters
-----------------
The following system parameters can be configured.

- ``argocd.application_set_repo``: Set to the SSH URL of the repository that stores the application sets.
- ``argocd.application_set_branch``: Set to the branch that contains the application sets. Should normally be HEAD or main.
- ``argocd.application_set_repo_directory``: The local folder that contains the .git folder of the repository that contains the application sets.
- ``argocd.application_set_deployment_directory``: The folder inside the repository that will contain the application sets.
- ``argocd.git_simulation_mode``: For debugging purposes. Can be set to values like ``none``, ``push``, ``pull``, ``push&pull``.
By setting one of these values, the corresponding git action will be skipped. This can prevent delays and repo clogging when doing manual
tests.
Expand Down
2 changes: 1 addition & 1 deletion argocd_deployer/data/application_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="repository_url">[email protected]:onesteinbv/flavoured-odoo-k8s.git</field>
<field name="branch">main</field>
<field name="repository_directory">/home/tarteo/repo</field>
<field name="deployment_directory"></field>
<field name="deployment_directory">application_sets</field>
<field name="template_id" ref="application_set_template_master"/>
<field name="is_master">True</field>
</record>
Expand Down
19 changes: 10 additions & 9 deletions argocd_deployer/data/application_set_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@
<record id="application_set_template_master" model="argocd.application.set.template">
<field name="name">Master application set template - Do not change</field>
<field name="yaml">apiVersion: argoproj.io/v1alpha1
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: curq-application-sets
name: curq-master-application-set
namespace: argocd
spec:
goTemplate: true
generators:
- git:
repoURL: {{.config.repository_url}}
revision: {{.config.branch}}
files:
- path: {{.config.deployment_directory}}
- git:
repoURL: {{.config.repository_url}}
revision: {{.config.branch}}
files:
- path: {{.config.deployment_directory}}/**/application_set.yaml
template:
metadata:
name: curq-application-sets
name: "application-set-{{ "{{ " }}.path.basename{{ " }}" }}"
spec:
project: "default"
source:
repoURL: {{.config.repository_url}}
targetRevision: {{.config.branch}}
path: {{.config.deployment_directory}}/{{ "{{ " }}.path.basename{{ " }}" }}
path: "{{ "{{ " }}.path.filename{{ " }}" }}"
destination:
name: in-cluster
namespace: argocd
namespace: "application-set-{{ "{{ " }}.path.basename{{ " }}" }}"
syncPolicy:
syncOptions:
- CreateNamespace=true
Expand Down
28 changes: 8 additions & 20 deletions argocd_deployer/data/ir_config_parameter_data.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="application_set_repo" model="ir.config_parameter">
<field name="key">argocd.application_set_repo</field>
<field name="value">[email protected]:onesteinbv/odoo-generator-k8s.git</field>
</record>
<record id="application_set_branch" model="ir.config_parameter">
<field name="key">argocd.application_set_branch</field>
<field name="value">main</field>
</record>
<record id="application_set_repo_directory" model="ir.config_parameter">
<field name="key">argocd.application_set_repo_directory</field>
<field name="value">/home/tarteo/repo</field>
</record>
<record id="application_set_deployment_directory" model="ir.config_parameter">
<field name="key">argocd.application_set_deployment_directory</field>
<field name="value">application_sets</field>
</record>
<record id="master_application_set_directory" model="ir.config_parameter">
<field name="key">argocd.master_application_set_directory</field>
<field name="value">application_set_deployment/templates</field>
</record>
<record id="application_set_destruction_delay" model="ir.config_parameter">
<field name="key">argocd.application_set_destruction_delay</field>
<field name="value">3600</field>
Expand All @@ -28,4 +8,12 @@
<field name="key">argocd.application_destruction_delay</field>
<field name="value">60</field>
</record>
<record id="git_simulation_mode" model="ir.config_parameter">
<field name="key">argocd.git_simulation_mode</field>
<field name="value">none</field>
</record>
<record id="allow_immediate_deployment" model="ir.config_parameter">
<field name="key">argocd.allow_immediate_deployment</field>
<field name="value" eval="'False'"/>
</record>
</odoo>
2 changes: 1 addition & 1 deletion argocd_deployer/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _render_description(self):

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

def get_urls(self):
self.ensure_one()
Expand Down
100 changes: 51 additions & 49 deletions argocd_deployer/models/application_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ class ApplicationSet(models.Model):

@api.constrains("deployment_directory")
def _check_deployment_directory(self):
if not self.is_master:
if not self.deployment_directory:
raise ValidationError("Deployment directory is required.")
if self.deployment_directory[-1] == "/":
raise ValidationError("Deployment directories should not end with '/'.")
else:
if self.deployment_directory:
raise ValidationError(
"The master deployment directory should be empty."
)
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):
Expand Down Expand Up @@ -123,60 +117,62 @@ def _create_path_or_error(path, directory_name, path_does_not_exist_action):

@api.model
def _get_master_repository_directory(self, path_does_not_exist_action="create"):
get_param = self.env["ir.config_parameter"].get_param
master = self.env.ref("argocd_deployer.application_set_master")
path = os.path.join(
get_param("argocd.application_set_repo_directory", ""),
get_param("argocd.application_set_branch", "master"),
master.repository_directory,
master.branch,
)
self._create_path_or_error(
path, "Master repository directory", path_does_not_exist_action
)
return path

@api.model
def _get_master_deployment_directory(self, path_does_not_exist_action="create"):
"""Return the directory the master application set lives."""
get_param = self.env["ir.config_parameter"].get_param
master = self.env.ref("argocd_deployer.application_set_master")
path = os.path.join(
self._get_master_repository_directory(path_does_not_exist_action),
get_param("argocd.master_application_set_directory", ""),
master.deployment_directory,
)
self._create_path_or_error(
path, "Master deployment directory", path_does_not_exist_action
)
return path

def _get_application_set_deployment_directory(
def _get_application_set_repository_directory(
self, path_does_not_exist_action="create"
):
"""Return the directory in which all application sets live."""
get_param = self.env["ir.config_parameter"].get_param
"""Return the directory in which the applications in the current application
set are located."""
self.ensure_one()
path = os.path.join(
self._get_master_repository_directory(path_does_not_exist_action),
get_param("argocd.application_set_deployment_directory", ""),
self.name,
self.repository_directory,
self.branch,
)
self._create_path_or_error(
path, "Application set deployment directory", path_does_not_exist_action
path, "Application set directory", path_does_not_exist_action
)
return path

def _get_application_set_repository_directory(
def _get_application_set_deployment_directory(
self, path_does_not_exist_action="create"
):
"""Return the directory in which the applications in the current application
set are located."""
"""Return the directory in which all application sets live."""
self.ensure_one()
path = os.path.join(
self.repository_directory,
self.branch,
self._get_master_deployment_directory(path_does_not_exist_action),
self.name,
)
self._create_path_or_error(
path, "Application set directory", path_does_not_exist_action
path, "Application set deployment directory", path_does_not_exist_action
)
return path

def _get_application_deployment_directory(
self, application_name, path_does_not_exist_action="create"
):
self.ensure_one()
path = os.path.join(
self._get_application_set_repository_directory(path_does_not_exist_action),
self.deployment_directory,
Expand All @@ -190,7 +186,8 @@ def _get_application_deployment_directory(
def _compute_is_deployed(self):
for app_set in self:
if app_set.is_master:
path = app_set._get_master_deployment_directory()
path = app_set._get_master_repository_directory("ignore")
path = os.path.join(path, "master_application_set/templates")
else:
path = app_set._get_application_set_deployment_directory("ignore")
path = os.path.join(
Expand Down Expand Up @@ -242,22 +239,19 @@ def _get_repository(self):
return Repo.clone_from(self.repository_url, directory)

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

def _format_commit_message(self, message):
return message % self.name

def _get_argocd_template(self):
get_param = self.env["ir.config_parameter"].get_param
master = self.env.ref("argocd_deployer.application_set_master")
replacements = {
"{{.config.repository_url}}": get_param("argocd.application_set_repo", "")
or "",
"{{.config.branch}}": get_param("argocd.application_set_branch", "master")
or "",
"{{.config.deployment_directory}}": get_param(
"argocd.application_set_deployment_directory", "application_sets"
)
or "",
"{{.config.repository_url}}": master.repository_url or "" or "",
"{{.config.branch}}": master.branch or "main",
"{{.config.deployment_directory}}": (
master.deployment_directory or "application_sets"
),
"{{.application_set.name}}": self.name or "",
"{{.application_set.repository_url}}": self.repository_url or "",
"{{.application_set.branch}}": self.branch or "",
Expand All @@ -270,16 +264,23 @@ def _get_argocd_template(self):
return template_yaml

def _create_master_application_set(self):
"""The master application set will be deployed in a master_application_set folder
in the root of the repository. There will be a templates folder in it, and a
Chart.yaml file."""
self.ensure_one()
template_yaml = self._get_argocd_template()
deployment_directory = self._get_master_deployment_directory("create")
application_set_dir = deployment_directory
yaml_file = os.path.join(application_set_dir, "application_set.yaml")
repo_dir = self._get_master_repository_directory("create")
application_set_dir = os.path.join(repo_dir, "master_application_set")
template_dir = os.path.join(application_set_dir, "templates")
if not os.path.exists(template_dir):
os.makedirs(template_dir)
message = "Added application set `%s`."

yaml_file = os.path.join(template_dir, "application_set.yaml")
with open(yaml_file, "w") as fh:
fh.write(template_yaml)

chart_file = os.path.join(application_set_dir, "..", "Chart.yaml")
chart_file = os.path.join(application_set_dir, "Chart.yaml")
with open(chart_file, "w") as fh:
fh.write(
f"""apiVersion: v2
Expand Down Expand Up @@ -308,14 +309,15 @@ def _create_application_set(self):
def _remove_master_application_set(self):
"""Remove an application set for ArgoCD."""
self.ensure_one()
deployment_directory = self._get_master_deployment_directory("error")
repo_dir = self._get_master_repository_directory("error")
application_set_dir = os.path.join(repo_dir, "master_application_set")
template_dir = os.path.join(application_set_dir, "templates")
message = "Removed application set `%s`."
application_set_dir = deployment_directory
yaml_file = os.path.join(application_set_dir, "application_set.yaml")
yaml_file = os.path.join(template_dir, "application_set.yaml")
chart_file = os.path.join(application_set_dir, "Chart.yaml")
os.remove(chart_file)
os.remove(yaml_file)
if not self.is_master:
os.removedirs(application_set_dir)
chart_file = os.path.join(application_set_dir, "..", "Chart.yaml")
os.removedirs(template_dir)

return {REMOVE_FILES: [yaml_file, chart_file]}, message

Expand Down
13 changes: 9 additions & 4 deletions argocd_deployer/models/application_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ class ApplicationTag(models.Model):

def get_domain_yaml_path(self, application_set=False):
self.ensure_one()
if not application_set:
return self.domain_yaml_path
if application_set.id in self.domain_override_ids.application_set_id.ids:
return self.domain_override_ids.filtered(
if (
not application_set
or application_set.id not in self.domain_override_ids.application_set_id.ids
):
return self.domain_yaml_path or ""
return (
self.domain_override_ids.filtered(
lambda do: do.application_set_id == application_set
).domain_yaml_path
or ""
)
1 change: 1 addition & 0 deletions argocd_deployer/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_application
from . import test_application_set
from . import test_application_tag
Loading

0 comments on commit 6a9a13e

Please sign in to comment.