Skip to content

Commit 31fe653

Browse files
Paulo Gomesstefanprodan
authored andcommitted
git: Enable managed transport by default
GitManagedTransport enables the use of Managed Transport. This replaces the previous 'EXPERIMENTAL_GIT_TRANSPORT' environment variable that was used for the same result. This commit also enables it by default. This is an opt-out feature, which can be disabled by starting the controller with the argument '--feature-gates=GitManagedTransport=false'. Signed-off-by: Paulo Gomes <[email protected]>
1 parent d89eb19 commit 31fe653

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

internal/features/features.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package features sets the feature gates that
18+
// source-controller supports, and their default
19+
// states.
20+
package features
21+
22+
import feathelper "github.com/fluxcd/pkg/runtime/features"
23+
24+
const (
25+
// GitManagedTransport implements a managed transport for GitRepository
26+
// objects that use the libgit2 implementation.
27+
//
28+
// When enabled, improves the reliability of libgit2 reconciliations,
29+
// by enforcing timeouts and ensuring libgit2 cannot hijack the process
30+
// and hang it indefinitely.
31+
GitManagedTransport = "GitManagedTransport"
32+
)
33+
34+
var features = map[string]bool{
35+
// GitManagedTransport
36+
// opt-in from v0.21 (via environment variable)
37+
// opt-out from v0.23
38+
GitManagedTransport: true,
39+
}
40+
41+
// DefaultFeatureGates contains a list of all supported feature gates and
42+
// their default values.
43+
func FeatureGates() map[string]bool {
44+
return features
45+
}
46+
47+
// Enabled verifies whether the feature is enabled or not.
48+
//
49+
// This is only a wrapper around the Enabled func in
50+
// pkg/runtime/features, so callers won't need to import
51+
// both packages for checking whether a feature is enabled.
52+
func Enabled(feature string) (bool, error) {
53+
return feathelper.Enabled(feature)
54+
}

main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/fluxcd/pkg/runtime/client"
3434
helper "github.com/fluxcd/pkg/runtime/controller"
3535
"github.com/fluxcd/pkg/runtime/events"
36+
feathelper "github.com/fluxcd/pkg/runtime/features"
3637
"github.com/fluxcd/pkg/runtime/leaderelection"
3738
"github.com/fluxcd/pkg/runtime/logger"
3839
"github.com/fluxcd/pkg/runtime/metrics"
@@ -41,6 +42,7 @@ import (
4142
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
4243

4344
imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
45+
"github.com/fluxcd/image-automation-controller/internal/features"
4446
"github.com/fluxcd/source-controller/pkg/git"
4547
"github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
4648

@@ -73,6 +75,7 @@ func main() {
7375
logOptions logger.Options
7476
leaderElectionOptions leaderelection.Options
7577
rateLimiterOptions helper.RateLimiterOptions
78+
featureGates feathelper.FeatureGates
7679
watchAllNamespaces bool
7780
concurrent int
7881
kexAlgos []string
@@ -86,16 +89,26 @@ func main() {
8689
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent resource reconciles.")
8790
flag.StringSliceVar(&kexAlgos, "ssh-kex-algos", []string{},
8891
"The list of key exchange algorithms to use for ssh connections, arranged from most preferred to the least.")
92+
8993
clientOptions.BindFlags(flag.CommandLine)
9094
logOptions.BindFlags(flag.CommandLine)
9195
leaderElectionOptions.BindFlags(flag.CommandLine)
9296
aclOptions.BindFlags(flag.CommandLine)
9397
rateLimiterOptions.BindFlags(flag.CommandLine)
98+
featureGates.BindFlags(flag.CommandLine)
99+
94100
flag.Parse()
95101

96102
log := logger.NewLogger(logOptions)
97103
ctrl.SetLogger(log)
98104

105+
err := featureGates.WithLogger(setupLog).
106+
SupportedFeatures(features.FeatureGates())
107+
if err != nil {
108+
setupLog.Error(err, "unable to load feature gates")
109+
os.Exit(1)
110+
}
111+
99112
metricsRecorder := metrics.NewRecorder()
100113
ctrlmetrics.Registry.MustRegister(metricsRecorder.Collectors()...)
101114

@@ -147,9 +160,10 @@ func main() {
147160
}
148161
// +kubebuilder:scaffold:builder
149162

150-
if managed.Enabled() {
163+
if enabled, _ := features.Enabled(features.GitManagedTransport); enabled {
151164
managed.InitManagedTransport(ctrl.Log.WithName("managed-transport"))
152165
}
166+
153167
setPreferredKexAlgos(kexAlgos)
154168

155169
setupLog.Info("starting manager")

0 commit comments

Comments
 (0)