Skip to content

Commit 6c32582

Browse files
JeffwanCopilot
andauthored
[CLI] Add —disableWebhook in controller (#931)
* [CLI] Add —disableWebhook in controller Signed-off-by: Jiaxin Shan <[email protected]> * Disable webhook for some standalone controllers Signed-off-by: Jiaxin Shan <[email protected]> * Update cmd/controllers/main.go Co-authored-by: Copilot <[email protected]> Signed-off-by: Jiaxin Shan <[email protected]> --------- Signed-off-by: Jiaxin Shan <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a27df3f commit 6c32582

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

cmd/controllers/main.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func main() {
111111
var controllers string
112112
var modeladapterSchedulerPolicy string
113113
var enableRuntimeSidecar bool
114+
var disableWebhook bool
114115
var debugMode bool
115116
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
116117
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -136,6 +137,8 @@ func main() {
136137
flag.StringVar(&modeladapterSchedulerPolicy, "model-adapter-scheduler-policy", modeladapter.DefaultModelAdapterSchedulerPolicy, "model-adapter-scheduler-policy is the name of the scheduler policy to use for model adapter controller.")
137138
flag.BoolVar(&enableRuntimeSidecar, "enable-runtime-sidecar", false,
138139
"If set, Runtime management API will be enabled for the metrics, model adapter and model downloading interactions, control plane will not talk to engine directly anymore")
140+
flag.BoolVar(&disableWebhook, "disable-webhook", false,
141+
"If set, mutation and validation webhook will be disabled, this will be only used in standalone setup mode for some controllers")
139142
flag.BoolVar(&debugMode, "debug-mode", false,
140143
"If set, control plane will talk to localhost nodePort for testing purpose")
141144

@@ -178,9 +181,12 @@ func main() {
178181

179182
runtimeConfig := config.NewRuntimeConfig(enableRuntimeSidecar, debugMode, modeladapterSchedulerPolicy)
180183

181-
webhookServer := webhook.NewServer(webhook.Options{
182-
TLSOpts: tlsOpts,
183-
})
184+
var webhookServer webhook.Server
185+
if !disableWebhook {
186+
webhookServer = webhook.NewServer(webhook.Options{
187+
TLSOpts: tlsOpts,
188+
})
189+
}
184190

185191
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
186192
Scheme: scheme,
@@ -240,9 +246,14 @@ func main() {
240246

241247
certsReady := make(chan struct{})
242248

243-
if err = cert.CertsManager(mgr, leaderElectionNamespace, certsReady); err != nil {
244-
setupLog.Error(err, "unable to setup cert rotation")
245-
os.Exit(1)
249+
if disableWebhook {
250+
setupLog.Info("Closing the certsReady channel because the webhook is disabled, this is to avoid blocking setupControllers")
251+
close(certsReady)
252+
} else {
253+
if err = cert.CertsManager(mgr, leaderElectionNamespace, certsReady); err != nil {
254+
setupLog.Error(err, "unable to setup cert rotation")
255+
os.Exit(1)
256+
}
246257
}
247258

248259
// Initialize controllers
@@ -254,7 +265,7 @@ func main() {
254265
// Cert won't be ready until manager starts, so start a goroutine here which
255266
// will block until the cert is ready before setting up the controllers.
256267
// Controllers who register after manager starts will start directly.
257-
go setupControllers(mgr, runtimeConfig, certsReady)
268+
go setupControllers(mgr, runtimeConfig, certsReady, disableWebhook)
258269

259270
//+kubebuilder:scaffold:builder
260271

@@ -274,12 +285,15 @@ func main() {
274285
}
275286
}
276287

277-
func setupControllers(mgr ctrl.Manager, runtimeConfig config.RuntimeConfig, certsReady chan struct{}) {
288+
// TODO: if the argument list will grow, we should create a ControllerSetupOptions struct instead.
289+
func setupControllers(mgr ctrl.Manager, runtimeConfig config.RuntimeConfig, certsReady chan struct{}, disableWebhook bool) {
278290
// The controllers won't work until the webhooks are operating,
279291
// and the webhook won't work until the certs are all in places.
280-
setupLog.Info("waiting for the cert generation to complete")
281-
<-certsReady
282-
setupLog.Info("certs ready")
292+
if !disableWebhook {
293+
setupLog.Info("waiting for the cert generation to complete")
294+
<-certsReady
295+
setupLog.Info("certs ready")
296+
}
283297

284298
// Kind controller registration is encapsulated inside the pkg/controller/controller.go
285299
// So here we can use more clean registration flow and there's no need to change logics in future.
@@ -288,8 +302,12 @@ func setupControllers(mgr ctrl.Manager, runtimeConfig config.RuntimeConfig, cert
288302
os.Exit(1)
289303
}
290304

291-
if err := apiwebhook.SetupBackendRuntimeWebhook(mgr); err != nil {
292-
setupLog.Error(err, "unable to create webhook", "webhook", "Model")
293-
os.Exit(1)
305+
if !disableWebhook {
306+
if err := apiwebhook.SetupBackendRuntimeWebhook(mgr); err != nil {
307+
setupLog.Error(err, "unable to create webhook", "webhook", "Model")
308+
os.Exit(1)
309+
}
310+
} else {
311+
setupLog.Info("webhook setup skipped due to --disable-webhook flag")
294312
}
295313
}

config/standalone/autoscaler-controller/patch.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ spec:
1313
- --leader-election-id=aibrix-pod-autoscaler-controller
1414
- --health-probe-bind-address=:8081
1515
- --metrics-bind-address=0
16-
- --controllers=pod-autoscaler-controller
16+
- --controllers=pod-autoscaler-controller
17+
- --disable-webhook

config/standalone/distributed-inference-controller/patch.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ spec:
1313
- --leader-election-id=aibrix-distributed-inference-controller
1414
- --health-probe-bind-address=:8081
1515
- --metrics-bind-address=0
16-
- --controllers=distributed-inference-controller
16+
- --controllers=distributed-inference-controller
17+
- --disable-webhook

config/standalone/model-adapter-controller/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ resources:
66
- ../../rbac/model
77
- ../../rbac/controller-manager
88
- ../../manager
9+
# lora needs webhook manifest
10+
- ../../webhook
11+
- ../../internalcert
912

1013
# Adds namespace to all resources.
1114
namespace: aibrix-system

config/standalone/model-adapter-controller/patch.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ spec:
1313
- --leader-election-id=aibrix-model-adapter-controller
1414
- --health-probe-bind-address=:8081
1515
- --metrics-bind-address=0
16-
- --controllers=model-adapter-controller
16+
- --controllers=model-adapter-controller
17+
# following patch is from config/default/manager_webhook_patch.yaml
18+
ports:
19+
- containerPort: 9443
20+
name: webhook-server
21+
protocol: TCP
22+
volumeMounts:
23+
- mountPath: /tmp/k8s-webhook-server/serving-certs
24+
name: cert
25+
readOnly: true
26+
volumes:
27+
- name: cert
28+
secret:
29+
defaultMode: 420
30+
secretName: webhook-server-cert

0 commit comments

Comments
 (0)