Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add top-level known referencers in single config#142

Merged
muvaf merged 4 commits intocrossplane-contrib:mainfrom
muvaf:common-conf
Jan 6, 2022
Merged

Add top-level known referencers in single config#142
muvaf merged 4 commits intocrossplane-contrib:mainfrom
muvaf:common-conf

Conversation

@muvaf
Copy link
Copy Markdown
Member

@muvaf muvaf commented Jan 6, 2022

Description of your changes

With this change, we get the following number of referencer configs on top of the existing ones:

VPC: 27
Key: 35
Role: 68
SecurityGroup: 35
Subnet: 36

Fixes #135

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

make reviewable

Comment thread config/overrides.go

// KnownReferencers adds referencers for fields that are known and common among
// more than a few resources.
func KnownReferencers() tjconfig.ResourceOption { //nolint:gocyclo
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have you considered the v1alpha2 bumps in this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just rebased and fixed the paths to include v1alpha2

Comment thread config/overrides.go Outdated
switch {
case strings.HasSuffix(k, "role_arn"):
r.References[k] = tjconfig.Reference{
Type: "github.com/crossplane-contrib/provider-jet-aws/apis/iam/v1alpha1.Role",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If these type constants are used elsewhere (for example in other custom configurations), you may consider defining constants for them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good idea but I'd like to do that for manual referencers as well altogether in another PR.

Comment thread config/overrides.go
case strings.HasSuffix(k, "security_group_ids"):
r.References[k] = tjconfig.Reference{
Type: "github.com/crossplane-contrib/provider-jet-aws/apis/ec2/v1alpha1.SecurityGroup",
RefFieldName: strings.TrimSuffix(name.NewFromSnake(k).Camel, "s") + "Refs",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about caching strings.TrimSuffix(name.NewFromSnake(k).Camel, "s") in a variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it reads better to have it contained like this and there isn't much gain/loss in performance.

Comment thread config/overrides.go
switch k {
case "vpc_id":
r.References["vpc_id"] = tjconfig.Reference{
Type: "github.com/crossplane-contrib/provider-jet-aws/apis/ec2/v1alpha2.VPC",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we handle resolver generation if the referrer and the referee are in the same package?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

angryjet takes care of the case where the type is in the same package even if a full path is given. Though I'm not really sure what's going on here in these two. It prints an error talking about import cycle with autoscaling and for some reason adds an import to self. But I didn't have the patience to dig too deep.

Comment thread config/overrides.go Outdated
Type: "github.com/crossplane-contrib/provider-jet-aws/apis/ec2/v1alpha2.SecurityGroup",
}
case "kms_key_id":
if !r.TerraformResource.Schema["kms_key_id"].Sensitive {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we assume if these fields are sensitive, then they should be references to references to secrets (actual data, e.g., credentials) and not to another AWS object? Maybe a little comment would help.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just moved the sensitive check to top of the for loop. The reason we do this is that we use a secret ref for all fields that are sensitive and adding reference to them breaks the resolver since it's not a valid case. I'll add a comment.

Copy link
Copy Markdown
Collaborator

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @muvaf.

@muvaf muvaf merged commit ce4c9a2 into crossplane-contrib:main Jan 6, 2022
@muvaf muvaf deleted the common-conf branch January 6, 2022 13:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Common configurators for common reference fields

2 participants