Skip to content

Commit

Permalink
Merge pull request #946 from Chandan-DK/other-policies-cel-part-1
Browse files Browse the repository at this point in the history
feat: add other policies in CEL expressions - Part 1
  • Loading branch information
JimBugwadia authored May 15, 2024
2 parents 7949c9e + 065e052 commit 8e31d60
Show file tree
Hide file tree
Showing 107 changed files with 3,962 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
- ^other$/^re[c-q]
- ^other$/^res
- ^other$/^[s-z]
- ^other-cel$/^a
- ^other-cel$/^[b-d]
- ^other-cel$/^[m-q]
- ^pod-security$
- ^pod-security-cel$
Expand Down
39 changes: 39 additions & 0 deletions other-cel/allowed-annotations/.chainsaw-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: allowed-annotations
spec:
steps:
- name: step-01
try:
- apply:
file: ../allowed-annotations.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: allowed-annotations
spec:
validationFailureAction: Enforce
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: pod-good.yaml
- apply:
file: podcontroller-good.yaml
- apply:
expect:
- check:
($error != null): true
file: pod-bad.yaml
- apply:
expect:
- check:
($error != null): true
file: podcontroller-bad.yaml

47 changes: 47 additions & 0 deletions other-cel/allowed-annotations/.chainsaw-test/pod-bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
fluxcd.io/cat: meow
name: badpod01
spec:
containers:
- name: pod01-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
foo: bar
fluxcd.io/foo: bar
name: badpod02
spec:
containers:
- name: pod02-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
fluxcd.io/bar: foo
foo: bar
name: badpod03
spec:
containers:
- name: pod-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
fluxcd.io/bar: foo
fluxcd.io/cow: moo
name: badpod04
spec:
containers:
- name: pod-01
image: busybox:1.35

45 changes: 45 additions & 0 deletions other-cel/allowed-annotations/.chainsaw-test/pod-good.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: v1
kind: Pod
metadata:
name: goodpod01
spec:
containers:
- name: pod01-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
foo: bar
fluxcd.io/cow: ox
fluxcd.io/dog: cat
name: goodpod02
spec:
containers:
- name: pod02-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
foo: bar
name: goodpod03
spec:
containers:
- name: pod-01
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
annotations:
fluxcd.io/cow: moo
foo: bar
name: goodpod04
spec:
containers:
- name: pod-01
image: busybox:1.35

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: baddeployment01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
foo: bar
fluxcd.io/foo: bar
labels:
app: busybox
spec:
containers:
- name: bb-01
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: baddeployment02
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
fluxcd.io/cat: meow
fluxcd.io/cow: moo
labels:
app: busybox
spec:
containers:
- name: bb-01
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: badcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
foo: bar
fluxcd.io/foo: bar
spec:
containers:
- name: hello
image: busybox:1.35
imagePullPolicy: IfNotPresent
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: badcronjob02
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
fluxcd.io/cat: meow
fluxcd.io/cow: moo
spec:
containers:
- name: hello
image: busybox:1.35
imagePullPolicy: IfNotPresent
command:
- "sleep"
- "3600"
restartPolicy: OnFailure

132 changes: 132 additions & 0 deletions other-cel/allowed-annotations/.chainsaw-test/podcontroller-good.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeployment01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
foo: bar
labels:
app: busybox
spec:
containers:
- name: bb-01
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeployment02
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
fluxcd.io/cow: moo
fluxcd.io/dog: bark
labels:
app: busybox
spec:
containers:
- name: bb-01
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeployment03
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: bb-01
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
foo: bar
spec:
containers:
- name: hello
image: busybox:1.35
imagePullPolicy: IfNotPresent
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob02
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
fluxcd.io/cow: moo
fluxcd.io/dog: bark
spec:
containers:
- name: hello
image: busybox:1.35
imagePullPolicy: IfNotPresent
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob03
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.35
imagePullPolicy: IfNotPresent
command:
- "sleep"
- "3600"
restartPolicy: OnFailure

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: allowed-annotations
status:
ready: true

Loading

0 comments on commit 8e31d60

Please sign in to comment.