Created
February 18, 2025 16:13
-
-
Save daemonfire300/c83c3f2830f13b3a43241143537c7b9d to your computer and use it in GitHub Desktop.
example-admission-policy
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: admissionregistration.k8s.io/v1alpha1 | |
kind: MutatingAdmissionPolicy | |
metadata: | |
name: "modify-init-container-security-context" | |
spec: | |
matchConstraints: | |
resourceRules: | |
- apiGroups: ["apps"] | |
apiVersions: ["v1"] | |
operations: ["CREATE", "UPDATE"] | |
resources: ["statefulsets"] | |
matchConditions: | |
- name: has-init-container-xxx | |
expression: "object.spec.template.spec.initContainers.exists(ic, ic.name == \"xxx\")" | |
failurePolicy: Fail | |
reinvocationPolicy: IfNeeded | |
mutations: | |
- patchType: "ApplyConfiguration" | |
applyConfiguration: | |
expression: > | |
Object{ | |
spec: Object.spec{ | |
template: Object.spec.template{ | |
spec: Object.spec.template.spec{ | |
initContainers: Object.spec.template.spec.initContainers.map(ic, | |
ic.name == "xxx" ? Object{ | |
name: ic.name, | |
image: ic.image, | |
securityContext: Object{ | |
runAsUser: 1000 | |
} | |
} : ic | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment