File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
main/python/wlsdeploy/tool/util
test/python/wlsdeploy/tool/util Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 55Methods and constants for building Kubernetes resource files,
66including domain resource configuration for WebLogic Kubernetes Operator.
77"""
8+ import re
9+
810from wlsdeploy .aliases import alias_utils
911from wlsdeploy .aliases .model_constants import CLUSTER
1012from wlsdeploy .aliases .model_constants import DYNAMIC_CLUSTER_SIZE
1719def 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
2632def get_server_count (cluster_name , cluster_values , model_dictionary ):
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments