Skip to content

Commit

Permalink
Add rbac support
Browse files Browse the repository at this point in the history
  • Loading branch information
micw523 committed Feb 23, 2019
1 parent 7ab1b85 commit 7f5cb02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions kubernetes/e2e_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ 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", 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"]
4 changes: 2 additions & 2 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ 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())
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 7f5cb02

Please sign in to comment.