-
Notifications
You must be signed in to change notification settings - Fork 397
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
Test Case Provider Switch #4135
Open
edwardfeng-db
wants to merge
4
commits into
main
Choose a base branch
from
jinghao-feng_data/pfw-test-switch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+358
−197
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,26 +45,34 @@ var onboardedDataSources = []func() datasource.DataSource{ | |
} | ||
|
||
// GetUseSdkV2DataSources is a helper function to get name of resources that should use SDK V2 instead of plugin framework | ||
func getUseSdkV2Resources() []string { | ||
func getUseSdkV2Resources(ctx context.Context) []string { | ||
useSdkV2 := os.Getenv("USE_SDK_V2_RESOURCES") | ||
if useSdkV2 == "" { | ||
return []string{} | ||
useSdkV2Ctx := ctx.Value("USE_SDK_V2_RESOURCES") | ||
combinedNames := "" | ||
if useSdkV2 != "" && useSdkV2Ctx != "" { | ||
combinedNames = useSdkV2 + "," + useSdkV2Ctx.(string) | ||
} else { | ||
combinedNames = useSdkV2 + useSdkV2Ctx.(string) | ||
} | ||
return strings.Split(useSdkV2, ",") | ||
return strings.Split(combinedNames, ",") | ||
} | ||
|
||
// GetUseSdkV2DataSources is a helper function to get name of data sources that should use SDK V2 instead of plugin framework | ||
func getUseSdkV2DataSources() []string { | ||
func getUseSdkV2DataSources(ctx context.Context) []string { | ||
useSdkV2 := os.Getenv("USE_SDK_V2_DATA_SOURCES") | ||
if useSdkV2 == "" { | ||
return []string{} | ||
useSdkV2Ctx := ctx.Value("USE_SDK_V2_DATA_SOURCES") | ||
combinedNames := "" | ||
if useSdkV2 != "" && useSdkV2Ctx != "" { | ||
combinedNames = useSdkV2 + "," + useSdkV2Ctx.(string) | ||
} else { | ||
combinedNames = useSdkV2 + useSdkV2Ctx.(string) | ||
} | ||
return strings.Split(useSdkV2, ",") | ||
return strings.Split(combinedNames, ",") | ||
} | ||
|
||
// Helper function to check if a resource should use be in SDK V2 instead of plugin framework | ||
func shouldUseSdkV2Resource(resourceName string) bool { | ||
useSdkV2Resources := getUseSdkV2Resources() | ||
func shouldUseSdkV2Resource(ctx context.Context, resourceName string) bool { | ||
useSdkV2Resources := getUseSdkV2Resources(ctx) | ||
for _, sdkV2Resource := range useSdkV2Resources { | ||
if resourceName == sdkV2Resource { | ||
return true | ||
|
@@ -74,8 +82,8 @@ func shouldUseSdkV2Resource(resourceName string) bool { | |
} | ||
|
||
// Helper function to check if a data source should use be in SDK V2 instead of plugin framework | ||
func shouldUseSdkV2DataSource(dataSourceName string) bool { | ||
sdkV2DataSources := getUseSdkV2DataSources() | ||
func shouldUseSdkV2DataSource(ctx context.Context, dataSourceName string) bool { | ||
sdkV2DataSources := getUseSdkV2DataSources(ctx) | ||
for _, sdkV2DataSource := range sdkV2DataSources { | ||
if dataSourceName == sdkV2DataSource { | ||
return true | ||
|
@@ -85,13 +93,13 @@ func shouldUseSdkV2DataSource(dataSourceName string) bool { | |
} | ||
|
||
// getPluginFrameworkResourcesToRegister is a helper function to get the list of resources that are migrated away from sdkv2 to plugin framework | ||
func getPluginFrameworkResourcesToRegister() []func() resource.Resource { | ||
func getPluginFrameworkResourcesToRegister(ctx context.Context) []func() resource.Resource { | ||
var resources []func() resource.Resource | ||
|
||
// Loop through the map and add resources if they're not specifically marked to use the SDK V2 | ||
for _, resourceFunc := range migratedResources { | ||
name := getResourceName(resourceFunc) | ||
if !shouldUseSdkV2Resource(name) { | ||
if !shouldUseSdkV2Resource(ctx, name) { | ||
resources = append(resources, resourceFunc) | ||
} | ||
} | ||
|
@@ -100,13 +108,13 @@ func getPluginFrameworkResourcesToRegister() []func() resource.Resource { | |
} | ||
|
||
// getPluginFrameworkDataSourcesToRegister is a helper function to get the list of data sources that are migrated away from sdkv2 to plugin framework | ||
func getPluginFrameworkDataSourcesToRegister() []func() datasource.DataSource { | ||
func getPluginFrameworkDataSourcesToRegister(ctx context.Context) []func() datasource.DataSource { | ||
var dataSources []func() datasource.DataSource | ||
|
||
// Loop through the map and add data sources if they're not specifically marked to use the SDK V2 | ||
for _, dataSourceFunc := range migratedDataSources { | ||
name := getDataSourceName(dataSourceFunc) | ||
if !shouldUseSdkV2DataSource(name) { | ||
if !shouldUseSdkV2DataSource(ctx, name) { | ||
dataSources = append(dataSources, dataSourceFunc) | ||
} | ||
} | ||
|
@@ -127,23 +135,23 @@ func getDataSourceName(dataSourceFunc func() datasource.DataSource) string { | |
} | ||
|
||
// GetSdkV2ResourcesToRemove is a helper function to get the list of resources that are migrated away from sdkv2 to plugin framework | ||
func GetSdkV2ResourcesToRemove() []string { | ||
func GetSdkV2ResourcesToRemove(ctx context.Context) []string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the context passed through for getting the names |
||
resourcesToRemove := []string{} | ||
for _, resourceFunc := range migratedResources { | ||
name := getResourceName(resourceFunc) | ||
if !shouldUseSdkV2Resource(name) { | ||
if !shouldUseSdkV2Resource(ctx, name) { | ||
resourcesToRemove = append(resourcesToRemove, name) | ||
} | ||
} | ||
return resourcesToRemove | ||
} | ||
|
||
// GetSdkV2DataSourcesToRemove is a helper function to get the list of data sources that are migrated away from sdkv2 to plugin framework | ||
func GetSdkV2DataSourcesToRemove() []string { | ||
func GetSdkV2DataSourcesToRemove(ctx context.Context) []string { | ||
dataSourcesToRemove := []string{} | ||
for _, dataSourceFunc := range migratedDataSources { | ||
name := getDataSourceName(dataSourceFunc) | ||
if !shouldUseSdkV2DataSource(name) { | ||
if !shouldUseSdkV2DataSource(ctx, name) { | ||
dataSourcesToRemove = append(dataSourcesToRemove, name) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,15 +60,15 @@ func GetProviderServer(ctx context.Context, options ...ServerOption) (tfprotov6. | |
} | ||
sdkPluginProvider := serverOptions.sdkV2Provider | ||
if sdkPluginProvider == nil { | ||
sdkPluginProvider = sdkv2.DatabricksProvider() | ||
sdkPluginProvider = sdkv2.DatabricksProvider(ctx) | ||
} | ||
pluginFrameworkProvider := serverOptions.pluginFrameworkProvider | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can provide own options |
||
if pluginFrameworkProvider == nil { | ||
pluginFrameworkProvider = pluginfw.GetDatabricksProviderPluginFramework() | ||
} | ||
|
||
upgradedSdkPluginProvider, err := tf5to6server.UpgradeServer( | ||
context.Background(), | ||
ctx, | ||
sdkPluginProvider.GRPCProvider, | ||
) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key should be a separate type