Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

SelfSubjectAccessReviews now work with the k8s module #237

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- include_tasks: tasks/exec.yml
- include_tasks: tasks/log.yml
- include_tasks: tasks/cluster_info.yml
- include_tasks: tasks/access_review.yml

roles:
- helm
Expand Down
22 changes: 22 additions & 0 deletions molecule/default/tasks/access_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Create a SelfSubjectAccessReview resource
register: can_i_create_namespaces
ignore_errors: yes
k8s:
state: present
definition:
apiVersion: authorization.k8s.io/v1
kind: SelfSubjectAccessReview
spec:
resourceAttributes:
group: v1
resource: Namespace
verb: create

- name: Assert that the SelfSubjectAccessReview request succeded
assert:
that:
- can_i_create_namespaces is successful
- can_i_create_namespaces.result.status is defined
- can_i_create_namespaces.result.status.allowed is defined
- can_i_create_namespaces.result.status.allowed
4 changes: 2 additions & 2 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import (
ResourceNotFoundError, ResourceNotUniqueError, NotFoundError, DynamicApiError,
ConflictError, ForbiddenError)
ConflictError, ForbiddenError, MethodNotAllowedError)
HAS_K8S_MODULE_HELPER = True
k8s_import_exception = None
except ImportError as e:
Expand Down Expand Up @@ -610,7 +610,7 @@ def perform_action(self, resource, definition):
if namespace:
params['namespace'] = namespace
existing = resource.get(**params)
except NotFoundError:
except (NotFoundError, MethodNotAllowedError):
# Remove traceback so that it doesn't show up in later failures
try:
sys.exc_clear()
Expand Down