1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-08 17:06:57 +00:00
kyverno/test/conformance/kuttl/mutate/e2e/patchesjson6902-simple/policy.yaml
Chip Zoller 21da0f335e
Migrate all mutate e2e tests to kuttl and expand (#5491)
* add jmespath-logic test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add simple-conditional test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add variables-in-keys test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add patchesjson6902-simple

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add foreach-patchStrategicMerge-preconditions test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add patchStrategicMerge-global test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add patchStrategicMerge-global-addifnotpresent test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add patchesJson6902-replace test

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* adjust "basic" mutate existing test to prep for e2e migrations

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add basic-create test (mutate existing)

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add basic-delete test (mutate existing)

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add basic-create-policy test (mutate existing)

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* add basic-create-patchesJson6902 test (mutate existing)

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

* change name to avoid deletion race

Signed-off-by: Chip Zoller <chipzoller@gmail.com>

Signed-off-by: Chip Zoller <chipzoller@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
2022-11-29 08:40:57 +00:00

77 lines
2.2 KiB
YAML

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: add-image-as-env-var
# env array needs to exist (least one env var is present)
spec:
background: false
schemaValidation: false
rules:
# One Pod
- name: pod-containers-1-inject-image
match:
any:
- resources:
kinds:
- Pod
preconditions:
all:
- key: "{{request.object.spec.containers[] | length(@)}}"
operator: GreaterThanOrEquals
value: 1
mutate:
patchesJson6902: |-
- op: add
path: "/spec/containers/0/env/-"
value: {"name":"K8S_IMAGE","value":"{{request.object.spec.containers[0].image}}"}
# Two or more Pods
- name: pod-containers-2-inject-image
match:
any:
- resources:
kinds:
- Pod
preconditions:
all:
- key: "{{request.object.spec.containers[] | length(@)}}"
operator: GreaterThanOrEquals
value: 2
mutate:
patchesJson6902: |-
- op: add
path: "/spec/containers/1/env/-"
value: {"name":"K8S_IMAGE","value":"{{request.object.spec.containers[1].image}}"}
# Deployment with one Pod
- name: deploy-containers-1-inject-image
match:
any:
- resources:
kinds:
- Deployment
preconditions:
all:
- key: "{{request.object.spec.template.spec.containers[] | length(@)}}"
operator: GreaterThanOrEquals
value: 1
mutate:
patchesJson6902: |-
- op: add
path: "/spec/template/spec/containers/0/env/-"
value: {"name":"K8S_IMAGE","value":"{{request.object.spec.template.spec.containers[0].image}}"}
# Deployment with two or more Pods
- name: deploy-containers-2-inject-image
match:
any:
- resources:
kinds:
- Deployment
preconditions:
all:
- key: "{{request.object.spec.template.spec.containers[] | length(@)}}"
operator: GreaterThanOrEquals
value: 2
mutate:
patchesJson6902: |-
- op: add
path: "/spec/template/spec/containers/1/env/-"
value: {"name":"K8S_IMAGE","value":"{{request.object.spec.template.spec.containers[1].image}}"}