APPSRE-13008: added typed queries for clusterrolebinding#5315
Open
mehfuz wants to merge 6 commits intoapp-sre:masterfrom
Open
APPSRE-13008: added typed queries for clusterrolebinding#5315mehfuz wants to merge 6 commits intoapp-sre:masterfrom
mehfuz wants to merge 6 commits intoapp-sre:masterfrom
Conversation
chassing
reviewed
Dec 4, 2025
| @@ -0,0 +1,23 @@ | |||
| # qenerate: plugin=pydantic_v2 | |||
| query AppInterfaceClusterRoles { | |||
| clusterRoles: roles_v1 { | |||
Member
There was a problem hiding this comment.
Fix indentation:
Suggested change
| clusterRoles: roles_v1 { | |
| clusterRoles: roles_v1 { |
chassing
reviewed
Dec 4, 2025
| resource_name: str | ||
|
|
||
|
|
||
| @dataclass |
Member
There was a problem hiding this comment.
Could you please not mix dataclasses and Pydantic models? Just use a basemodel here too; you don't need to set arbitrary_types_allowed=True below.
chassing
reviewed
Dec 4, 2025
| sa_name: str | ||
|
|
||
| @classmethod | ||
| def create_sa_spec(cls, bots: list[BotV1] | None) -> list[Self]: |
Member
There was a problem hiding this comment.
Suggested change
| def create_sa_spec(cls, bots: list[BotV1] | None) -> list[Self]: | |
| def create_sa_spec(cls, bots: Iterable[BotV1] | None) -> list[Self]: |
|
|
||
| @staticmethod | ||
| def get_usernames_from_users_and_cluster( | ||
| users: list[UserV1], cluster: ClusterV1 |
Member
There was a problem hiding this comment.
Suggested change
| users: list[UserV1], cluster: ClusterV1 | |
| users: Iterable[UserV1], cluster: ClusterV1 |
hemslo
reviewed
Dec 5, 2025
Comment on lines
+102
to
+159
| def test_get_oc_resources() -> None: | ||
| test_clusterrole = get_app_interface_test_clusterroles() | ||
| cluster_role_binding_spec_list = ( | ||
| ClusterRoleBindingSpec.create_cluster_role_binding_specs(test_clusterrole[0]) | ||
| ) | ||
| oc_resources = cluster_role_binding_spec_list[0].get_oc_resources() | ||
| assert len(oc_resources) == 2 | ||
| assert oc_resources[0] == OCResource( | ||
| resource=OR( | ||
| integration="openshift-clusterrolebindings", | ||
| integration_version="0.1.0", | ||
| error_details="test-clusterrole5-test-org-user", | ||
| body={ | ||
| "kind": "ClusterRoleBinding", | ||
| "apiVersion": "rbac.authorization.k8s.io/v1", | ||
| "metadata": { | ||
| "name": "test-clusterrole5-test-org-user", | ||
| }, | ||
| "roleRef": { | ||
| "kind": "ClusterRole", | ||
| "name": "test-clusterrole5", | ||
| }, | ||
| "subjects": [ | ||
| { | ||
| "kind": "User", | ||
| "name": "test-org-user", | ||
| } | ||
| ], | ||
| }, | ||
| ), | ||
| resource_name="test-clusterrole5-test-org-user", | ||
| ) | ||
| assert oc_resources[1] == OCResource( | ||
| resource=OR( | ||
| integration="openshift-clusterrolebindings", | ||
| integration_version="0.1.0", | ||
| error_details="test-clusterrole5-test-namespace5-test-serviceaccount", | ||
| body={ | ||
| "apiVersion": "rbac.authorization.k8s.io/v1", | ||
| "kind": "ClusterRoleBinding", | ||
| "metadata": { | ||
| "name": "test-clusterrole5-test-namespace5-test-serviceaccount", | ||
| }, | ||
| "roleRef": { | ||
| "kind": "ClusterRole", | ||
| "name": "test-clusterrole5", | ||
| }, | ||
| "subjects": [ | ||
| { | ||
| "kind": "ServiceAccount", | ||
| "name": "test-serviceaccount", | ||
| "namespace": "test-namespace5", | ||
| }, | ||
| ], | ||
| }, | ||
| ), | ||
| resource_name="test-clusterrole5-test-namespace5-test-serviceaccount", | ||
| ) |
Contributor
There was a problem hiding this comment.
can we simplify test case to test one oc resource in one test case? can use pytest.mark.parametrize
Comment on lines
+184
to
+195
| if allowed_clusters is not None and not allowed_clusters: | ||
| return None | ||
| cluster_roles: list[RoleV1] = expiration.filter(get_app_interface_clusterroles()) | ||
| clusters_to_check = allowed_clusters or set() | ||
| cluster_role_binding_specs = [ | ||
| cluster_role_binding_spec | ||
| for cluster_role in cluster_roles | ||
| for cluster_role_binding_spec in ClusterRoleBindingSpec.create_cluster_role_binding_specs( | ||
| cluster_role | ||
| ) | ||
| if cluster_role_binding_spec.cluster.name in clusters_to_check | ||
| ] |
Contributor
There was a problem hiding this comment.
when allowed_clusters is None, means no filter, cluster_role_binding_specs here will be empty, expected?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This MR refactors the openshift-clusterrolebindings integration to use type-safe GraphQL queries including testcases.