Skip to content

refactor(kubernetes): export k.CanIUse func#775

Open
swghosh wants to merge 2 commits intocontainers:mainfrom
swghosh:ground-work-for-mg-34
Open

refactor(kubernetes): export k.CanIUse func#775
swghosh wants to merge 2 commits intocontainers:mainfrom
swghosh:ground-work-for-mg-34

Conversation

@swghosh
Copy link

@swghosh swghosh commented Feb 11, 2026

Certain downstream implementations (eg.) would want to call k.CanIUse in other packages outside pkg/kubernetes. CanIUse performs generic SubjectAccessReview calls to check if current user is authorized with certain resources, this is useful beyond the immediate package.

Also, added a fake Kube client that allows mocking the CanIUse func in other dependent packages.

xref: openshift#51 (comment)

Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
@swghosh
Copy link
Author

swghosh commented Feb 11, 2026

/cc @Cali0707 @matzew

@Cali0707 Cali0707 changed the title MG-34: Export k.CanIUse func refactor(kubernetes): export k.CanIUse func Feb 11, 2026
@Cali0707 Cali0707 requested review from manusa and matzew February 11, 2026 19:40
@swghosh swghosh force-pushed the ground-work-for-mg-34 branch from 46b2b7e to 09d2757 Compare February 11, 2026 19:56
Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
@swghosh swghosh force-pushed the ground-work-for-mg-34 branch from 09d2757 to e603ee1 Compare February 11, 2026 20:17
func (c *Core) canIUse(ctx context.Context, gvr *schema.GroupVersionResource, namespace, verb string) bool {
// CanIUse checks if the current user has permission to perform a specific verb on a resource.
// It uses SelfSubjectAccessReview to determine if the operation is allowed.
func (c *Core) CanIUse(ctx context.Context, gvr *schema.GroupVersionResource, namespace, verb string) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this file just exposes "crud" operations.

Not sure if for a public func we might want to move it else?
Before was private, which is different story

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any suggestions for a new package / existing package to place this func instea?

@manusa
Copy link
Member

manusa commented Feb 12, 2026

This has a slight overlap with #764

Not sure if we can extract this somewhere so that it can be reused by both, or if we can reuse what's added in #764 once we merge it (cc @nader-ziada)

@swghosh
Copy link
Author

swghosh commented Feb 16, 2026

@nader-ziada
Copy link
Collaborator

nader-ziada commented Feb 17, 2026

/close

@swghosh were you trying to close the PR? i don't think this command works in this repo

@manusa
Copy link
Member

manusa commented Feb 18, 2026

I added the closes ref to the other PR. This PR will be closed automatically when we merge the other one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments