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

[Internal] Migrate Share Data Source to Plugin Framework #4161

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Oct 28, 2024

Changes

This PR migrates the share/shares data sources to the Plugin framework. The code was largely copied "as is" from the previous implementation of the share data source, with the necessary adaptations made for integration with the Plugin framework.

Tests

Note: current tests create shares using the SDKv2 resource, but fetch them using the new plugin framework data source. Once the resource migration will be merged, I will amend this. Edit: Now that the resource itself is merged, the acceptance tests use the plugin framework's version of the resource.

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

@rauchy rauchy requested review from a team as code owners October 28, 2024 08:22
@rauchy rauchy requested review from parthban-db and removed request for a team October 28, 2024 08:22
@rauchy rauchy temporarily deployed to test-trigger-is October 28, 2024 08:22 — with GitHub Actions Inactive
@tanmay-db tanmay-db self-requested a review October 28, 2024 09:42
Copy link
Contributor

@alexott alexott left a comment

Choose a reason for hiding this comment

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

Why do we need to do staging for data sources? Imho it's less critical than resources.

but the main issue IMHO is that we modify the acceptance tests to work only with the staged resources, and leaving a hole in acceptance testing of "normal" data sources

Comment on lines 31 to 35
attrs, blocks := tfschema.DataSourceStructToSchemaMap(sharing_tf.ShareInfo{}, nil)
resp.Schema = schema.Schema{
Attributes: attrs,
Blocks: blocks,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a direct problem, but such code is repeated everywhere. Should we add a helper function that we can use instead?

@rauchy rauchy force-pushed the migrate-share-datasource-to-plugin-framework branch from 58c0ba5 to 2235d30 Compare October 29, 2024 10:46
@rauchy rauchy temporarily deployed to test-trigger-is October 29, 2024 10:46 — with GitHub Actions Inactive
@rauchy rauchy temporarily deployed to test-trigger-is October 29, 2024 10:48 — with GitHub Actions Inactive
@alexott
Copy link
Contributor

alexott commented Oct 29, 2024

@rauchy I think that it makes sense just to duplicate tests, not to replace resources/data sources, so we keep tests for SDK-based resources as well, and remove the duplicate tests when we replace SDK-based with plugin framework-based

@rauchy
Copy link
Contributor Author

rauchy commented Oct 29, 2024

@alexott that was exactly what I was about to propose :)

@rauchy rauchy force-pushed the migrate-share-datasource-to-plugin-framework branch from 227dbb6 to 74ad0f6 Compare October 29, 2024 11:42
@rauchy rauchy temporarily deployed to test-trigger-is October 29, 2024 11:42 — with GitHub Actions Inactive
}

func (d *ShareDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = pluginfwcommon.GetDatabricksStagingName("share")
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment below.

Name: config.Name.ValueString(),
IncludeSharedData: true,
})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove from state if missing:


		if apierr.IsMissing(err) {
			resp.State.RemoveResource(ctx)
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know that's needed :) b7c32b7

}

func (d *SharesDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = pluginfwcommon.GetDatabricksStagingName("shares")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially, I planned to use a dataSourceName constant for both the share and shares data sources. However, since they share the same namespace, that wasn’t an option. So, I just included the constant within the Metadata function, particularly since it’s only used once in each data source. Alternatively, I could assign a dataSourceName constant to one data source and rename it for the other, but that didn't feel quite right.

Let me know if you have a preferred approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, yeah we could use dataSourceNameShare, dataSourceNameShares, mentioning this because we would also need to set the useragent (eg: https://github.com/databricks/terraform-provider-databricks/blob/main/internal/providers/pluginfw/resources/volume/data_volumes.go#L56) and use the same name there as well so might be better to abstract this in a single variable.

@rauchy rauchy force-pushed the migrate-share-datasource-to-plugin-framework branch from 74ad0f6 to b7c32b7 Compare October 30, 2024 06:01
@rauchy rauchy enabled auto-merge October 30, 2024 06:03
@rauchy rauchy force-pushed the migrate-share-datasource-to-plugin-framework branch from b7c32b7 to 7e28bac Compare October 30, 2024 10:54
@rauchy rauchy temporarily deployed to test-trigger-is October 30, 2024 10:54 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot
Copy link
Collaborator

Test Details: go/deco-tests/11591746843

@rauchy rauchy added this pull request to the merge queue Oct 30, 2024
Merged via the queue into main with commit 613ed1a Oct 30, 2024
12 checks passed
@rauchy rauchy deleted the migrate-share-datasource-to-plugin-framework branch October 30, 2024 12:39
tanmay-db added a commit that referenced this pull request Nov 5, 2024
### New Features and Improvements

 * Added `databricks_functions` data source ([#4154](#4154)).

### Bug Fixes

 * Handle edge case for `effective_properties` in `databricks_sql_table` ([#4153](#4153)).
 * Provide more prescriptive error when users fail to create a single node cluster ([#4168](#4168)).

### Internal Changes

 * Add test instructions for external contributors ([#4169](#4169)).
 * Always write message for manual test integration ([#4188](#4188)).
 * Make `Read` after `Create`/`Update` configurable ([#4190](#4190)).
 * Migrate Share Data Source to Plugin Framework ([#4161](#4161)).
 * Migrate Share Resource to Plugin Framework ([#4047](#4047)).
 * Rollout Plugin Framework  ([#4134](#4134)).

### Dependency Updates

 * Bump Go SDK to v0.50.0 ([#4178](#4178)).

### Exporter

 * Allow to match resource names by regular expression ([#4177](#4177)).
github-merge-queue bot pushed a commit that referenced this pull request Nov 6, 2024
### New Features and Improvements

* Added `databricks_functions` data source
([#4154](#4154)).


### Bug Fixes

* Handle edge case for `effective_properties` in `databricks_sql_table`
([#4153](#4153)).
* Provide more prescriptive error when users fail to create a single
node cluster
([#4168](#4168)).


### Internal Changes

* Add test instructions for external contributors
([#4169](#4169)).
* Always write message for manual test integration
([#4188](#4188)).
* Make `Read` after `Create`/`Update` configurable
([#4190](#4190)).
* Migrate Share Data Source to Plugin Framework
([#4161](#4161)).
* Migrate Share Resource to Plugin Framework
([#4047](#4047)).
* Rollout Plugin Framework
([#4134](#4134)).


### Dependency Updates

* Bump Go SDK to v0.50.0
([#4178](#4178)).


### Exporter

* Allow to match resource names by regular expression
([#4177](#4177)).
github-merge-queue bot pushed a commit that referenced this pull request Nov 14, 2024
…mework (#4187)

## Changes
<!-- Summary of your changes that are easy to understand -->
Following up for
#4161 (comment),
I noticed some other resources also aren't setting the user agent.
Creating a PR to fix them. Also added a note in the contributing
guideline.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->
NA
- [ ] `make test` run locally
- [ ] relevant change in `docs/` folder
- [ ] covered with integration tests in `internal/acceptance`
- [ ] relevant acceptance tests are passing
- [ ] using Go SDK
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.

4 participants