Add shallow_clone config to the provider config
#753
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.
Describe the bug
I currently manage hundreds of Kubernetes clusters, which are configured using Flux from a single GitOps repository. We utilize
flux_bootstrap_gitto manage Flux installations for each cluster. On average, this repository receives new commits every minute during day time hours.This high frequency of commits has caused issues when updating the
flux_bootstrap_gitresource. Specifically, whenever flux terraform provider attempts to push a commit to our GitOps repository, the Terraform provider almost always times out with the following error:To mitigate this, we’ve increased the timeouts, which has helped to some extent. However, we’ve observed that on every retry, the Terraform provider performs a full clone of the entire repository. This process is time-consuming, given that the repository has over 300,000 commits, and new commits are often added within the retry window.
A potential improvement could involve modifying the
func (prd *providerResourceData) CloneRepository(ctx context.Context)function ininternal/provider/provider_resource_data.goto use a shallow clone. Here’s an example of the proposed change:func (prd *providerResourceData) CloneRepository(ctx context.Context) (*gogit.Client, error) { tmpDir, err := manifestgen.MkdirTempAbs("", "flux-bootstrap-") if err != nil { return nil, fmt.Errorf("could not create temporary working directory for git repository: %w", err) } gitClient, err := prd.GetGitClient(tmpDir) if err != nil { return nil, fmt.Errorf("could not create git client: %w", err) } // TODO: Need to conditionally clone here. If repository is empty this will fail. _, err = gitClient.Clone(ctx, prd.GetRepositoryURL().String(), repository.CloneConfig{ CheckoutStrategy: repository.CheckoutStrategy{ Branch: prd.git.Branch.ValueString(), }, + ShallowClone: true, }) if err != nil { return nil, fmt.Errorf("could not clone git repository: %w", err) } return gitClient, nil }Testing this change locally has shown an improvement in performance. It reduces the time required to clone the repository and should decrease the likelihood of timeouts when applying our Terraform configuration.
OG Issue: #735
How has this been tested?
Output from acceptance testing:
Types of changes
Documentation
make docsChecklist:
git commit -sCommunity Note