Skip to content

Commit 01cffa9

Browse files
author
Paulo Gomes
authored
Merge pull request #718 from pjbgf/default-managed
libgit2: enable managed transport by default
2 parents 351b21b + a0d0a63 commit 01cffa9

File tree

6 files changed

+34
-69
lines changed

6 files changed

+34
-69
lines changed

docs/spec/v1beta2/gitrepositories.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,17 @@ Some Git providers like Azure DevOps _require_ the `libgit2` implementation, as
388388
their Git servers provide only support for the
389389
[v2 protocol](https://git-scm.com/docs/protocol-v2).
390390

391-
#### Experimental managed transport for `libgit2` Git implementation
391+
#### Managed transport for `libgit2` Git implementation
392392

393-
The `libgit2` Git implementation supports a new experimental transport for
393+
The `libgit2` Git implementation supports a new managed transport for
394394
improved reliability, adding timeout enforcement for Git network operations.
395-
Opt-in by setting the environment variable `EXPERIMENTAL_GIT_TRANSPORT` to
396-
`true` in the controller's Deployment. This will result in the low-level
397-
transport being handled by the controller, instead of `libgit2`.
398395

399-
This may lead to an increased number of timeout messages in the logs, however
400-
it will fix the bug in which Git operations make the controllers hang indefinitely.
396+
This feature is enabled by default. It can be disabled by starting the
397+
controller with the argument `--feature-gates=GitManagedTransport=false`.
398+
399+
By disabling this feature the management of the transport is passed on to
400+
`libgit2`, which may result in blocking Git operations leading the controllers
401+
to hang indefinitely.
401402

402403
#### Optimized Git clones
403404

internal/features/features.go

+13
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@ const (
3030
// the last revision is still the same at the target repository,
3131
// and if that is so, skips the reconciliation.
3232
OptimizedGitClones = "OptimizedGitClones"
33+
34+
// GitManagedTransport implements a managed transport for GitRepository
35+
// objects that use the libgit2 implementation.
36+
//
37+
// When enabled, improves the reliability of libgit2 reconciliations,
38+
// by enforcing timeouts and ensuring libgit2 cannot hijack the process
39+
// and hang it indefinitely.
40+
GitManagedTransport = "GitManagedTransport"
3341
)
3442

3543
var features = map[string]bool{
3644
// OptimizedGitClones
3745
// opt-out from v0.25
3846
OptimizedGitClones: true,
47+
48+
// GitManagedTransport
49+
// opt-in from v0.22 (via environment variable)
50+
// opt-out from v0.25
51+
GitManagedTransport: true,
3952
}
4053

4154
// DefaultFeatureGates contains a list of all supported feature gates and

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func main() {
310310
startFileServer(storage.BasePath, storageAddr, setupLog)
311311
}()
312312

313-
if managed.Enabled() {
313+
if enabled, _ := features.Enabled(features.GitManagedTransport); enabled {
314314
managed.InitManagedTransport(ctrl.Log.WithName("managed-transport"))
315315
}
316316

pkg/git/libgit2/managed/flag.go

-34
This file was deleted.

pkg/git/libgit2/managed/init.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@ var (
4040

4141
debugLog logr.Logger
4242
traceLog logr.Logger
43+
enabled bool
4344
)
4445

46+
// Enabled defines whether the use of Managed Transport is enabled which
47+
// is only true if InitManagedTransport was called successfully at least
48+
// once.
49+
//
50+
// This is only affects git operations that uses libgit2 implementation.
51+
func Enabled() bool {
52+
return enabled
53+
}
54+
4555
// InitManagedTransport initialises HTTP(S) and SSH managed transport
4656
// for git2go, and therefore only impact git operations using the
4757
// libgit2 implementation.
@@ -57,7 +67,7 @@ func InitManagedTransport(log logr.Logger) error {
5767
var err error
5868

5969
once.Do(func() {
60-
log.Info("Enabling experimental managed transport")
70+
log.Info("Initializing managed transport")
6171
debugLog = log.V(logger.DebugLevel)
6272
traceLog = log.V(logger.TraceLevel)
6373

@@ -66,6 +76,7 @@ func InitManagedTransport(log logr.Logger) error {
6676
}
6777

6878
err = registerManagedSSH()
79+
enabled = true
6980
})
7081

7182
return err

pkg/git/libgit2/managed/managed_test.go

-26
Original file line numberDiff line numberDiff line change
@@ -201,32 +201,6 @@ func TestOptions(t *testing.T) {
201201
}
202202
}
203203

204-
func TestFlagStatus(t *testing.T) {
205-
if Enabled() {
206-
t.Errorf("experimental transport should not be enabled by default")
207-
}
208-
209-
os.Setenv("EXPERIMENTAL_GIT_TRANSPORT", "true")
210-
if !Enabled() {
211-
t.Errorf("experimental transport should be enabled when env EXPERIMENTAL_GIT_TRANSPORT=true")
212-
}
213-
214-
os.Setenv("EXPERIMENTAL_GIT_TRANSPORT", "1")
215-
if !Enabled() {
216-
t.Errorf("experimental transport should be enabled when env EXPERIMENTAL_GIT_TRANSPORT=1")
217-
}
218-
219-
os.Setenv("EXPERIMENTAL_GIT_TRANSPORT", "somethingelse")
220-
if Enabled() {
221-
t.Errorf("experimental transport should be enabled only when env EXPERIMENTAL_GIT_TRANSPORT is 1 or true but was enabled for 'somethingelse'")
222-
}
223-
224-
os.Unsetenv("EXPERIMENTAL_GIT_TRANSPORT")
225-
if Enabled() {
226-
t.Errorf("experimental transport should not be enabled when env EXPERIMENTAL_GIT_TRANSPORT is not present")
227-
}
228-
}
229-
230204
func TestManagedTransport_E2E(t *testing.T) {
231205
g := NewWithT(t)
232206

0 commit comments

Comments
 (0)