Class SidecarPatchBuilder

java.lang.Object
org.mockserver.webhook.SidecarPatchBuilder

public class SidecarPatchBuilder extends Object
Builds a RFC 6902 JSON Patch that injects the MockServer sidecar container and iptables-REDIRECT init container into a Kubernetes Pod spec.

The patch is designed for use in a MutatingAdmissionWebhook response. It adds:

  1. An init container that sets up iptables REDIRECT rules with UID-based loop-avoidance (the same pattern used in the Helm chart's sidecar.iptables)
  2. A MockServer sidecar container with transparent proxy enabled
  3. An idempotency marker annotation to prevent double-injection
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.fasterxml.jackson.databind.node.ArrayNode
    buildPatch(com.fasterxml.jackson.databind.JsonNode podSpec)
    Builds a JSON Patch (RFC 6902) array to inject the MockServer sidecar and iptables init container into the given pod.
    boolean
    shouldInject(com.fasterxml.jackson.databind.JsonNode podSpec)
    Determines whether the given pod should be injected with the MockServer sidecar.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • shouldInject

      public boolean shouldInject(com.fasterxml.jackson.databind.JsonNode podSpec)
      Determines whether the given pod should be injected with the MockServer sidecar.
      Parameters:
      podSpec - the pod object from the admission review (the full pod, not just spec)
      Returns:
      true if the pod opts in via annotation and has not already been injected
    • buildPatch

      public com.fasterxml.jackson.databind.node.ArrayNode buildPatch(com.fasterxml.jackson.databind.JsonNode podSpec)
      Builds a JSON Patch (RFC 6902) array to inject the MockServer sidecar and iptables init container into the given pod.
      Parameters:
      podSpec - the pod object from the admission review
      Returns:
      a JSON Patch array node