Merge pull request #463 from fluxcd/shallow

Add GitShallowClone feature
This commit is contained in:
Paulo Gomes 2022-12-07 10:37:23 +00:00 committed by GitHub
commit 5453088b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -298,6 +298,10 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
opts.Branch = ref.Branch
}
if enabled, _ := r.features[features.GitShallowClone]; enabled {
opts.ShallowClone = true
}
// Use the git operations timeout for the repo.
cloneCtx, cancel := context.WithTimeout(ctx, origin.Spec.Timeout.Duration)
defer cancel()

View File

@ -112,8 +112,8 @@ with write access; e.g., if using a GitHub deploy key, "Allow write access" shou
creating it. Only the `url`, `ref`, and `secretRef` fields of the `GitRepository` are used.
The [`gitImplementation` field][source-docs] in the referenced `GitRepository` is ignored. The
automation controller cannot use shallow clones or submodules, so there is no reason to use the
go-git implementation rather than libgit2.
automation controller automatically uses the go-git implementation rather than libgit2.
To change this behavor, start the controller with `--feature-gates=ForceGoGitImplementation=false`.
Other fields particular to how the Git repository is used are in the `git` field, [described
below](#git-specific-specification).
@ -169,6 +169,9 @@ When `checkout` is given, it overrides the analogous field in the `GitRepository
in `.spec.sourceRef`. You would use this to put automation commits on a different branch than that
you are syncing, for example.
By default the controller will only do shallow clones, but this can be disabled by starting the controller
with `--feature-gates=GitShallowClone=false`.
### Commit
The `.spec.git.commit` field gives details to use when making a commit to push to the Git repository:
@ -402,7 +405,12 @@ branch name, the automation will fail.
When `push` is present, the `branch` field specifies a branch to push to at the origin. The branch
will be created locally if it does not already exist, starting from the checkout branch. If it does
already exist, updates will be calculated on top of any commits already on the branch.
already exist, it will be overwritten with the cloned version plus the changes made by the
controller. Alternatively, force push can be disabled by starting the controller with `--feature-gates=GitForcePushBranch=false`,
in which case the updates will be calculated on top of any commits already on the push branch.
Note that without force push in push branches, if the target branch is stale, the controller may not
be able to conclude the operation and will consistently fail until the branch is either deleted or
refreshed.
In the following snippet, updates will be pushed as commits to the branch `auto`, and when that
branch does not exist at the origin, it will be created locally starting from the branch `main`, and

View File

@ -32,6 +32,10 @@ const (
// When enabled, libgit2 won't be initialized, nor will any git2go cgo
// code be called.
ForceGoGitImplementation = "ForceGoGitImplementation"
// GitShallowClone enables the use of shallow clones when pulling source from
// Git repositories.
GitShallowClone = "GitShallowClone"
)
var features = map[string]bool{
@ -42,6 +46,10 @@ var features = map[string]bool{
// ForceGoGitImplementation
// opt-out from v0.27
ForceGoGitImplementation: true,
// GitShallowClone
// opt-out from v0.28
GitShallowClone: true,
}
// DefaultFeatureGates contains a list of all supported feature gates and