-
Notifications
You must be signed in to change notification settings - Fork 209
Create custom list and map fields #222
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
Create custom list and map fields #222
Conversation
Skipping CI for Draft Pull Request. |
Waiting for rebase on top of #221 |
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.
The refactor from model
to operations
makes things a lot clearer 👍
pkg/generate/ack/controller.go
Outdated
@@ -22,6 +22,7 @@ import ( | |||
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config" | |||
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset" | |||
ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model" | |||
ackoperations "github.com/aws-controllers-k8s/code-generator/pkg/operations" |
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.
why not use this import alias everywhere? Such as in check.go
below
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.
The import aliasing in ACK seems to be a bit random. Some places use ackmodel
others import model without an alias. I have just stuck to whatever the file has as convention. I don't think ackmodel
is necessary, because we are clearly in the ack
project, so model
should be sufficient.
typeRenames: nil, | ||
} | ||
|
||
h.InjectCustomShapes(sdkapi) |
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.
From the current implementation of Helper, I don't think it makes sense for one of its methods to be able to change/edit sdkapi
.
Is there any reason this couldn't be a setter? ex: func (a *SDKAPI) SetCustomShapes(cfg ackgenconfig.Config)
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.
My aim for some of the refactoring work was that SDKAPI
is an artifact produced by the sdk.Helper
struct. "Injecting" it here, is just one stage of creating that artifact - before it is eventually passed to the model struct initializer.
Because of tight code coupling, SDKAPI
has to stay in the model
package, but ideally it would be owned in the sdk
package.
pkg/sdk/helper.go
Outdated
h.apiVersion = apiVersion | ||
} | ||
|
||
// API returns the aws-sdk-go API model for a supplied service model name. | ||
func (h *SDKHelper) API(serviceModelName string) (*SDKAPI, error) { | ||
func (h *Helper) API(serviceModelName string) (*SDKAPI, error) { |
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.
I know you didn't change any logic here, but why have the helper do this instead of a constructor for SDKAPI
requiring serviceModelName?
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.
I don't have any history for this method - they predate my introduction to the project. My best guess is that we don't care about the service name anywhere else in the Helper
, but I think over time we have expanded it and now we have an awkward waterfall of passing it between methods.
42429aa
to
d501b02
Compare
/test s3-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.
Is the only way to use this custom field via Hooks in service-controller code?
"github.com/aws-controllers-k8s/code-generator/pkg/model" | ||
"github.com/stretchr/testify/assert" |
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.
nit: import order
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.
Ugh damn linter, again.
) | ||
panic(msg) | ||
} | ||
} else if fieldConfig.CustomField != nil { |
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.
It seems like the custom field is being added to both Spec and Status-- is that intended? Am I misreading?
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.
The field can be added to either the Spec or the Status, depending on the value of is_read_only
. Otherwise the implementations don't discriminate.
At the moment, yes. Considering the type doesn't exist in the SDK, the generator won't really know how to use it - it's not linked to any of the operations and therefore not linked to any SDK methods. This could be smarter in the future, but not in this revision. |
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: brycahta, 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/community#914 Description of changes: Uses the new custom fields code-generator PR (aws-controllers-k8s/code-generator#222) to create lists of configuration types. At runtime each of these configurations is put individually (mapped using their ID field) onto the bucket. For each reconciliation, we describe the configurations using a `List*` operation and determine the delta for each configuration using a generated `compare*` method in the `sdk.go`. The configuration elements are individually created, deleted, updated or no-op'd depending on the diff. 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#881
Description of changes:
Supports creating custom list and map fields where the member shapes of those fields already exist in the SDK.
Rather than supplying a
from
in the field config, you can now supply acustom_field
property which requireseither
list_of
ormap_of
with the name of an API shape as the value.An example of generating a list (for an S3 Bucket):
Produces the following:
An example of generating a map (for an S3 Bucket):
Produces the following:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.