You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate resource identifiers from ReadOne or ReadMany (#105)
Issue #, if available: aws-controllers-k8s/community#842
Description of changes:
This pull request introduces a smarter system for detecting resource primary identifiers by using the fields from the `ReadOne` (or optionally `ReadMany`) operations.
It detects if a field is attempting to use the resource ARN and will set the status metadata to the corresponding identifier element. Otherwise, it will search through each of the required fields in the operation to attempt to identify the "primary" identifier field (such as `*Name`, `Name`, `*ID`). All other fields in the operation can be configured through the use of the new `AdditionalKeys` map (https://github.com/aws-controllers-k8s/runtime/pull/13/files). Optionally, the primary identifier field can be configured in the generator under `operations.<operation>.primary_identifier_field_name` if one cannot be (or is incorrectly) identified.
Example output from `applicationautoscaling` `ScalingPolicy`:
```golang
func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
if identifier.NameOrID == nil {
return ackerrors.MissingNameIdentifier
}
r.ko.Spec.ResourceID = identifier.NameOrID
f0, f0ok := identifier.AdditionalKeys["scalableDimension"]
if f0ok {
r.ko.Spec.ScalableDimension = f0
}
f1, f1ok := identifier.AdditionalKeys["serviceNamespace"]
if f1ok {
r.ko.Spec.ServiceNamespace = f1
}
return nil
}
```
Example output from `mq` `Broker`:
```golang
func (r *resource) SetIdentifiers(identifier *ackv1alpha1.AWSIdentifiers) error {
if identifier.NameOrID == nil {
return ackerrors.MissingNameIdentifier
}
r.ko.Status.BrokerID = identifier.NameOrID
return nil
}
```
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
0 commit comments