Skip to content

Commit

Permalink
Add rbac support for yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
micw523 committed Mar 20, 2019
1 parent 84c057b commit 17c9048
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
14 changes: 14 additions & 0 deletions kubernetes/e2e_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def test_create_namespace_from_yaml(self):
self.assertIsNotNone(nmsp)
core_api.delete_namespace(name="development", body={})

def test_create_rbac_role_from_yaml(self):
"""
Should be able to create an rbac role.
"""
k8s_client = client.api_client.ApiClient(configuration=self.config)
utils.create_from_yaml(
k8s_client, self.path_prefix + "rbac-role.yaml")
rbac_api = client.RbacAuthorizationV1Api(k8s_client)
rbac_role = rbac_api.read_namespaced_role(
name="pod-reader", namespace="default")
self.assertIsNotNone(rbac_role)
rbac_api.delete_namespaced_role(
name="pod-reader", namespace="default", body={})

def test_create_deployment_non_default_namespace_from_yaml(self):
"""
Should be able to create a namespace "dep",
Expand Down
9 changes: 9 additions & 0 deletions kubernetes/e2e_test/test_yaml/rbac-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
5 changes: 3 additions & 2 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def create_from_yaml_single_item(
# Take care for the case e.g. api_type is "apiextensions.k8s.io"
# Only replace the last instance
group = "".join(group.rsplit(".k8s.io", 1))
fcn_to_call = "{0}{1}Api".format(group.capitalize(),
version.capitalize())
# convert group name from DNS subdomain format to python class name convention
group = "".join(word.capitalize() for word in group.split('.'))
fcn_to_call = "{0}{1}Api".format(group, version.capitalize())
k8s_api = getattr(client, fcn_to_call)(k8s_client)
# Replace CamelCased action_type into snake_case
kind = yml_object["kind"]
Expand Down

0 comments on commit 17c9048

Please sign in to comment.