Skip to content

Support namespaceObject in MAP #12

Description

@utam0k

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
          }
        ]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions