MAP provides access to the namespaceObject. This issue proposes adding support for testing MAP functionality using this feature.
https://kubernetes.io/docs/reference/access-authn-authz/mutating-admission-policy/#patch-type-apply-configuration
Example:
apiVersion: admissionregistration.k8s.io/v1alpha1
kind: MutatingAdmissionPolicy
metadata:
name: map-with-namespaceObject
spec:
failurePolicy: Fail
reinvocationPolicy: IfNeeded
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE"]
resources: ["pods"]
namespaceSelector: {}
objectSelector: {}
variables:
- name: test-annotation-val
expression: "namespaceObject.metadata.annotations['test']"
mutations:
- patchType: JSONPatch
jsonPatch:
expression: >
!has(object.metadata.labels) ? [
JSONPatch{
op: "add",
path: "/metadata/labels",
value: { "k8s.io/test": variables.test-annotation-val}
}
] : [
JSONPatch{
op: "add",
path: "/metadata/labels/" + jsonpatch.escapeKey("k8s.io/test"),
value: variables.test-annotation-val
}
]
MAP provides access to the namespaceObject. This issue proposes adding support for testing MAP functionality using this feature.
https://kubernetes.io/docs/reference/access-authn-authz/mutating-admission-policy/#patch-type-apply-configuration
Example: