Last active
August 4, 2025 13:53
-
-
Save Nathanael-Mtd/9290faef3163acb653c34a556b8f6d5d to your computer and use it in GitHub Desktop.
Kyverno policy : Mutate pods to redirect bitnami to bitnamilegacy image repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apiVersion: kyverno.io/v1 | |
| kind: ClusterPolicy | |
| metadata: | |
| name: replace-bitnami-image-repository-with-bitnamilegacy | |
| annotations: | |
| policies.kyverno.io/title: Replace Bitnami Image Repository With Bitnami Legacy | |
| pod-policies.kyverno.io/autogen-controllers: none | |
| policies.kyverno.io/subject: Pod | |
| spec: | |
| rules: | |
| - name: redirect-bitnami-to-bitnamilegacy | |
| match: | |
| any: | |
| - resources: | |
| kinds: | |
| - Pod | |
| operations: | |
| - CREATE | |
| - UPDATE | |
| mutate: | |
| foreach: | |
| - list: request.object.spec.initContainers[] | |
| context: | |
| - name: imageData | |
| imageRegistry: | |
| reference: "{{ element.image }}" | |
| preconditions: | |
| any: | |
| - key: "{{ regex_match('^(docker\\.io)/(bitnami)/(.*)$', '{{element.image}}') }}" | |
| operator: Equals | |
| value: true | |
| patchStrategicMerge: | |
| spec: | |
| initContainers: | |
| - name: "{{ element.name }}" | |
| image: "{{ regex_replace_all('^(docker\\.io)/(bitnami)/(.*)$', '{{element.image}}', '$1/bitnamilegacy/$3' )}}" | |
| - list: request.object.spec.containers[] | |
| context: | |
| - name: imageData | |
| imageRegistry: | |
| reference: "{{ element.image }}" | |
| preconditions: | |
| any: | |
| - key: "{{ regex_match('^(docker\\.io)/(bitnami)/(.*)$', '{{element.image}}') }}" | |
| operator: Equals | |
| value: true | |
| patchStrategicMerge: | |
| spec: | |
| containers: | |
| - name: "{{ element.name }}" | |
| image: "{{ regex_replace_all('^(docker\\.io)/(bitnami)/(.*)$', '{{element.image}}', '$1/bitnamilegacy/$3' )}}" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably not perfect, it only handle image source in docker.io/bitnami/xxx format.
It only apply on new or updated pods, not on existing ones. A restart on StatefulSet/Deploy, or a change on Pod object is needed.