-
Notifications
You must be signed in to change notification settings - Fork 181
IAMRoleSelector - support for resource label selector #222
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
base: main
Are you sure you want to change the base?
IAMRoleSelector - support for resource label selector #222
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zarko-a The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Hi @zarko-a. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@a-hilaly . This is based on our conversation here. Please take a look. For us, ability to do a cross account provisioning on an individual resource level is super important (not just based on namespace). Crossplane is able to do this by having multiple providers and it would great if this was merged so ACK could do the same. |
michaelhtm
left a comment
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.
great work @zarko-a 🚀
left a few nits below
| // Validate label selector | ||
| if len(nsSelector.LabelSelector.MatchLabels) > 0 { | ||
| for key := range nsSelector.LabelSelector.MatchLabels { | ||
| if key == "" { | ||
| return fmt.Errorf("label key cannot be empty") | ||
| } | ||
| // Kubernetes label values can be empty, so we don't validate value | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // validateResourceLabelSelector checks that the resource label selector has valid label keys | ||
| func validateResourceLabelSelector(labelSelector ackv1alpha1.LabelSelector) error { | ||
| if len(labelSelector.MatchLabels) > 0 { | ||
| for key := range labelSelector.MatchLabels { | ||
| if key == "" { | ||
| return fmt.Errorf("label key cannot be empty") | ||
| } | ||
| // Kubernetes label values can be empty, so we don't validate value | ||
| } | ||
| } | ||
| return 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.
nit: this seems to be repeated code..should we have some sort of helper function?
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.
or rename validateResourceLabelSelector to validateLabelSelector
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.
Good point. I've renamed the function to validateLabelSelector and changed validateNamespaceSelector to use the same helper.
Please see the latest commit.
| // If no label selector specified, matches all resources | ||
| if len(labelSelector.MatchLabels) == 0 { | ||
| return true | ||
| } | ||
|
|
||
| // Check if all specified labels match (AND logic within label selector) | ||
| selector := labels.SelectorFromSet(labelSelector.MatchLabels) | ||
| return selector.Matches(labels.Set(resourceLabels)) |
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.
nit: same here..we can rename this to matchesLabels?
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.
Done.
Please see the latest commit.
|
/ok-to-test |
|
@zarko-a: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Description of changes:
This PR adds the ability to select resources based on their labels in addition to namespace and resource type. The new
resourceLabelSelectorfield works identically to the existingnamespaceSelector.labelSelector- when specified, all labels must match (AND logic), and when omitted, all resources are matched. All selector conditions (namespace, resource type, and resource labels) are ANDed together.Idea for this change was mentioned here.
I built a custom image of IAM controller and I tested two scenarios:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.