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 5
5
Methods and constants for building Kubernetes resource files,
6
6
including domain resource configuration for WebLogic Kubernetes Operator.
7
7
"""
8
+ import re
9
+
8
10
from wlsdeploy .aliases import alias_utils
9
11
from wlsdeploy .aliases .model_constants import CLUSTER
10
12
from wlsdeploy .aliases .model_constants import DYNAMIC_CLUSTER_SIZE
17
19
def get_domain_uid (domain_name ):
18
20
"""
19
21
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}$
20
23
:param domain_name: the domain name to be checked
21
24
:return: the domain UID
22
25
"""
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
24
30
25
31
26
32
def 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