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

Update Aliases function for ResourceProvider to handle recursive structures more gracefully #3338

Merged
merged 14 commits into from
Mar 7, 2024

Conversation

edwardfeng-db
Copy link
Contributor

@edwardfeng-db edwardfeng-db commented Mar 6, 2024

Changes

  • This is a sub PR of [Closed] jobs gosdk migration #3320
  • Make Aliases function return a map of map which can derive aliases from the parent type name and field name.
  • The goal is to avoid redundantly specifying the aliases in recursive data types such as the jobs for_each_task
  • Also updating the recursion_tracking.go functions to make getNameForType more sharable

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@edwardfeng-db edwardfeng-db changed the title Update Aliases method for ResourceProvider Update Aliases function for ResourceProvider to handle recursive structures more gracefully Mar 6, 2024
@edwardfeng-db edwardfeng-db marked this pull request as ready for review March 6, 2024 14:12
@edwardfeng-db edwardfeng-db requested review from a team as code owners March 6, 2024 14:12
@edwardfeng-db edwardfeng-db requested review from hectorcast-db and mgyucht and removed request for a team March 6, 2024 14:12
Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

Seems reasonable, small suggestions but we're almost there.

@@ -41,7 +41,7 @@ var kindMap = map[reflect.Kind]string{
// Generic interface for ResourceProvider. Using CustomizeSchema and Aliases functions to keep track of additional information
// on top of the generated go-sdk struct. This is used to replace manually maintained structs with `tf` tags.
type ResourceProvider interface {
Aliases() map[string]string
Aliases() map[string]map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the doccomment here? What are the keys and values?

By the way, we may want to make Aliases optional for ResourceProvider. If a resource has no aliases, we shouldn't be forced to add an empty Aliases function, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments with an example.

For making Aliases optional, I played around with the idea of adding another interface without Aliases() but I think it's a bit more complicated since we also have RecursiveResourceProvider. I think I'm probably going to leave it as it is and try to resolve this later on. For now I think let's just merge this to unblock the next steps for the jobs migration

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline. We'll do this.

common/reflect_resource.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 83.47%. Comparing base (e0236c9) to head (edf4efd).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3338      +/-   ##
==========================================
- Coverage   83.47%   83.47%   -0.01%     
==========================================
  Files         175      176       +1     
  Lines       16095    16166      +71     
==========================================
+ Hits        13436    13494      +58     
- Misses       1846     1854       +8     
- Partials      813      818       +5     
Files Coverage Δ
clusters/resource_cluster.go 87.15% <ø> (-0.05%) ⬇️
common/recursion_tracking.go 100.00% <100.00%> (ø)
common/reflect_resource.go 84.91% <92.30%> (-0.09%) ⬇️

... and 5 files with indirect coverage changes

@edwardfeng-db edwardfeng-db requested a review from mgyucht March 7, 2024 12:20
common/recursion_tracking.go Outdated Show resolved Hide resolved
@@ -41,7 +41,7 @@ var kindMap = map[reflect.Kind]string{
// Generic interface for ResourceProvider. Using CustomizeSchema and Aliases functions to keep track of additional information
// on top of the generated go-sdk struct. This is used to replace manually maintained structs with `tf` tags.
type ResourceProvider interface {
Aliases() map[string]string
Aliases() map[string]map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline. We'll do this.

@edwardfeng-db edwardfeng-db requested a review from mgyucht March 7, 2024 13:20
common/reflect_resource.go Outdated Show resolved Hide resolved
Co-authored-by: Miles Yucht <miles@databricks.com>
@edwardfeng-db edwardfeng-db added this pull request to the merge queue Mar 7, 2024
Merged via the queue into main with commit ddc5c1a Mar 7, 2024
5 checks passed
@edwardfeng-db edwardfeng-db deleted the edwardfeng-db/update-tf-alias branch March 7, 2024 13:32
@hectorcast-db hectorcast-db mentioned this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants