Skip to content

Commit fa6e794

Browse files
authored
Reorder account ID lookup in getOwnerAccountID (#153)
This commit changes the order of operations in the `getOwnerAccountID` function to prioritize checking namespace annotations over resource status when determining the owner account ID. The new order of checks is: 1. Namespace annotations 2. Resource status (`status.ackResourceMetadata`) 3. Controller's default AWS account By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a132c88 commit fa6e794

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pkg/runtime/reconciler.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -1054,14 +1054,14 @@ func (r *resourceReconciler) HandleReconcileError(
10541054
}
10551055

10561056
// getOwnerAccountID returns the AWS account that owns the supplied resource.
1057-
// The function looks to the common `Status.ACKResourceState` object, followed
1058-
// by the default AWS account ID associated with the Kubernetes Namespace in
1059-
// which the CR was created, followed by the AWS Account in which the IAM Role
1060-
// that the service controller is in.
1057+
// The function looks first to the default AWS account ID associated with the
1058+
// Kubernetes Namespace in which the CR was created, followed by the common
1059+
// `status.ackResourceMetadata` object, and finally the AWS Account in which the
1060+
// IAM Role that the service controller is in.
10611061
//
10621062
// This function is also returning a boolean stating whether the account ID
10631063
// is retrieved from the namespace annotations. This information is used to
1064-
// determine whether the a role ARN should be assumed to manage the resource,
1064+
// determine whether a role ARN should be assumed to manage the resource,
10651065
// which is typically found in the CARM ConfigMap.
10661066
//
10671067
// If the returned boolean is true, it means that the resource is owned by
@@ -1070,21 +1070,20 @@ func (r *resourceReconciler) HandleReconcileError(
10701070
func (r *resourceReconciler) getOwnerAccountID(
10711071
res acktypes.AWSResource,
10721072
) (ackv1alpha1.AWSAccountID, bool) {
1073-
controllerAccountID := ackv1alpha1.AWSAccountID(r.cfg.AccountID)
1074-
1075-
// look for owner account id in the resource status
1076-
acctID := res.Identifiers().OwnerAccountID()
1077-
if acctID != nil {
1078-
return *acctID, *acctID != controllerAccountID
1079-
}
1080-
10811073
// look for owner account id in the namespace annotations
10821074
namespace := res.MetaObject().GetNamespace()
10831075
accID, ok := r.cache.Namespaces.GetOwnerAccountID(namespace)
10841076
if ok {
10851077
return ackv1alpha1.AWSAccountID(accID), true
10861078
}
10871079

1080+
controllerAccountID := ackv1alpha1.AWSAccountID(r.cfg.AccountID)
1081+
// look for owner account id in the resource status
1082+
acctID := res.Identifiers().OwnerAccountID()
1083+
if acctID != nil {
1084+
return *acctID, *acctID != controllerAccountID
1085+
}
1086+
10881087
// use controller configuration
10891088
return controllerAccountID, false
10901089
}

0 commit comments

Comments
 (0)