diff --git a/core/src/main/python/wlsdeploy/tool/util/k8s_helper.py b/core/src/main/python/wlsdeploy/tool/util/k8s_helper.py index 105d5c523..a8937fcbe 100644 --- a/core/src/main/python/wlsdeploy/tool/util/k8s_helper.py +++ b/core/src/main/python/wlsdeploy/tool/util/k8s_helper.py @@ -5,6 +5,8 @@ Methods and constants for building Kubernetes resource files, including domain resource configuration for WebLogic Kubernetes Operator. """ +import re + from wlsdeploy.aliases import alias_utils from wlsdeploy.aliases.model_constants import CLUSTER from wlsdeploy.aliases.model_constants import DYNAMIC_CLUSTER_SIZE @@ -17,10 +19,14 @@ def get_domain_uid(domain_name): """ Determine the domain UID based on domain name. + The domain UID must be DNS-1123 compatible, with the pattern ^[a-z0-9-.]{1,253}$ :param domain_name: the domain name to be checked :return: the domain UID """ - return domain_name.lower() + result = domain_name.lower() + # replace any disallowed character with hyphen + result = re.sub('[^a-z0-9-.]', '-', result) + return result def get_server_count(cluster_name, cluster_values, model_dictionary): diff --git a/core/src/test/python/wlsdeploy/tool/util/k8s_helper_test.py b/core/src/test/python/wlsdeploy/tool/util/k8s_helper_test.py new file mode 100644 index 000000000..5c54e30f1 --- /dev/null +++ b/core/src/test/python/wlsdeploy/tool/util/k8s_helper_test.py @@ -0,0 +1,29 @@ +""" +Copyright (c) 2020, Oracle Corporation and/or its affiliates. +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +""" +import unittest + +from wlsdeploy.tool.util import k8s_helper + + +class K8sHelperTestCase(unittest.TestCase): + _program_name = 'k8s_helper_test' + _class_name = 'K8sHelperTestCase' + + def testDomainUidCompliant(self): + """ + Verify domain UID based on domain name is DNS-1123 compatible. + """ + self._check_uid("base_domain", "base-domain") + self._check_uid("My Domain", "my-domain") + self._check_uid("my.a#$^!z.domain", "my.a----z.domain") + self._check_uid("my.123.domain", "my.123.domain") + + def _check_uid(self, domain_name, expected_uid): + domain_uid = k8s_helper.get_domain_uid(domain_name) + self.assertEquals(expected_uid, domain_uid, "Domain UID for " + domain_name + " should be " + expected_uid) + + +if __name__ == '__main__': + unittest.main()