-
Notifications
You must be signed in to change notification settings - Fork 406
Permission claim fixes / cleanups #1745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of questions for myself to understand.
for k, v := range expectedLabels { | ||
if labels == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this inside the loop instead of at line 96?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because only here it is needed
u.SetLabels(labels) | ||
|
||
return nil | ||
|
||
} | ||
|
||
func (m *mutatingPermissionClaims) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) error { | ||
if a.GetSubresource() != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it always the case that we don't want to validate the labels the subresource?
I am unaware of a subresource that will let you change metadata, but I thought I would ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as admission is best effort in our case this should be safe, even if some day some other subresource is added that allows it (I doubt it).
labels[k] = v | ||
} | ||
|
||
u.SetLabels(labels) | ||
|
||
return nil | ||
|
||
} | ||
|
||
func (m *mutatingPermissionClaims) Validate(ctx context.Context, a admission.Attributes, o admission.ObjectInterfaces) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure we can remove this function entirely, given that Admit sets everything we're validating here. Right?
labels := obj.GetLabels() | ||
if labels == nil { | ||
labels = make(map[string]string) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
background for this commit: it is not good to depend on nil-vs-empty behaviour of LabelsFor
.
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Extracted from https://github.com/kcp-dev/kcp/pull/1563/commits.