Skip to content

Commit 8066e43

Browse files
committed
temp
1 parent bb2ab97 commit 8066e43

File tree

7 files changed

+25
-30
lines changed

7 files changed

+25
-30
lines changed

apis/core/v1alpha1/iam_role_selector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type LabelSelector struct {
2525

2626
// IAMRoleSelectorSpec defines the desired state of IAMRoleSelector
2727
type NamespaceSelector struct {
28-
Names []string `json:"name"`
28+
Names []string `json:"names"`
2929
LabelSelector LabelSelector `json:"labelSelector,omitempty"`
3030
}
3131

@@ -40,6 +40,7 @@ type IAMRoleSelectorStatus struct{}
4040
// IAMRoleSelector is the schema for the IAMRoleSelector API.
4141
// +kubebuilder:object:root=true
4242
// +kubebuilder:subresource:status
43+
// +kubebuilder:resource:scope=Cluster
4344
type IAMRoleSelector struct {
4445
metav1.TypeMeta `json:",inline"`
4546
metav1.ObjectMeta `json:"metadata,omitempty"`

apis/core/v1alpha1/resource_metadata.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ 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+
36+
IAMRoleSelector *SelectedIAMRole `json:"iamRoleSelector"`
37+
}
38+
39+
type SelectedIAMRole struct {
40+
SelectorName string `json:"selectorName"`
41+
ResourceVersion string `json:"resourceVersion"`
3542
}

apis/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/services.k8s.aws_iamroleselectors.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.2
6+
controller-gen.kubebuilder.io/version: v0.19.0
77
name: iamroleselectors.services.k8s.aws
88
spec:
99
group: services.k8s.aws
@@ -12,7 +12,7 @@ spec:
1212
listKind: IAMRoleSelectorList
1313
plural: iamroleselectors
1414
singular: iamroleselector
15-
scope: Namespaced
15+
scope: Cluster
1616
versions:
1717
- name: v1alpha1
1818
schema:
@@ -53,12 +53,12 @@ spec:
5353
required:
5454
- matchLabels
5555
type: object
56-
name:
56+
names:
5757
items:
5858
type: string
5959
type: array
6060
required:
61-
- name
61+
- names
6262
type: object
6363
resourceTypeSelector:
6464
items:

pkg/runtime/iamroleselector/cache.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package iamroleselector
1515

1616
import (
17-
"context"
1817
"fmt"
1918
"sync"
2019

@@ -204,7 +203,7 @@ func (c *Cache) ListSelectors() []*ackv1alpha1.IAMRoleSelector {
204203

205204
// Matches returns a list of IAMRoleSelectors that match the given resource. This function
206205
// should only be called after the cache has been started and synced.
207-
func (c *Cache) Matches(ctx context.Context, resource runtime.Object) ([]*ackv1alpha1.IAMRoleSelector, error) {
206+
func (c *Cache) Matches(resource runtime.Object) ([]*ackv1alpha1.IAMRoleSelector, error) {
208207
// Extract metadata from the resource
209208
metaObj, err := meta.Accessor(resource)
210209
if err != nil {

pkg/runtime/reconciler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (r *resourceReconciler) Reconcile(ctx context.Context, req ctrlrt.Request)
216216
}
217217
return ctrlrt.Result{}, err
218218
}
219+
latest := desired.DeepCopy()
219220

220221
rlog := ackrtlog.NewResourceLogger(
221222
r.log, desired,
@@ -272,7 +273,6 @@ func (r *resourceReconciler) Reconcile(ctx context.Context, req ctrlrt.Request)
272273
// are any matching IAMRoleSelectors for this resource. If there are, we
273274
// override the roleARN from CARM (if any) with the one from the selector.
274275
selectors, err := r.irsCache.Matches(
275-
ctx,
276276
desired.RuntimeObject(),
277277
)
278278
if err != nil {
@@ -349,7 +349,7 @@ func (r *resourceReconciler) Reconcile(ctx context.Context, req ctrlrt.Request)
349349
if err != nil {
350350
return ctrlrt.Result{}, err
351351
}
352-
latest, err := r.reconcile(ctx, rm, desired)
352+
latest, err = r.reconcile(ctx, rm, desired)
353353
return r.HandleReconcileError(ctx, desired, latest, err)
354354
}
355355

@@ -374,7 +374,7 @@ func (r *resourceReconciler) regionDrifted(desired acktypes.AWSResource) bool {
374374

375375
// look for default region in namespace metadata annotations
376376
ns := desired.MetaObject().GetNamespace()
377-
nsRegion, ok := r.cache.Namespaces.GetDefaultRegion(ns)
377+
nsRegion, ok := r.carmCache.Namespaces.GetDefaultRegion(ns)
378378
if ok {
379379
return ackv1alpha1.AWSRegion(nsRegion) != *currentRegion
380380
}
@@ -1225,6 +1225,7 @@ func (r *resourceReconciler) getAWSResource(
12251225
if err := r.apiReader.Get(ctx, req.NamespacedName, ro); err != nil {
12261226
return nil, err
12271227
}
1228+
ro.GetObjectKind().SetGroupVersionKind(r.rd.GroupVersionKind())
12281229
return r.rd.ResourceFromRuntimeObject(ro), nil
12291230
}
12301231

pkg/runtime/reconciler_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func TestReconcilerReadOnlyResource(t *testing.T) {
331331
rm.On("IsSynced", ctx, latest).Return(true, nil)
332332
rmf, rd := managedResourceManagerFactoryMocks(desired, latest)
333333
rd.On("Delta", desired, latest).Return(ackcompare.NewDelta())
334-
334+
335335
r, kc, scmd := reconcilerMocks(rmf)
336336
rm.On("EnsureTags", ctx, desired, scmd).Return(nil)
337337
statusWriter := &ctrlrtclientmock.SubResourceWriter{}
@@ -1914,12 +1914,12 @@ func TestReconcile_AccountDrifted(t *testing.T) {
19141914
// Create reconciler with namespace cache
19151915
r := &resourceReconciler{
19161916
reconciler: reconciler{
1917-
kc: kc,
1918-
sc: sc,
1919-
log: fakeLogger,
1920-
cfg: ackcfg.Config{AccountID: "333333333333"},
1921-
cache: caches,
1922-
metrics: ackmetrics.NewMetrics("test"),
1917+
kc: kc,
1918+
sc: sc,
1919+
log: fakeLogger,
1920+
cfg: ackcfg.Config{AccountID: "333333333333"},
1921+
carmCache: caches,
1922+
metrics: ackmetrics.NewMetrics("test"),
19231923
},
19241924
rmf: rmf,
19251925
rd: rd,

0 commit comments

Comments
 (0)