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

Refactor plugin cache implementation #141

Merged
merged 1 commit into from
Nov 20, 2022

Conversation

bobh66
Copy link
Collaborator

@bobh66 bobh66 commented Nov 17, 2022

  • Remove setenv of TF_PLUGIN_CACHE_DIR for each Workspace connect
  • Set TF_PLUGIN_CACHE_DIR env var in Dockerfile
  • Unset TF_PLUGIN_CACHE_DIR in the CLI process environment when pluginCache is false
  • Set TF_IN_AUTOMATION env var in Dockerfile

Signed-off-by: Bob Haddleton bob.haddleton@nokia.com

Description of your changes

Fixes #139

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

Tested in a development cluster with 100+ workspaces

Copy link
Collaborator

@ytsarev ytsarev left a comment

Choose a reason for hiding this comment

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

We also need to remove PluginCache from ProviderConfig in this case

https://github.com/crossplane-contrib/provider-terraform/blob/master/apis/v1alpha1/types.go#L36-L40

@bobh66
Copy link
Collaborator Author

bobh66 commented Nov 17, 2022

We also need to remove PluginCache from ProviderConfig in this case

https://github.com/crossplane-contrib/provider-terraform/blob/master/apis/v1alpha1/types.go#L36-L40

I wondered about that - I didn't know if that would break the existing ProviderConfig objects that have been modified to have that attribute set? Will removing the attribute definition make those objects invalid?

@ytsarev
Copy link
Collaborator

ytsarev commented Nov 17, 2022

Yeah, it will not match CRD spec anymore, not sure how it will exactly behave as it is additive field. Anyway, v1alpha1 still gives us freedom for breaking changing until we bump maturity level

@bobh66
Copy link
Collaborator Author

bobh66 commented Nov 17, 2022

Yeah, it will not match CRD spec anymore, not sure how it will exactly behave as it is additive field. Anyway, v1alpha1 still gives us freedom for breaking changing until we bump maturity level

I'll build it and see what happens in our test environment

@bobh66
Copy link
Collaborator Author

bobh66 commented Nov 17, 2022

I pushed the updated changes - I think it will be ok as long as the provider doesn't access the attribute, which it doesn't.

// https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache
// +optional
// +kubebuilder:default=true
PluginCache *bool `json:"pluginCache,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Can we test upgrading a running version of provider-terraform to this version to make sure this doesn't break? It's v1alpha1 but may be worth bumping to v1alpha2 and announce it as breaking change. I'd expect it to work as expected since its omitempty already but a validation would be good.

@bobh66
Copy link
Collaborator Author

bobh66 commented Nov 18, 2022

I think I might have a way to make this work at the providerConfig/Workspace level - we can unset the TF_PLUGIN_CACHE_DIR environment variable in the process that runs the CLI command,

This is some rework but if we went to v1alpha2 that would also be more work, so does it make sense to leave the pluginCache option in place to disable the cache and modify the Init() code to unset the env variable?

* Remove setenv of TF_PLUGIN_CACHE_DIR
* Remove TF_PLUGIN_CACHE_DIR from CLI env when cache is disabled
* Set TF_PLUGIN_CACHE_DIR env var in Dockerfile
* Set TF_IN_AUTOMATION env var in Dockerfile

Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
@bobh66
Copy link
Collaborator Author

bobh66 commented Nov 18, 2022

I refactored the changes to leave the existing pluginCache flag in ProviderConfig. The default is to use the plugin cache (it is set in the Dockerfile) but it can be disabled by setting pluginCache: false in the ProviderConfig. This removes the TF_PLUGIN_CACHE_DIR env variable from the environment before calling terraform init.

I tested that the cache works with pluginCache: true and that it does not get used when pluginCache: false.

Copy link
Collaborator

@ytsarev ytsarev left a comment

Choose a reason for hiding this comment

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

Neat solution, LGTM 👍

@bobh66 bobh66 merged commit 27a73f9 into crossplane-contrib:master Nov 20, 2022
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.

Provider cache is only used for some workspaces and not all
3 participants