Skip to content
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

Allow override resource identifier to ARN #163

Merged
merged 4 commits into from
Aug 23, 2021

Conversation

RedbackThomson
Copy link
Contributor

@RedbackThomson RedbackThomson commented Aug 20, 2021

Closes aws-controllers-k8s/community#909

Description of changes:
The SageMaker ModelPackage (in some cases) needs to be described using the resource ARN, even though the spec has a ModelPackageName and the DescribeModelPackage input shape has a ModelPackageName field. This pull requests allows the service teams to set the primary_identifier_field_name as "ARN", to override the default generator logic in order to set the ACKResourceMetadata.ARN field to be identifier.ARN.

Also refactored the identifier code to use the new FindIdentifiersInShape common method and to use the setResourceForScalar method.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this @RedbackThomson. Do we have a GH issue associated with this, btw? If not, feel free to create one and pop it into the current sprint.

return arnOut + additionalKeyOut
}
return primaryKeyOut + additionalKeyOut
return primaryKeyConditionalOut + primaryKeyOut + additionalKeyOut
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code changes are perfectly fine. I do think you might want to break the function into a couple smaller helper functions in a future PR, though. The function is still pretty longish. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this method has grown and grown over time. Will break it out when I implement aws-controllers-k8s/community#874

expected,
code.SetResourceIdentifiers(crd.Config(), crd, "identifier", "r.ko", 1),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 929 to +954
renamedName, _ := r.InputFieldRename(
op.Name, memberName,
)

isPrimaryIdentifier := memberName == primaryIdentifier
cleanMemberNames := names.New(renamedName)
cleanMemberName := cleanMemberNames.Camel

memberPath := ""
_, inSpec := r.SpecFields[renamedName]
_, inStatus := r.StatusFields[renamedName]
var targetField *model.Field

specField, inSpec := r.SpecFields[renamedName]
statusField, inStatus := r.StatusFields[renamedName]
switch {
case inSpec:
memberPath = cfg.PrefixConfig.SpecField
targetField = specField
case inStatus:
memberPath = cfg.PrefixConfig.StatusField
targetField = statusField
case isPrimaryIdentifier:
panic("Primary identifier field '" + memberName + "' in operation '" + op.Name + "' cannot be found in either spec or status.")
default:
continue
}

targetVarPath := fmt.Sprintf("%s%s", targetVarName, memberPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use getSanitizedMemberPath here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think there would still be roughly the same number of LoC even if I use getSanitizedMemberPath, here. Mainly because I need a reference to the *Field - as its required for the setResourceForScalar parameters. Although I'm essentially doing the same logic, just with an extra return value.

I might refactor getSanitizedMemberPath to return the field as well, but not in this PR.


// Still haven't determined the identifier? Panic
if primaryIdentifier == "" {
switch len(identifiers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v clean 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So clean. I love this!

@RedbackThomson RedbackThomson added the kind/enhancement Categorizes issue or PR as related to existing feature enhancements. label Aug 20, 2021
@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 23, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Aug 23, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jaypipes, RedbackThomson

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:
  • OWNERS [RedbackThomson,jaypipes]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 23278de into aws-controllers-k8s:main Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/enhancement Categorizes issue or PR as related to existing feature enhancements. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to override primary_identifier_field_name to ARN
4 participants