Skip to content

Commit c55035b

Browse files
authored
JIRA WDT-453 - Ensure that domain UID from domain name conforms to DNS-1123 (#701)
1 parent ab40870 commit c55035b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

core/src/main/python/wlsdeploy/tool/util/k8s_helper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Methods and constants for building Kubernetes resource files,
66
including domain resource configuration for WebLogic Kubernetes Operator.
77
"""
8+
import re
9+
810
from wlsdeploy.aliases import alias_utils
911
from wlsdeploy.aliases.model_constants import CLUSTER
1012
from wlsdeploy.aliases.model_constants import DYNAMIC_CLUSTER_SIZE
@@ -17,10 +19,14 @@
1719
def get_domain_uid(domain_name):
1820
"""
1921
Determine the domain UID based on domain name.
22+
The domain UID must be DNS-1123 compatible, with the pattern ^[a-z0-9-.]{1,253}$
2023
:param domain_name: the domain name to be checked
2124
:return: the domain UID
2225
"""
23-
return domain_name.lower()
26+
result = domain_name.lower()
27+
# replace any disallowed character with hyphen
28+
result = re.sub('[^a-z0-9-.]', '-', result)
29+
return result
2430

2531

2632
def get_server_count(cluster_name, cluster_values, model_dictionary):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
import unittest
6+
7+
from wlsdeploy.tool.util import k8s_helper
8+
9+
10+
class K8sHelperTestCase(unittest.TestCase):
11+
_program_name = 'k8s_helper_test'
12+
_class_name = 'K8sHelperTestCase'
13+
14+
def testDomainUidCompliant(self):
15+
"""
16+
Verify domain UID based on domain name is DNS-1123 compatible.
17+
"""
18+
self._check_uid("base_domain", "base-domain")
19+
self._check_uid("My Domain", "my-domain")
20+
self._check_uid("my.a#$^!z.domain", "my.a----z.domain")
21+
self._check_uid("my.123.domain", "my.123.domain")
22+
23+
def _check_uid(self, domain_name, expected_uid):
24+
domain_uid = k8s_helper.get_domain_uid(domain_name)
25+
self.assertEquals(expected_uid, domain_uid, "Domain UID for " + domain_name + " should be " + expected_uid)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

0 commit comments

Comments
 (0)