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

Add GitShallowClone feature #463

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions controllers/imageupdateautomation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 11 additions & 3 deletions docs/spec/v1beta1/imageupdateautomations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down