Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PrePatch capabilities #7

Open
achetronic opened this issue Oct 20, 2024 · 0 comments
Open

Add PrePatch capabilities #7

achetronic opened this issue Oct 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@achetronic
Copy link
Member

The idea is to be able to patch resources before they enter the cluster. This is useful in situations where mutations are involved and other tools (like Kyverno) are not powerful enough, for example:

Imagine the user wants to patch pods from a namespace to implement a custom pod affinity/anti-affinity not already covered by Kubernetes. Patching resources can solve this with ease. An examples:

apiVersion: reforma.prosimcorp.com/v1beta1
kind: PrePatch
metadata:
   name: patch-gateway-pods
spec:
   # Sources to look for the data to make wonderful patches
   sources:
      - apiVersion: v1
        kind: Pod
        # (optional)
        #name: cluster-info
        namespace: istio-gateways

   # Target to apply patches to
   target:
      apiVersion: v1
      kind: Pod
      # (Optional) Should return a list with just one item if defined
      # name: ^(istio-gateway-stable-)(.*)
      namespace: istio-gateways

   # (required) when to act. Admited operations are those admited by MutatingWebhookConfiguration
   # Ref: https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-objectselector
   operation: create 

   # The patch type. Currently, the only supported patch by MutatinWebhookConfiguration is JsonPatch
   patchType: application/json-patch+json

   # Templating section is where you can be creative to craft a patch
   # Basically, if you know Helm templating and Kustomize patches, do what you want
   template: |
     {{- $targetList := (index . 0) -}}
     {{- $sourceList := (index . 1) -}}
     {{- $anotherSourceList := (index . 2) -}}

     {{/* The rest of the patch here to spread the pods on your own */}}

This will discussed internally, but if someone want to contribute or discuss about this topic, the discussion is open too

@achetronic achetronic added the enhancement New feature or request label Oct 20, 2024
@achetronic achetronic pinned this issue Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant