Skip to content

Commit aa4f9ec

Browse files
committed
Return early if no webhooks are registered
1 parent cacab52 commit aa4f9ec

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • crates/stackable-webhook/src

crates/stackable-webhook/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ impl WebhookServer {
158158

159159
/// Runs the Webhook server and sets up signal handlers for shutting down.
160160
///
161-
/// This does not implement graceful shutdown of the underlying server.
161+
/// This does not implement graceful shutdown of the underlying server. Additionally, the server
162+
/// is never started in cases where no [`Webhook`] is registered. Callers of this function need
163+
/// to ensure to choose the correct joining mechanism for their use-case to for example avoid
164+
/// unexpected shutdowns of the whole Kubernetes controller.
162165
pub async fn run(self) -> Result<()> {
163166
let future_server = self.run_server();
164167
let future_signal = async {
@@ -207,6 +210,14 @@ impl WebhookServer {
207210
tls_server,
208211
mut cert_rx,
209212
} = self;
213+
214+
// If no webhooks are registered exit immediately without spanning the TLS server and the
215+
// certificate rotation loop.
216+
if webhooks.is_empty() {
217+
tracing::debug!("no registered webhooks, returning without starting TLS server");
218+
return Ok(());
219+
}
220+
210221
let tls_server = tls_server
211222
.run()
212223
.map_err(|err| WebhookServerError::RunTlsServer { source: err });

0 commit comments

Comments
 (0)