Skip to content

gitrepo: remove OptimizedGitClones as a feature gate #1124

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

Merged
merged 1 commit into from
Jun 21, 2023
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
18 changes: 0 additions & 18 deletions docs/spec/v1/gitrepositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,6 @@ GitRepository, and changes to the resource or in the Git repository will not
result in a new Artifact. When the field is set to `false` or removed, it will
resume.

#### Optimized Git clones

Optimized Git clones decreases resource utilization for GitRepository
reconciliations.

When enabled, it avoids full Git clone operations by first checking whether
the revision of the last stored artifact is still the head of the remote
repository and none of the other factors that contribute to a change in the
artifact, like ignore rules and included repositories, have changed. If that is
so, the reconciliation is skipped. Else, a full reconciliation is performed as
usual.

This feature is enabled by default. It can be disabled by starting the
controller with the argument `--feature-gates=OptimizedGitClones=false`.

NB: GitRepository objects configured for SemVer or Commit clones are
not affected by this functionality.

#### Proxy support

When a proxy is configured in the source-controller Pod through the appropriate
Expand Down
14 changes: 4 additions & 10 deletions internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
// Persist the ArtifactSet.
*includes = *artifacts

var optimizedClone bool
if val, ok := r.features[features.OptimizedGitClones]; ok && val {
optimizedClone = true
}

c, err := r.gitCheckout(ctx, obj, authOpts, dir, optimizedClone)
c, err := r.gitCheckout(ctx, obj, authOpts, dir)
if err != nil {
return sreconcile.ResultEmpty, err
}
Expand Down Expand Up @@ -583,7 +578,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch

// If we can't skip the reconciliation, checkout again without any
// optimization.
c, err := r.gitCheckout(ctx, obj, authOpts, dir, false)
c, err := r.gitCheckout(ctx, obj, authOpts, dir)
if err != nil {
return sreconcile.ResultEmpty, err
}
Expand Down Expand Up @@ -782,8 +777,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context, sp *patc
// gitCheckout builds checkout options with the given configurations and
// performs a git checkout.
func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
obj *sourcev1.GitRepository, authOpts *git.AuthOptions, dir string,
optimized bool) (*git.Commit, error) {
obj *sourcev1.GitRepository, authOpts *git.AuthOptions, dir string) (*git.Commit, error) {
// Configure checkout strategy.
cloneOpts := repository.CloneConfig{
RecurseSubmodules: obj.Spec.RecurseSubmodules,
Expand All @@ -800,7 +794,7 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
// Only if the object has an existing artifact in storage, attempt to
// short-circuit clone operation. reconcileStorage has already verified
// that the artifact exists.
if optimized && conditions.IsTrue(obj, sourcev1.ArtifactInStorageCondition) {
if conditions.IsTrue(obj, sourcev1.ArtifactInStorageCondition) {
if artifact := obj.GetArtifact(); artifact != nil {
cloneOpts.LastObservedCommit = artifact.Revision
}
Expand Down
10 changes: 2 additions & 8 deletions internal/controller/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
Client: clientBuilder.Build(),
EventRecorder: record.NewFakeRecorder(32),
Storage: testStorage,
features: map[string]bool{
features.OptimizedGitClones: true,
},
patchOptions: getPatchOptions(gitRepositoryReadyCondition.Owned, "sc"),
patchOptions: getPatchOptions(gitRepositoryReadyCondition.Owned, "sc"),
}

tmpDir := t.TempDir()
Expand Down Expand Up @@ -792,10 +789,7 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
Build(),
EventRecorder: record.NewFakeRecorder(32),
Storage: testStorage,
features: map[string]bool{
features.OptimizedGitClones: true,
},
patchOptions: getPatchOptions(gitRepositoryReadyCondition.Owned, "sc"),
patchOptions: getPatchOptions(gitRepositoryReadyCondition.Owned, "sc"),
}

for _, tt := range tests {
Expand Down
4 changes: 0 additions & 4 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/source-controller/internal/cache"
"github.com/fluxcd/source-controller/internal/features"
"github.com/fluxcd/source-controller/internal/helm/registry"
// +kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -241,9 +240,6 @@ func TestMain(m *testing.M) {
EventRecorder: record.NewFakeRecorder(32),
Metrics: testMetricsH,
Storage: testStorage,
features: map[string]bool{
features.OptimizedGitClones: true,
},
}).SetupWithManagerAndOptions(testEnv, GitRepositoryReconcilerOptions{
RateLimiter: controller.GetDefaultRateLimiter(),
}); err != nil {
Expand Down
10 changes: 0 additions & 10 deletions internal/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ package features
import feathelper "github.com/fluxcd/pkg/runtime/features"

const (
// OptimizedGitClones decreases resource utilization for GitRepository
// reconciliations.
//
// When enabled, avoids full clone operations by first checking whether
// the last revision is still the same at the target repository,
// and if that is so, skips the reconciliation.
OptimizedGitClones = "OptimizedGitClones"
// CacheSecretsAndConfigMaps controls whether secrets and configmaps should be cached.
//
// When enabled, it will cache both object types, resulting in increased memory usage
Expand All @@ -37,9 +30,6 @@ const (
)

var features = map[string]bool{
// OptimizedGitClones
// opt-out from v0.25
OptimizedGitClones: true,
// CacheSecretsAndConfigMaps
// opt-in from v0.34
CacheSecretsAndConfigMaps: false,
Expand Down