Class WebhookServer

java.lang.Object
org.mockserver.webhook.WebhookServer

public class WebhookServer extends Object
Kubernetes MutatingAdmissionWebhook HTTPS server.

Starts an HTTPS server that:

  • POST /inject — handles AdmissionReview requests (delegates to AdmissionReviewHandler)
  • GET /healthz — returns 200 for readiness/liveness probes

TLS cert + key are loaded from file paths (env-configurable). Sidecar injection config is read from environment variables so Helm values flow through.

  • Constructor Details

    • WebhookServer

      public WebhookServer(InetSocketAddress bindAddress, SSLContext sslContext, SidecarInjectionConfig config) throws IOException
      Creates a WebhookServer that binds to the given address using the provided SSLContext.
      Parameters:
      bindAddress - the address/port to bind to
      sslContext - the SSL context for HTTPS
      config - the sidecar injection configuration
      Throws:
      IOException - if the server cannot bind
  • Method Details

    • start

      public void start()
      Starts the HTTPS server.
    • stop

      public void stop(int delaySeconds)
      Stops the HTTPS server gracefully.
      Parameters:
      delaySeconds - seconds to wait for in-flight requests
    • getPort

      public int getPort()
      Returns the port the server is listening on. Useful for tests with ephemeral ports.
    • buildSslContext

      public static SSLContext buildSslContext(Path certPath, Path keyPath) throws Exception
      Builds an SSLContext from PEM-encoded certificate and private key files.
      Parameters:
      certPath - path to the PEM certificate file (may contain a chain)
      keyPath - path to the PEM private key file (PKCS#8)
      Returns:
      a configured SSLContext
      Throws:
      Exception
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception