File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,20 @@ def test_create_namespace_from_yaml(self):
9999 self .assertIsNotNone (nmsp )
100100 core_api .delete_namespace (name = "development" , body = {})
101101
102+ def test_create_rbac_role_from_yaml (self ):
103+ """
104+ Should be able to create an rbac role.
105+ """
106+ k8s_client = client .api_client .ApiClient (configuration = self .config )
107+ utils .create_from_yaml (
108+ k8s_client , self .path_prefix + "rbac-role.yaml" )
109+ rbac_api = client .RbacAuthorizationV1Api (k8s_client )
110+ rbac_role = rbac_api .read_namespaced_role (
111+ name = "pod-reader" , namespace = "default" )
112+ self .assertIsNotNone (rbac_role )
113+ rbac_api .delete_namespaced_role (
114+ name = "pod-reader" , namespace = "default" , body = {})
115+
102116 def test_create_deployment_non_default_namespace_from_yaml (self ):
103117 """
104118 Should be able to create a namespace "dep",
Original file line number Diff line number Diff line change 1+ kind : Role
2+ apiVersion : rbac.authorization.k8s.io/v1
3+ metadata :
4+ namespace : default
5+ name : pod-reader
6+ rules :
7+ - apiGroups : [""] # "" indicates the core API group
8+ resources : ["pods"]
9+ verbs : ["get", "watch", "list"]
Original file line number Diff line number Diff line change @@ -97,8 +97,10 @@ def create_from_yaml_single_item(
9797 # Take care for the case e.g. api_type is "apiextensions.k8s.io"
9898 # Only replace the last instance
9999 group = "" .join (group .rsplit (".k8s.io" , 1 ))
100- fcn_to_call = "{0}{1}Api" .format (group .capitalize (),
101- version .capitalize ())
100+ # convert group name from DNS subdomain format to
101+ # python class name convention
102+ group = "" .join (word .capitalize () for word in group .split ('.' ))
103+ fcn_to_call = "{0}{1}Api" .format (group , version .capitalize ())
102104 k8s_api = getattr (client , fcn_to_call )(k8s_client )
103105 # Replace CamelCased action_type into snake_case
104106 kind = yml_object ["kind" ]
You can’t perform that action at this time.
0 commit comments