From 7f5cb0201e3bb3f91bda25454403deead239207c Mon Sep 17 00:00:00 2001 From: Xianglong Wang Date: Fri, 22 Feb 2019 20:04:57 -0600 Subject: [PATCH] Add rbac support --- kubernetes/e2e_test/test_utils.py | 13 +++++++++++++ kubernetes/e2e_test/test_yaml/rbac-role.yaml | 9 +++++++++ kubernetes/utils/create_from_yaml.py | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 kubernetes/e2e_test/test_yaml/rbac-role.yaml diff --git a/kubernetes/e2e_test/test_utils.py b/kubernetes/e2e_test/test_utils.py index 9f63c35091..b54e1cc4aa 100644 --- a/kubernetes/e2e_test/test_utils.py +++ b/kubernetes/e2e_test/test_utils.py @@ -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", diff --git a/kubernetes/e2e_test/test_yaml/rbac-role.yaml b/kubernetes/e2e_test/test_yaml/rbac-role.yaml new file mode 100644 index 0000000000..404204d978 --- /dev/null +++ b/kubernetes/e2e_test/test_yaml/rbac-role.yaml @@ -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"] \ No newline at end of file diff --git a/kubernetes/utils/create_from_yaml.py b/kubernetes/utils/create_from_yaml.py index 2e61b677c5..5fac1c2934 100644 --- a/kubernetes/utils/create_from_yaml.py +++ b/kubernetes/utils/create_from_yaml.py @@ -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"]