-
Notifications
You must be signed in to change notification settings - Fork 226
Generate resource identifiers from ReadOne
or ReadMany
#105
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
Generate resource identifiers from ReadOne
or ReadMany
#105
Conversation
/retest |
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.
Looks good to me. Just one comment above about secret.
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.
LGTM Over all!
Left few comments bellow
Nice! 👍 |
// r.ko.Status.BrokerID = identifier.NameOrID | ||
primaryKeyOut += fmt.Sprintf("%s%s.%s.%s = %s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName) | ||
} else { | ||
// f0, f0ok := identifier.AdditionalKeys["scalableDimension"] |
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.
Did we plan to support case-insensitive lookups? Because if the Spec
or Status
field is PascalCased, per Go export rules, and we're asking users to use lowerCamelCased, things might get confusing here.
I think we should probably support case-insensitive key lookups here.
Thoughts?
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.
All other fields in the k8s spec are lowerCamelCased, I am trying to make the additionalKeys
map feel more "k8s native".
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.
@RedbackThomson yeah, I guess that's a fair point. I just worry that without the TODO below on line 953 being implemented, that simple typos here will be quite difficult to detect.
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.
Yeah totally understandable. A typo in an additionalKeys
key would not be detectable and would not produce any error statements at the moment. It would be interesting to pop values out of the additionalKeys
map as they are consumed and return error conditions for any remaining values.
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.
// r.ko.Status.BrokerID = identifier.NameOrID | ||
primaryKeyOut += fmt.Sprintf("%s%s.%s.%s = %s.NameOrID\n", indent, targetVarName, memberPath, cleanMemberName, sourceVarName) | ||
} else { | ||
// f0, f0ok := identifier.AdditionalKeys["scalableDimension"] |
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.
@RedbackThomson yeah, I guess that's a fair point. I just worry that without the TODO below on line 953 being implemented, that simple typos here will be quite difficult to detect.
LGTM |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, RedbackThomson, vijtrip2 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…de (#115) Related to #105 and aws-controllers-k8s/runtime#13 Description of changes: - replace nil pointer checks with string zero value checks - replace `string` value assignment with `string` ptr assignments By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
…de (aws-controllers-k8s#115) Related to aws-controllers-k8s#105 and aws-controllers-k8s/runtime#13 Description of changes: - replace nil pointer checks with string zero value checks - replace `string` value assignment with `string` ptr assignments By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
…ollers-k8s#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.
…de (aws-controllers-k8s#115) Related to aws-controllers-k8s#105 and aws-controllers-k8s/runtime#13 Description of changes: - replace nil pointer checks with string zero value checks - replace `string` value assignment with `string` ptr assignments By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
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 optionallyReadMany
) 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 newAdditionalKeys
map (https://github.com/aws-controllers-k8s/runtime/pull/13/files). Optionally, the primary identifier field can be configured in the generator underoperations.<operation>.primary_identifier_field_name
if one cannot be (or is incorrectly) identified.Example output from
applicationautoscaling
ScalingPolicy
:Example output from
mq
Broker
:By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.