Skip to content

Ensure that domain UID from domain name conforms to DNS-1123 #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/main/python/wlsdeploy/tool/util/k8s_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
29 changes: 29 additions & 0 deletions core/src/test/python/wlsdeploy/tool/util/k8s_helper_test.py
Original file line number Diff line number Diff line change
@@ -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()