-
Notifications
You must be signed in to change notification settings - Fork 190
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
Support lists of structs containing refs and ClearResolvedReferences
#435
Support lists of structs containing refs and ClearResolvedReferences
#435
Conversation
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.
Awesome, nice work on this mate 👍
Left few comments. I will get back with a more constructive review once i test it this patch with one of the controllers!
` if ko.Spec.APIRef != nil && ko.Spec.APIID != nil { | ||
return ackerr.ResourceReferenceAndIDNotSupportedFor("APIID", "APIRef") | ||
} | ||
if ko.Spec.APIRef == nil && ko.Spec.APIID == nil { | ||
return ackerr.ResourceReferenceOrIDRequiredFor("APIID", "APIRef") | ||
} |
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.
One of the good use case of https://github.com/aws-controllers-k8s/pkg/pull/14/files#diff-4b1976072e607d66abb6e181c6699c9be57d46ada282e77ee704c6cdbebb17e7R36-R48 i believe. I know it's a pain to check for the zero values as well. But users could provide apiID: ""
...
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.
lo
also supports IsEmpty
The caveat to these changes that is still not fixed: These changes allow for resolving references within lists of structs, but reference fields are removed (replaced with their concrete values) from the spec of the resources at the end of the create resource reconciliation. This is because |
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.
👍
ece5c8f
to
75792fb
Compare
/test s3-controller-test |
/test apigatewayv2-controller-test |
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jljaco, 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 |
Implements aws-controllers-k8s/runtime#121
Description of changes:
This PR abstracts out the process of iterating through all references into a separate method called
iterReferenceValues
.iterReferenceValues
produces Go code that drills down into the spec for every ref, iterating through any slices as necessary. Once it reaches the ref object, it calls a callback which can be used by other methods for logic pertaining to accessing the refs.This change allows
ResolveReferencesForField
to access all refs within lists of structs (or even within lists of lists of structs, etc.).iterReferenceValues
is also used to implementClearResolvedReferencesForField
, which simply sets the concrete value tonil
if it detects a non-nil value in the ref field (orlen > 0
for lists of refs).This PR also removes
hasNonNilReferences
.hasNonNilReferences
was being used to indicate whether there were any references inside the resource, which required another set of iterating through all ref fields. Instead, eachresolveReferencesFor*
returns a boolean which indicates whether it found a reference during its iteration.Below is a Gist that shows the output of running the code-generator on the current EC2
generator.yaml
:https://gist.github.com/RedbackThomson/8e11cbbe96065a4eb812c387665c747d
For testing:
ec2
andlambda
already have a series of tests for references. Both of these tests are passing, but they were also passing before this PR. I have a branch of theec2-controller
with additional tests usingRouteTables
, which have lists of structs containing refs, and all of those are passing as well.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.