File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 20
20
21
21
from kubernetes import client
22
22
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
+
23
26
24
27
def create_from_yaml (
25
28
k8s_client ,
@@ -155,8 +158,8 @@ def create_from_yaml_single_item(
155
158
k8s_api = getattr (client , fcn_to_call )(k8s_client )
156
159
# Replace CamelCased action_type into snake_case
157
160
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 ()
160
163
# Expect the user to create namespaced objects more often
161
164
if hasattr (k8s_api , "create_namespaced_{0}" .format (kind )):
162
165
# Decide which namespace we are going to put the object in,
You can’t perform that action at this time.
0 commit comments