Skip to content
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

Align naming and return types for accessors in config package #327

Merged
merged 6 commits into from
Apr 21, 2022
Merged

Align naming and return types for accessors in config package #327

merged 6 commits into from
Apr 21, 2022

Conversation

brycahta
Copy link
Contributor

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

Description of changes:

  • Prepend Getter names with Get and remove error and bool return types
  • Re-Name Query (does resource have X, is resource Y) methods to be consistent and styled similarly
  • Update comments and fix typos

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 jaypipes April 19, 2022 22:51
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.

Couple tiny comments, @brycahta. I won't hold up the PR for the removal of the one panic() but want to get your thoughts about it...

func (c *Config) GetCompareIgnoredFields(resName string) []string {
// GetCompareIgnoredFields returns the list of field paths to ignore when
// comparing two different objects
func (c *Config) GetCompareIgnoredFields(resourceName string) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to rename this to GetCompareIgnoredFieldPaths to more accurately describe the function's returned value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@brycahta if you update this little guy, I'll merge away.

Comment on lines -538 to -542
} else if foundFieldRename {
msg := fmt.Sprintf(
"Field rename %s for operation %s is not part of %s Spec or"+
" Status fields", memberName, op.Name, r.Names.Camel)
panic(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this was an important panic() in the original code, no? It was informing the author of the generator.yaml file that they had specified in the generator.yaml file a field to be renamed that isn't in the Status or Spec...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking when removing:

  1. code generate package shouldn't need to worry or care if a field was renamed. just hand it over fields and generate Go code
  2. if we are unable to satisfy a rename request (i.e. unable to insert renamed field into Spec or Status), then we should panic when creating the CRD

Related to 2, was there a reason to not panic here (and similar for Status field)? Due to continue, I think this is the only possible way to trigger the panic() in the downstream, removed clause.

Copy link
Member

Choose a reason for hiding this comment

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

code generate package shouldn't need to worry or care if a field was renamed. just hand it over fields and generate Go code

The problem with not panicking here is that we might experience different kinds of errors or even nil pointer panics in other parts of the code (which is kinda hard to debug, when it comes to the templating part). Forcing panics in similar areas helps the user understand the errors and fix them quickly.

Related to 2, was there a reason to not panic here (and similar for Status field)?

There are a lot of missing panics in the code generator. I personally believe we should add more of them to guide the user on passing valid configurations to the users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Bryan, you make a good point about how the panic() in the generation code paths improperly couples the inference piece with the generation piece. I think we can look at adding back some checks/panics in the inference part of the refactored code generator in the future and keep it nicely decoupled.

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

Nice! :shipit:

func (c *Config) GetCompareIgnoredFields(resName string) []string {
// GetCompareIgnoredFields returns the list of field paths to ignore when
// comparing two different objects
func (c *Config) GetCompareIgnoredFields(resourceName string) []string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@brycahta if you update this little guy, I'll merge away.

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.

👍

@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 21, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Apr 21, 2022

[APPROVALNOTIFIER] This PR is APPROVED

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

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:
  • OWNERS [A-Hilaly,brycahta,jaypipes,vijtrip2]

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

@ack-bot ack-bot merged commit 302c31f into aws-controllers-k8s:main Apr 21, 2022
@brycahta brycahta deleted the go-on-get branch April 21, 2022 20:52
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