Skip to content

Conversation

@a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Mar 3, 2023

While developing the ACK pipes-controller, we encountered an issue where
the generated code didn't compile mainly because the code-generator
assumed that the AWS SDK client/interface/import-paths always followed
the same naming conventions. However, we discovered that Pipes was the
exception as they renamed the model, import path, and client
struct/interface.

This patch introduces a new feature that enables users to manually set
the client struct and interface names in the generator.yaml file.
This update allows for greater flexibility in the AWS client naming
within pipes-controller and possibly other controllers in the future.

In this patch, we've also introduced a breaking change by renaming
model_name to sdk_names.model. Mainly to keep all the SDK-related
naming conventions in the same place.

e.g:

old configuration:

model_name: foo

new configuration:

sdk_names:
  model_name: foo

Signed-off-by: Amine Hilaly [email protected]

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

@ack-prow ack-prow bot requested review from RedbackThomson and vijtrip2 March 3, 2023 00:40
@ack-prow ack-prow bot added the approved label Mar 3, 2023
@a-hilaly
Copy link
Member Author

a-hilaly commented Mar 3, 2023

/test lambda-controller-test

@jaypipes
Copy link
Collaborator

jaypipes commented Mar 3, 2023

Pipes are always a problem.

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.

@a-hilaly @embano1 I think it would be better to just rely on the aws-sdk-go/private/model/api.API InterfaceName and StructName methods.

@a-hilaly
Copy link
Member Author

a-hilaly commented Mar 3, 2023

@a-hilaly @embano1 I think it would be better to just rely on the aws-sdk-go/private/model/api.API InterfaceName and StructName methods.

@jaypipes Unfortunately, those don't work properly for us. The reason is that the aws-sdk-go/pipes package was generated using flags different than the default ones. And since we don't have access to those there is nothing we can do (i think)

@jaypipes
Copy link
Collaborator

jaypipes commented Mar 6, 2023

@a-hilaly @embano1 I think it would be better to just rely on the aws-sdk-go/private/model/api.API InterfaceName and StructName methods.

@jaypipes Unfortunately, those don't work properly for us. The reason is that the aws-sdk-go/pipes package was generated using flags different than the default ones. And since we don't have access to those there is nothing we can do (i think)

@a-hilaly can you prove this? I don't understand why those two methods won't work for this use case...

@a-hilaly
Copy link
Member Author

a-hilaly commented Mar 6, 2023

@jaypipes api.InterfacePackageName returns eventbridgepipesiface (we need pipesiface) and api.StructName returns EventBridgePipes (we need Pipes/PipesAPI). Note that the values returned by &api{} are correct theoritically speaking, but pipes teams generated their controller using different struct/interface/package names: probably with something like

go run -tags codegen ./private/model/cli/gen-api/main.go -use-service-id -path pipes ./models/apis/pipes/2015-10-07/api-2.json

if a == nil || a.API == nil {
return ""
}
return fmt.Sprintf("%s%s", a.API.StructName(), "API")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a.API.InterfaceName() by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no a.API.InterfaceName :/ . However there a a.API.InterfacePackageName but it return the package name that defines the interface.. which is not what we need here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, looking in the upstream code they indeed use StructName ... :/

While developing the ACK pipes-controller, we encountered an issue where
the generated code didn't compile mainly because the code-generator
assumed that the AWS SDK client/interface/import-paths always followed
the same naming convetions. However, we discovered that pipes was the
exception as they renamed the model, import path and client
struct/interface.

This patch introduces a new feature that enables users to manually set
the client structg and interface names int he `generator.yaml` file.
This update allows for greater flexibvility in the AWS client naming
within pipes-controller and possibly other controllers in the future.

In this patch, we've also introduced a breaking change by renaming
`model_name` to `sdk_names.model`. Mianly to keep all the SDK related
naming convetions in the same place.

Signed-off-by: Amine Hilaly <[email protected]>
@ack-prow
Copy link

ack-prow bot commented Mar 10, 2023

@a-hilaly: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ec2-controller-test e371c49 link true /test ec2-controller-test

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

Copy link
Contributor

@RedbackThomson RedbackThomson left a comment

Choose a reason for hiding this comment

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

Happy to approve this. I'm a bit tentative about the naming, only because I don't fully understand the difference between these. Would you mind adding examples for each of these to the PR description for our reference? (examples of the normal default, and then what pipes does differently?)

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.

👍

if a == nil || a.API == nil {
return ""
}
return fmt.Sprintf("%s%s", a.API.StructName(), "API")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, looking in the upstream code they indeed use StructName ... :/

@jaypipes
Copy link
Collaborator

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Mar 14, 2023
@ack-prow
Copy link

ack-prow bot commented Mar 14, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,RedbackThomson,jaypipes]

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

@jaypipes jaypipes merged commit 5404da8 into aws-controllers-k8s:main Mar 14, 2023
@bobh66
Copy link
Contributor

bobh66 commented Mar 21, 2023

@jaypipes After this commit I'm seeing errors when running ack-generate crossplane for the prometheusservice in the crossplane-contrib/provider-aws project:

./ack-generate crossplane --aws-sdk-go-version v1.44.174 prometheusservice --output ../../
Error: service prometheusservice not found
+ exit 1

The Makefile is generating a list of services from the directories in https://github.com/crossplane-contrib/provider-aws/tree/master/apis that contain generator_config.yaml files. This logic worked until these changes were applied.

I can dig into it more tomorrow but I thought I would check to see if it's something obvious that we can change on the provider-aws side.

Thanks

@haarchri
Copy link
Contributor

@bobh66 you need to switch

model_name to sdk_names.model

https://github.com/crossplane-contrib/provider-aws/blob/master/apis/prometheusservice/generator-config.yaml#L1

@bobh66
Copy link
Contributor

bobh66 commented Mar 21, 2023

Thanks @haarchri - that fixed it.

For future reference if this comes up as a search result, the specific change is:

model_name: foo

to

sdk_names:
  model_name: foo

@a-hilaly
Copy link
Member Author

modified PR description to include the example you provided @bobh66 . Thank you folks!

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants