Skip to content

Commit 46340f7

Browse files
a-hilalymichaelhtm
andauthored
feat: add IAMRoleSelector CRD/feature (#204)
* feat: add `IAMRoleSelector` CRD/feature Implements aws-controllers-k8s/community#2628 (mostly) Introduces a new IAMRoleSelector CRD that enables dynamic IAM role assignment based on namespace and resource type selectors. This feature provides an alternative to CARM for role selection and cannot be used simultaneously with CARM (enforced by validation). Key components: - New IAMRoleSelector CRD with namespace and resource type selectors - Selector matching logic with AND between selector types, OR within arrays - Dynamic informer-based cache for IAMRoleSelector resources - Integration into the reconciler to override CARM role selection - Alpha feature gate (IAMRoleSelector) defaulting to disabled Note: ResourceTypeSelector uses schema.GroupVersionKind in the API, which differs from the separate fields approach in the original types. This may need adjustment based on CRD generation requirements. * add IAMRoleSelected condition --------- Co-authored-by: michaelhtm <98621731+michaelhtm@users.noreply.github.com>
1 parent c101a18 commit 46340f7

19 files changed

+2078
-55
lines changed

apis/core/v1alpha1/conditions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ const (
6666
// "False" status indicates that the resource references failed to resolve.
6767
// For Ex: When referenced resource is in terminal condition
6868
ConditionTypeReferencesResolved ConditionType = "ACK.ReferencesResolved"
69+
// ConditionTypeIAMRoleSelected indicates whether an IAMRoleSelector has been selected
70+
// to manage the AWSResource. If none are selected, this condition will be removed
71+
// and we'll use the custom role to manage the AWSResource
72+
ConditionTypeIAMRoleSelected ConditionType = "ACK.IAMRoleSelected"
6973
)
7074

7175
// Condition is the common struct used by all CRDs managed by ACK service
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package v1alpha1
15+
16+
import (
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
)
19+
20+
// LabelSelector is a label query over a set of resources.
21+
type LabelSelector struct {
22+
MatchLabels map[string]string `json:"matchLabels"`
23+
}
24+
25+
// IAMRoleSelectorSpec defines the desired state of IAMRoleSelector
26+
type NamespaceSelector struct {
27+
Names []string `json:"names"`
28+
LabelSelector LabelSelector `json:"labelSelector,omitempty"`
29+
}
30+
31+
type GroupVersionKind struct {
32+
Group string `json:"group"`
33+
Version string `json:"version"`
34+
Kind string `json:"kind"`
35+
}
36+
37+
type IAMRoleSelectorSpec struct {
38+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable once set"
39+
ARN string `json:"arn"`
40+
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
41+
ResourceTypeSelector []GroupVersionKind `json:"resourceTypeSelector,omitempty"`
42+
}
43+
44+
type IAMRoleSelectorStatus struct{}
45+
46+
// IAMRoleSelector is the schema for the IAMRoleSelector API.
47+
// +kubebuilder:object:root=true
48+
// +kubebuilder:subresource:status
49+
// +kubebuilder:resource:scope=Cluster
50+
type IAMRoleSelector struct {
51+
metav1.TypeMeta `json:",inline"`
52+
metav1.ObjectMeta `json:"metadata,omitempty"`
53+
Spec IAMRoleSelectorSpec `json:"spec,omitempty"`
54+
Status IAMRoleSelectorStatus `json:"status,omitempty"`
55+
}
56+
57+
// +kubebuilder:object:root=true
58+
type IAMRoleSelectorList struct {
59+
metav1.TypeMeta `json:",inline"`
60+
metav1.ListMeta `json:"metadata,omitempty"`
61+
Items []IAMRoleSelector `json:"items"`
62+
}
63+
64+
func init() {
65+
SchemeBuilder.Register(&IAMRoleSelector{}, &IAMRoleSelectorList{})
66+
}

apis/core/v1alpha1/resource_metadata.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,15 @@ type ResourceMetadata struct {
3232
OwnerAccountID *AWSAccountID `json:"ownerAccountID"`
3333
// Region is the AWS region in which the resource exists or will exist.
3434
Region *AWSRegion `json:"region"`
35+
// IAMRoleSelector is the selected IAMRoleSelector that is used to manage
36+
// the AWS resource. This will be nil if the default controller role is used.
37+
IAMRoleSelector *SelectedIAMRole `json:"iamRoleSelector,omitempty"`
38+
}
39+
40+
type SelectedIAMRole struct {
41+
// SelectorName is the k8s resource name of the IAMRoleSelector object
42+
SelectorName string `json:"selectorName"`
43+
// ResourceVersion is the metadata.resourceVersion of the selected
44+
// IAMRoleSelector object
45+
ResourceVersion string `json:"resourceVersion"`
3546
}

apis/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 173 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.19.0
7+
name: iamroleselectors.services.k8s.aws
8+
spec:
9+
group: services.k8s.aws
10+
names:
11+
kind: IAMRoleSelector
12+
listKind: IAMRoleSelectorList
13+
plural: iamroleselectors
14+
singular: iamroleselector
15+
scope: Cluster
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: IAMRoleSelector is the schema for the IAMRoleSelector API.
21+
properties:
22+
apiVersion:
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
28+
type: string
29+
kind:
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
properties:
41+
arn:
42+
type: string
43+
x-kubernetes-validations:
44+
- message: Value is immutable once set
45+
rule: self == oldSelf
46+
namespaceSelector:
47+
description: IAMRoleSelectorSpec defines the desired state of IAMRoleSelector
48+
properties:
49+
labelSelector:
50+
description: LabelSelector is a label query over a set of resources.
51+
properties:
52+
matchLabels:
53+
additionalProperties:
54+
type: string
55+
type: object
56+
required:
57+
- matchLabels
58+
type: object
59+
names:
60+
items:
61+
type: string
62+
type: array
63+
required:
64+
- names
65+
type: object
66+
resourceTypeSelector:
67+
items:
68+
properties:
69+
group:
70+
type: string
71+
kind:
72+
type: string
73+
version:
74+
type: string
75+
required:
76+
- group
77+
- kind
78+
- version
79+
type: object
80+
type: array
81+
required:
82+
- arn
83+
type: object
84+
status:
85+
type: object
86+
type: object
87+
served: true
88+
storage: true
89+
subresources:
90+
status: {}

0 commit comments

Comments
 (0)