Skip to content

Commit 0779bcf

Browse files
authoredJul 10, 2023
disable leader election when controller is not enabled (#12)
1 parent 2a23099 commit 0779bcf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎cmd/main.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,7 @@ func main() {
7878
setupLog.Error(err, "unable to build REST config")
7979
os.Exit(1)
8080
}
81-
rtOpts := config.BuildRuntimeOptions(controllerCFG.RuntimeConfig, scheme)
82-
83-
mgr, err := ctrl.NewManager(restCFG, rtOpts)
84-
if err != nil {
85-
setupLog.Error(err, "unable to create controller manager")
86-
os.Exit(1)
87-
}
88-
clientSet, err := kubernetes.NewForConfig(mgr.GetConfig())
81+
clientSet, err := kubernetes.NewForConfig(restCFG)
8982
if err != nil {
9083
setupLog.Error(err, "unable to obtain clientSet")
9184
os.Exit(1)
@@ -104,6 +97,18 @@ func main() {
10497
os.Exit(1)
10598
}
10699
enableNetworkPolicyController = configMapManager.IsControllerEnabled()
100+
if !enableNetworkPolicyController {
101+
setupLog.Info("Disabling leader election since network policy controller is not enabled")
102+
controllerCFG.RuntimeConfig.EnableLeaderElection = false
103+
}
104+
}
105+
106+
rtOpts := config.BuildRuntimeOptions(controllerCFG.RuntimeConfig, scheme)
107+
108+
mgr, err := ctrl.NewManager(restCFG, rtOpts)
109+
if err != nil {
110+
setupLog.Error(err, "unable to create controller manager")
111+
os.Exit(1)
107112
}
108113

109114
policyEndpointsManager := policyendpoints.NewPolicyEndpointsManager(mgr.GetClient(),

0 commit comments

Comments
 (0)
Failed to load comments.