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 2020
2121from 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
2427def 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,
You can’t perform that action at this time.
0 commit comments