Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add other policies in CEL expressions - Part 4 #964

Merged
merged 32 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
182c23e
add CI test for other-cel re(c-q) directories
Chandan-DK Apr 9, 2024
3379669
copy require-annotations
Chandan-DK Apr 9, 2024
8906909
add kyverno tests for require-annotations
Chandan-DK Apr 9, 2024
35af3d8
convert require-annotations to cel
Chandan-DK Apr 9, 2024
424424f
copy require-deployments-have-multiple-replicas
Chandan-DK Apr 9, 2024
b426610
add fail kyverno tests for require-deployments-have-multiple-replica
Chandan-DK Apr 9, 2024
fbbe2cc
convert require-deployments-have-multiple-replicas to cel
Chandan-DK Apr 9, 2024
4a1cfb0
copy require-image-checksum
Chandan-DK Apr 10, 2024
4acf9ed
convert require-image-checksum to cel
Chandan-DK Apr 10, 2024
9ac723b
copy require-ingress-https
Chandan-DK Apr 10, 2024
27cf3ab
add kyverno tests for require-ingress-https
Chandan-DK Apr 10, 2024
ed1ac4d
convert require-ingress-https to cel
Chandan-DK Apr 10, 2024
946d40d
Merge branch 'main' into other-policies-cel-part-4
Chandan-DK Apr 10, 2024
2c32b04
copy require-pod-priorityclassname
Chandan-DK Apr 11, 2024
626a29e
convert require-pod-priorityclassname to cel
Chandan-DK Apr 11, 2024
e0381af
copy require-qos-burstable
Chandan-DK Apr 11, 2024
dbed4d6
convert require-qos-burstable to cel
Chandan-DK Apr 11, 2024
6f5e93c
copy require-storageclass
Chandan-DK Apr 11, 2024
d82679f
convert require-storageclass to cel
Chandan-DK Apr 11, 2024
32c6863
rename files for clarity
Chandan-DK Apr 12, 2024
8ee9d76
add a new line at the end of files
Chandan-DK Apr 12, 2024
4faf096
update digest
Chandan-DK Apr 12, 2024
bd9c111
add corresponding kyverno tests in other folder
Chandan-DK Apr 15, 2024
fbd4cb0
use has() in cel expression for readability
Chandan-DK Apr 23, 2024
eed80c6
remove extra whitespace and line
Chandan-DK Apr 23, 2024
59d6541
Merge branch 'main' into other-policies-cel-part-4
MariamFahmy98 May 13, 2024
cab2f56
Merge branch 'main' into other-policies-cel-part-4
Chandan-DK May 15, 2024
ed87d82
resolve conflicts
Chandan-DK May 15, 2024
0e117fa
Merge branch 'main' into other-policies-cel-part-4
Chandan-DK May 15, 2024
ea44c2b
remove duplicate tests
Chandan-DK May 16, 2024
77118ba
Merge branch 'main' into other-policies-cel-part-4
MariamFahmy98 May 22, 2024
665d5e5
Merge branch 'main' into other-policies-cel-part-4
MariamFahmy98 May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-annotations
status:
ready: true
38 changes: 38 additions & 0 deletions other-cel/require-annotations/.chainsaw-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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: require-annotations
spec:
steps:
- name: step-01
try:
- apply:
file: ../require-annotations.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-annotations
spec:
validationFailureAction: Enforce
- assert:
file: chainsaw-step-01-assert-1.yaml
Chandan-DK marked this conversation as resolved.
Show resolved Hide resolved
- name: step-02
try:
- apply:
file: pod-good.yaml
- apply:
expect:
- check:
($error != null): true
file: pod-bad.yaml
- apply:
file: podcontroller-good.yaml
- apply:
expect:
- check:
($error != null): true
file: podcontroller-bad.yaml
19 changes: 19 additions & 0 deletions other-cel/require-annotations/.chainsaw-test/pod-bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
corp.org/department: ""
name: badpod01
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: v1
kind: Pod
metadata:
name: badpod02
spec:
containers:
- name: busybox
image: busybox:1.35
10 changes: 10 additions & 0 deletions other-cel/require-annotations/.chainsaw-test/pod-good.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
corp.org/department: "foo"
name: goodpod01
spec:
containers:
- name: busybox
image: busybox:1.35
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: baddeployment01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
corp.org/department: ""
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: badcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
spec:
containers:
- name: busybox
image: busybox:1.35
restartPolicy: OnFailure
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeployment01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
strategy: {}
template:
metadata:
annotations:
corp.org/department: "foo"
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
corp.org/department: "foo"
spec:
containers:
- name: busybox
image: busybox:1.35
restartPolicy: OnFailure
21 changes: 21 additions & 0 deletions other-cel/require-annotations/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: require-annotations
version: 1.0.0
displayName: Require Annotations
createdAt: "2023-04-10T20:30:05.000Z"
description: >-
Define and use annotations that identify semantic attributes of your application or Deployment. A common set of annotations allows tools to work collaboratively, describing objects in a common manner that all tools can understand. The recommended annotations describe applications in a way that can be queried. This policy validates that the annotation `corp.org/department` is specified with some value.
install: |-
```shell
kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/other/require-annotations/require-annotations.yaml
```
keywords:
- kyverno
- Other
readme: |
Define and use annotations that identify semantic attributes of your application or Deployment. A common set of annotations allows tools to work collaboratively, describing objects in a common manner that all tools can understand. The recommended annotations describe applications in a way that can be queried. This policy validates that the annotation `corp.org/department` is specified with some value.

Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/
annotations:
kyverno/category: "Other"
kyverno/subject: "Pod, Annotation"
digest: fafe53fa9a2931eba4755bff2e2a8dfeced08c3fa02593c966d9a07fdd4ae604
30 changes: 30 additions & 0 deletions other-cel/require-annotations/require-annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-annotations
annotations:
policies.kyverno.io/title: Require Annotations
policies.kyverno.io/category: Other
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod, Annotation
policies.kyverno.io/description: >-
Define and use annotations that identify semantic attributes of your application or Deployment.
A common set of annotations allows tools to work collaboratively, describing objects in a common manner that
all tools can understand. The recommended annotations describe applications in a way that can be
queried. This policy validates that the annotation `corp.org/department` is specified with some value.
spec:
validationFailureAction: audit
background: true
rules:
- name: check-for-annotation
match:
any:
- resources:
kinds:
- Pod
validate:
message: "The annotation `corp.org/department` is required."
pattern:
metadata:
annotations:
corp.org/department: "?*"