Skip to content

Conversation

brycahta
Copy link
Contributor

Issue #, if available: #890

Description of changes:

  • Adds checkRequiredFieldsMissingFromShapeReadMany to check.go to handle ReadMany operations without a corresponding ReadOne.
  • The new method will require resource identifier field should there exist an identifier or identifierS field in the ReadMany operation.
    • Eventually newListRequestPayload will use this identifier field to populate its request in order to guarantee the ReadMany operation returns the desired resource.
    • ex: DescribeVpcs has a VpcIds field. Therefore, Vpc shape should require VpcId, which is part of its status field.
  • Updated tests and templates

Testing:

  • make test
  • make build-controller
func (rm *resourceManager) sdkFind(
	ctx context.Context,
	r *resource,
) (latest *resource, err error) {
	rlog := ackrtlog.FromContext(ctx)
	exit := rlog.Trace("rm.sdkFind")
	defer exit(err)
	// If any required fields in the input shape are missing, AWS resource is
	// not created yet. Return NotFound here to indicate to callers that the
	// resource isn't yet created.
	if rm.requiredFieldsMissingFromReadManyInput(r) {
		return nil, ackerr.NotFound
	}

	input, err := rm.newListRequestPayload(r)

...


// requiredFieldsMissingFromReadManyInput returns true if there are any fields
// for the ReadMany Input shape that are required but not present in the
// resource's Spec or Status
func (rm *resourceManager) requiredFieldsMissingFromReadManyInput(
	r *resource,
) bool {
	return r.ko.Status.VPCID == nil

}

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

@ack-bot ack-bot requested review from a-hilaly and vijtrip2 August 12, 2021 20:53
@ack-bot ack-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 12, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Aug 12, 2021

Hi @brycahta. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

strings.TrimSpace(gotCode),
)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted a test where the Shape/CR have multiple identifiers, but the Id gets prioritized. The only one I could think of was SecurityGroups. The DescribeInput can take either Name or Id, and the SecurityGroup CR has both Name in the Spec and Id in the Status.

In this scenario Id should be a required field. However, when trying to test this I uncovered an edge case in the FindIdentifiers helper funcs. No identifiers are returned for SecurityGroup CR or the DescribeInput because the fields are not securityGroupName/securityGroupId, but groupName/groupId. 😒

I can address this edge case in a different PR, but if anyone else has a good API to test the above case I'd love to add and test it now!

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.

@brycahta this is almost there. I have a request for a couple clarifying code comments to help future readers of this code inline.

Comment on lines +160 to +176
// checkRequiredFieldsMissingFromShapeReadMany is a special-case handling
// of those APIs where there is no ReadOne operation and instead the only way to
// grab information for a single object is to call the ReadMany/List operation
// with one of more filtering fields-- specifically identifier(s). This method
// locates an identifier field in the shape that can be populated with an
// identifier value from the CR.
//
//
// As an example, DescribeVpcs EC2 API call doesn't have a ReadOne operation or
// required fields. However, the input shape has a VpcIds field which can be
// populated using a VpcId, a field in the VPC CR's Status. Therefore, require
// the VpcId field to be present to ensure the returned array from the API call
// consists only of the desired Vpc.
//
// Sample Output:
//
// return r.ko.Status.VPCID == nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great explanation. ++

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.

Great work on this @brycahta, thank you!

// The CRD identifiers being used for comparison reflect the
// *original* field names in the API model shape.
// Field renames are handled below in the call to
// getSanitizedMemberPath.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@jaypipes
Copy link
Collaborator

/lgtm

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

ack-bot commented Aug 17, 2021

[APPROVALNOTIFIER] This PR is APPROVED

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants