Skip to content

Commit bf63f59

Browse files
authored
Merge pull request #1390 from abhiabhi94/ref/utils
Refactor utils
2 parents f17076f + 44fe8bf commit bf63f59

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kubernetes/utils/create_from_yaml.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
from kubernetes import client
2222

23+
UPPER_FOLLOWED_BY_LOWER_RE = re.compile('(.)([A-Z][a-z]+)')
24+
LOWER_OR_NUM_FOLLOWED_BY_UPPER_RE = re.compile('([a-z0-9])([A-Z])')
25+
2326

2427
def create_from_yaml(
2528
k8s_client,
@@ -155,8 +158,8 @@ def create_from_yaml_single_item(
155158
k8s_api = getattr(client, fcn_to_call)(k8s_client)
156159
# Replace CamelCased action_type into snake_case
157160
kind = yml_object["kind"]
158-
kind = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', kind)
159-
kind = re.sub('([a-z0-9])([A-Z])', r'\1_\2', kind).lower()
161+
kind = UPPER_FOLLOWED_BY_LOWER_RE.sub(r'\1_\2', kind)
162+
kind = LOWER_OR_NUM_FOLLOWED_BY_UPPER_RE.sub(r'\1_\2', kind).lower()
160163
# Expect the user to create namespaced objects more often
161164
if hasattr(k8s_api, "create_namespaced_{0}".format(kind)):
162165
# Decide which namespace we are going to put the object in,

0 commit comments

Comments
 (0)