Class AdmissionReviewHandler

java.lang.Object
org.mockserver.webhook.AdmissionReviewHandler

public class AdmissionReviewHandler extends Object
Handles Kubernetes MutatingAdmissionWebhook requests (admission.k8s.io/v1).

Given an AdmissionReview JSON for a Pod CREATE, returns an AdmissionResponse with a base64-encoded JSONPatch that injects the MockServer sidecar container and iptables init container — but only when the pod opts in via annotation and has not already been injected.

This handler is stateless and safe to call concurrently.

  • Constructor Details

  • Method Details

    • handleAdmissionReview

      public byte[] handleAdmissionReview(byte[] requestBody) throws IOException
      Processes an AdmissionReview request and returns the AdmissionReview response JSON.
      Parameters:
      requestBody - the raw JSON bytes of the AdmissionReview request
      Returns:
      the AdmissionReview response JSON bytes
      Throws:
      IOException - if the request body cannot be parsed
    • handleAdmissionReview

      public byte[] handleAdmissionReview(com.fasterxml.jackson.databind.JsonNode request) throws IOException
      Processes an AdmissionReview request and returns the AdmissionReview response JSON bytes.
      Parameters:
      request - the parsed AdmissionReview request
      Returns:
      the AdmissionReview response JSON bytes
      Throws:
      IOException - if response serialisation fails
    • createAllowResponse

      public byte[] createAllowResponse(String uid) throws IOException
      Creates an AdmissionReview response that allows the request without any patch. Used for non-CREATE operations or error fallback.
      Parameters:
      uid - the request UID
      Returns:
      the allow-only response JSON bytes
      Throws:
      IOException - if serialisation fails
    • createAllowWithMessage

      public byte[] createAllowWithMessage(String uid, String message) throws IOException
      Creates an AdmissionReview response that allows the request but includes a status message explaining why no mutation was performed.
      Parameters:
      uid - the request UID
      message - the status message
      Returns:
      the response JSON bytes
      Throws:
      IOException - if serialisation fails