-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Added namespace prefix to application sets to be able to deploy…
… to different namespaces.
- Loading branch information
1 parent
2d776ed
commit a648e7f
Showing
13 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<odoo noupdate="1"> | ||
<record id="namespace_prefix_flavoured_odoo" model="argocd.application.namespace.prefix"> | ||
<field name="name">flavoured-odoo-</field> | ||
</record> | ||
<record id="namespace_prefix_application_set" model="argocd.application.namespace.prefix"> | ||
<field name="name">application-set-</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import re | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ApplicationNamespacePrefix(models.Model): | ||
_name = "argocd.application.namespace.prefix" | ||
_description = "Application Namespace Prefix" | ||
|
||
name = fields.Char(required=True) | ||
|
||
_sql_constraints = [ | ||
("application_namespace_name_prefix_unique", "unique(name)", "Already exists"), | ||
( | ||
"app_namespace_prefix_unique", | ||
"unique(name)", | ||
"A namespace prefix with that name was already defined.", | ||
), | ||
] | ||
|
||
@api.constrains("name") | ||
def _constrain_name(self): | ||
if not re.match( | ||
"^[a-z0-9-]{1,100}$", self.name | ||
): # lowercase a to z, 0 to 9 and - (dash) are allowed | ||
raise ValidationError( | ||
_( | ||
"Only lowercase letters, numbers and dashes are allowed in the name (max 100 characters)." | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import test_application | ||
from . import test_application_set | ||
from . import test_application_tag | ||
from . import test_application_namespace_prefix |
24 changes: 24 additions & 0 deletions
24
argocd_deployer/tests/test_application_namespace_prefix.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestApplicationNamespacePrefix(TransactionCase): | ||
def test_name(self): | ||
"""Name may only contain lowercase letters, digits and underscores.""" | ||
with self.assertRaisesRegex( | ||
ValidationError, "Only lowercase letters, numbers and dashes" | ||
): | ||
self.env["argocd.application.namespace.prefix"].create({"name": "Hello"}) | ||
|
||
with self.assertRaisesRegex(ValidationError, "max 100 characters"): | ||
self.env["argocd.application.namespace.prefix"].create( | ||
{ | ||
"name": "this-name-is-waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay-" | ||
"toooooooooooooooooooooo-ridiculously-long-and should-" | ||
"totally-not-be-allowed" | ||
} | ||
) | ||
|
||
self.env["argocd.application.namespace.prefix"].create( | ||
{"name": "hello-the-namespace"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from unittest.mock import MagicMock, mock_open, patch | ||
|
||
from odoo.exceptions import UserError | ||
from odoo.exceptions import UserError, ValidationError | ||
from odoo.tests import TransactionCase | ||
|
||
APPLICATION_SET_PATCH = ( | ||
|
@@ -25,6 +25,8 @@ def setUpClass(cls): | |
revision: {{.config.branch}} | ||
path: {{.config.deployment_directory}} | ||
template-path: {{.path.path}} | ||
destination: | ||
namespace: {{.application_set.namespace_prefix}}{{.path.basename}} | ||
""", | ||
} | ||
) | ||
|
@@ -36,6 +38,9 @@ def setUpClass(cls): | |
"template_id": cls.application_set_template.id, | ||
"repository_directory": "/home/test", | ||
"deployment_directory": "instances", | ||
"namespace_prefix_id": cls.env.ref( | ||
"argocd_deployer.namespace_prefix_application_set" | ||
).id, | ||
} | ||
) | ||
|
||
|
@@ -53,8 +58,47 @@ def setUpClass(cls): | |
revision: {cls.master_application_set.branch} | ||
path: {cls.master_application_set.deployment_directory} | ||
template-path: {{{{.path.path}}}} | ||
destination: | ||
namespace: application-set-{{{{.path.basename}}}} | ||
""" | ||
|
||
def test_name(self): | ||
"""Name may only contain lowercase letters, digits and underscores.""" | ||
params = { | ||
"template_id": self.env.ref( | ||
"argocd_deployer.application_set_template_default" | ||
).id, | ||
"repository_url": "[email protected]:odoo/odoo-no-exist.git", | ||
"repository_directory": "/home/test", | ||
} | ||
|
||
with self.assertRaisesRegex( | ||
ValidationError, "Only lowercase letters, numbers and dashes" | ||
): | ||
self.env["argocd.application.set"].create( | ||
{ | ||
**params, | ||
"name": "Hello", | ||
} | ||
) | ||
|
||
with self.assertRaisesRegex(ValidationError, "max 100 characters"): | ||
self.env["argocd.application.set"].create( | ||
{ | ||
**params, | ||
"name": "this-name-is-waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay-" | ||
"toooooooooooooooooooooo-ridiculously-long-and should-" | ||
"totally-not-be-allowed", | ||
} | ||
) | ||
|
||
self.env["argocd.application.set"].create( | ||
{ | ||
**params, | ||
"name": "hello-the-namespace", | ||
} | ||
) | ||
|
||
def test_get_master_repository_directory(self): | ||
"""The master repository directory is stored in the config. | ||
Check that it behaves.""" | ||
|
18 changes: 18 additions & 0 deletions
18
argocd_deployer/views/application_namespace_prefix_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="application_namespace_prefix_tree" model="ir.ui.view"> | ||
<field name="model">argocd.application.namespace.prefix</field> | ||
<field name="arch" type="xml"> | ||
<tree editable="bottom"> | ||
<field name="name" /> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="application_namespace_prefix_action" model="ir.actions.act_window"> | ||
<field name="name">Namespace prefixes</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">argocd.application.namespace.prefix</field> | ||
<field name="view_mode">tree</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters