Package org.mockserver.webhook
Class AdmissionReviewHandler
java.lang.Object
org.mockserver.webhook.AdmissionReviewHandler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Creates an AdmissionReview response that allows the request without any patch.byte[]createAllowWithMessage(String uid, String message) Creates an AdmissionReview response that allows the request but includes a status message explaining why no mutation was performed.byte[]handleAdmissionReview(byte[] requestBody) Processes an AdmissionReview request and returns the AdmissionReview response JSON.byte[]handleAdmissionReview(com.fasterxml.jackson.databind.JsonNode request) Processes an AdmissionReview request and returns the AdmissionReview response JSON bytes.
-
Constructor Details
-
AdmissionReviewHandler
-
-
Method Details
-
handleAdmissionReview
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
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
Creates an AdmissionReview response that allows the request but includes a status message explaining why no mutation was performed.- Parameters:
uid- the request UIDmessage- the status message- Returns:
- the response JSON bytes
- Throws:
IOException- if serialisation fails
-