Skip to content

Conversation

RedbackThomson
Copy link
Contributor

Issue #, if available: aws-controllers-k8s/community#766

Description of changes:
When setting identifiers on a given resource, dynamically add all additional keys according to their json tag names.

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


ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
{{- if $idField := .CRD.SpecIdentifierField }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can remove this now that #61 is merged.

if ok {
// Set the corresponding field with the value from the mapping
specRef.FieldByName(specType.Field(i).Name).Set(reflect.ValueOf(val))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if the jsonTag isn't found in the identifier.AdditionalKeys? should we error out?

// Iterate over spec fields and associate corresponding json tags
for i := 0; i < specRef.NumField(); i++ {
// Get only the first field in the json tag (the field name)
jsonTag := strings.Split(specType.Field(i).Tag.Get("json"), ",")[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm OK with using the reflect package (even though it's incredibly ugly to work with, IMHO) here.

In the future, we may want to take an approach similar to how we handle TerminalConditions and simply generate a switch case lookup here...

@ack-bot
Copy link
Collaborator

ack-bot commented Jun 16, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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:

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

@a-hilaly
Copy link
Member

@RedbackThomson is gonna rework this PR, sometime next week

/hold

@ack-bot ack-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 17, 2021
ack-bot pushed a commit to aws-controllers-k8s/runtime that referenced this pull request Jun 29, 2021
Issue #, if available: aws-controllers-k8s/community#766

Some resources require more than an ARN/Name/ID to describe a single resource. This PR adds an `additionalKeys` field to the `AWSIdentifiers` to allow for arbitrary identifiers as needed by any resources.

Generator code to support this change: aws-controllers-k8s/code-generator#62
@RedbackThomson RedbackThomson deleted the additional-keys branch July 8, 2021 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants