Skip to content

Commit 95145c6

Browse files
committed
Add centralized logging for feature gate status
Signed-off-by: Brett Tofel <[email protected]>
1 parent 384b93b commit 95145c6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Diff for: cmd/operator-controller/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ func run() error {
187187

188188
setupLog.Info("starting up the controller", "version info", version.String())
189189

190+
// log feature gate status after parsing flags and setting up logger
191+
features.LogFeatureGateStates(setupLog, features.OperatorControllerFeatureGate)
192+
190193
authFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s.json", authFilePrefix, apimachineryrand.String(8)))
191194
var globalPullSecretKey *k8stypes.NamespacedName
192195
if cfg.globalPullSecret != "" {
@@ -419,10 +422,7 @@ func run() error {
419422
// determine if PreAuthorizer should be enabled based on feature gate
420423
var preAuth authorization.PreAuthorizer
421424
if features.OperatorControllerFeatureGate.Enabled(features.PreflightPermissions) {
422-
setupLog.Info("preflight permissions check enabled via feature gate")
423425
preAuth = authorization.NewRBACPreAuthorizer(mgr.GetClient())
424-
} else {
425-
setupLog.Info("preflight permissions check disabled via feature gate")
426426
}
427427

428428
// now initialize the helmApplier, assigning the potentially nil preAuth

Diff for: internal/operator-controller/features/features.go

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package features
22

33
import (
4+
"sort"
5+
6+
"github.com/go-logr/logr"
47
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
58
"k8s.io/component-base/featuregate"
69
)
@@ -36,3 +39,20 @@ var OperatorControllerFeatureGate featuregate.MutableFeatureGate = featuregate.N
3639
func init() {
3740
utilruntime.Must(OperatorControllerFeatureGate.Add(operatorControllerFeatureGates))
3841
}
42+
43+
// LogFeatureGateStates logs the state of all known feature gates.
44+
func LogFeatureGateStates(log logr.Logger, fg featuregate.FeatureGate) {
45+
// Sort the keys for consistent logging order
46+
featureKeys := make([]featuregate.Feature, 0, len(operatorControllerFeatureGates))
47+
for k := range operatorControllerFeatureGates {
48+
featureKeys = append(featureKeys, k)
49+
}
50+
sort.Slice(featureKeys, func(i, j int) bool {
51+
return string(featureKeys[i]) < string(featureKeys[j]) // Sort by string representation
52+
})
53+
54+
log.Info("Feature Gates Status:")
55+
for _, feature := range featureKeys {
56+
log.Info(" ", "feature", string(feature), "enabled", fg.Enabled(feature))
57+
}
58+
}

0 commit comments

Comments
 (0)