Skip to content

Commit 52c5988

Browse files
committed
Add classes for ClusterRole and ClusterRoleBinding objects
Signed-off-by: averevki <[email protected]>
1 parent 9606102 commit 52c5988

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

testsuite/kubernetes/cluster_role.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""ClusterRole and ClusterRoleBinding objects for Kubernetes"""
2+
3+
from typing import Any
4+
from testsuite.kubernetes import KubernetesObject
5+
6+
7+
class ClusterRole(KubernetesObject):
8+
"""Kubernetes ClusterRole"""
9+
10+
@classmethod
11+
def create_instance(
12+
cls,
13+
cluster,
14+
name,
15+
rules: list[dict[str, Any]] = None,
16+
labels: dict[str, str] = None,
17+
):
18+
"""Creates a new ClusterRole instance"""
19+
model: dict = {
20+
"kind": "ClusterRole",
21+
"apiVersion": "rbac.authorization.k8s.io/v1",
22+
"metadata": {
23+
"name": name,
24+
"labels": labels,
25+
},
26+
"rules": rules,
27+
}
28+
return cls(model, context=cluster.context)
29+
30+
31+
class ClusterRoleBinding(KubernetesObject):
32+
"""Kubernetes ClusterRoleBinding"""
33+
34+
@classmethod
35+
def create_instance(
36+
cls,
37+
cluster,
38+
name,
39+
cluster_role: str,
40+
serviceaccounts: list[str],
41+
labels: dict[str, str] = None,
42+
):
43+
"""Creates a new ClusterRoleBinding object"""
44+
model: dict = {
45+
"kind": "ClusterRoleBinding",
46+
"apiVersion": "rbac.authorization.k8s.io/v1",
47+
"metadata": {
48+
"name": name,
49+
"labels": labels,
50+
},
51+
"roleRef": {
52+
"kind": "ClusterRole",
53+
"name": cluster_role,
54+
},
55+
"subjects": [
56+
{"kind": "ServiceAccount", "name": name, "namespace": cluster.project} for name in serviceaccounts
57+
],
58+
}
59+
return cls(model, context=cluster.context)

0 commit comments

Comments
 (0)