Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit efc9269

Browse files
committed
manager: configure webhook port
1 parent 2b4567a commit efc9269

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

main.go

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19+
"errors"
1920
"flag"
2021
"os"
2122

@@ -50,13 +51,12 @@ func init() {
5051
func main() {
5152

5253
var (
53-
metricsAddr string
54-
healthAddr string
5554
enableLeaderElection bool
55+
healthAddr string
56+
metricsAddr string
57+
webhookPort int
5658
)
5759

58-
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
59-
6060
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
6161
"Enable leader election for controller manager. "+
6262
"Enabling this will ensure there is only one active controller manager.")
@@ -67,6 +67,14 @@ func main() {
6767
"The address the health endpoint binds to.",
6868
)
6969

70+
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
71+
72+
flag.IntVar(&webhookPort,
73+
"webhook-port",
74+
0,
75+
"Webhook Server port, disabled by default. When enabled, the manager will only work as webhook server, no reconcilers are installed.",
76+
)
77+
7078
flag.Parse()
7179

7280
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
@@ -80,7 +88,7 @@ func main() {
8088
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
8189
Scheme: scheme,
8290
MetricsBindAddress: metricsAddr,
83-
Port: 9443,
91+
Port: webhookPort,
8492
EventBroadcaster: broadcaster,
8593
LeaderElection: enableLeaderElection,
8694
LeaderElectionID: "cad3ba79.cluster.x-k8s.io",
@@ -98,24 +106,30 @@ func main() {
98106
os.Exit(1)
99107
}
100108

101-
if err = (&controllers.PacketClusterReconciler{
102-
Client: mgr.GetClient(),
103-
Log: ctrl.Log.WithName("controllers").WithName("PacketCluster"),
104-
Recorder: mgr.GetEventRecorderFor("packetcluster-controller"),
105-
PacketClient: client,
106-
Scheme: mgr.GetScheme(),
107-
}).SetupWithManager(mgr); err != nil {
108-
setupLog.Error(err, "unable to create controller", "controller", "PacketCluster")
109-
os.Exit(1)
110-
}
111-
if err = (&controllers.PacketMachineReconciler{
112-
Client: mgr.GetClient(),
113-
Log: ctrl.Log.WithName("controllers").WithName("PacketMachine"),
114-
Scheme: mgr.GetScheme(),
115-
Recorder: mgr.GetEventRecorderFor("packetmachine-controller"),
116-
PacketClient: client,
117-
}).SetupWithManager(mgr); err != nil {
118-
setupLog.Error(err, "unable to create controller", "controller", "PacketMachine")
109+
if webhookPort == 0 {
110+
if err = (&controllers.PacketClusterReconciler{
111+
Client: mgr.GetClient(),
112+
Log: ctrl.Log.WithName("controllers").WithName("PacketCluster"),
113+
Recorder: mgr.GetEventRecorderFor("packetcluster-controller"),
114+
PacketClient: client,
115+
Scheme: mgr.GetScheme(),
116+
}).SetupWithManager(mgr); err != nil {
117+
setupLog.Error(err, "unable to create controller", "controller", "PacketCluster")
118+
os.Exit(1)
119+
}
120+
if err = (&controllers.PacketMachineReconciler{
121+
Client: mgr.GetClient(),
122+
Log: ctrl.Log.WithName("controllers").WithName("PacketMachine"),
123+
Scheme: mgr.GetScheme(),
124+
Recorder: mgr.GetEventRecorderFor("packetmachine-controller"),
125+
PacketClient: client,
126+
}).SetupWithManager(mgr); err != nil {
127+
setupLog.Error(err, "unable to create controller", "controller", "PacketMachine")
128+
os.Exit(1)
129+
}
130+
} else {
131+
// TODO: add the webhook configuration
132+
setupLog.Error(errors.New("webhook not implemented"), "webhook", "not available")
119133
os.Exit(1)
120134
}
121135
// +kubebuilder:scaffold:builder

0 commit comments

Comments
 (0)