12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- from os import path
15
+
16
16
import re
17
17
import sys
18
-
19
- from six import iteritems
18
+ from os import path
20
19
21
20
import yaml
21
+ from six import iteritems
22
22
23
23
from kubernetes import client
24
24
25
+
25
26
def create_from_yaml (k8s_client , yaml_file , verbose = False , ** kwargs ):
26
27
"""
27
28
Perform an action from a yaml file. Pass True for verbose to
28
29
print confirmation information.
29
-
30
30
Input:
31
31
yaml_file: string. Contains the path to yaml file.
32
32
k8s_cline: an ApiClient object, initialized with the client args.
@@ -40,7 +40,7 @@ def create_from_yaml(k8s_client, yaml_file, verbose=False, **kwargs):
40
40
41
41
with open (path .abspath (yaml_file )) as f :
42
42
yml_object = yaml .load (f )
43
- #TODO: case of yaml file containing multiple objects
43
+ # TODO: case of yaml file containing multiple objects
44
44
group , _ , version = yml_object ["apiVersion" ].partition ("/" )
45
45
if version == "" :
46
46
version = group
@@ -49,7 +49,7 @@ def create_from_yaml(k8s_client, yaml_file, verbose=False, **kwargs):
49
49
# Only replace the last instance
50
50
group = "" .join (group .rsplit (".k8s.io" , 1 ))
51
51
fcn_to_call = "{0}{1}Api" .format (group .capitalize (),
52
- version .capitalize ())
52
+ version .capitalize ())
53
53
k8s_api = getattr (client , fcn_to_call )(k8s_client )
54
54
# Replace CamelCased action_type into snake_case
55
55
kind = yml_object ["kind" ]
@@ -71,4 +71,3 @@ def create_from_yaml(k8s_client, yaml_file, verbose=False, **kwargs):
71
71
if verbose :
72
72
print ("{0} created. status='{1}'" .format (kind , str (resp .status )))
73
73
return k8s_api
74
-
0 commit comments