Skip to content

Commit

Permalink
Adds chainsaw tests
Browse files Browse the repository at this point in the history
Signed-off-by: Darkhood148 <[email protected]>
  • Loading branch information
Darkhood148 committed Jan 22, 2025
1 parent 15ef878 commit d37184c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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: block-kubectl-cp-by-pod-label
spec:
steps:
- name: step-01
try:
- apply:
file: ../block-kubectl-cp-by-pod-label.yaml
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: ns.yaml
- apply:
file: pods.yaml
- name: step-03
try:
- sleep:
duration: 5s
- name: step-04
try:
- script:
content: if kubectl cp -n bkc-podlabel-ns pod03:/test3.txt ./test3.txt; then exit 1;else
exit 0; fi
- script:
content: kubectl cp -n bkc-podlabel-ns pod01:/test1.txt ./test1.txt; exit 0;
- script:
content: kubectl cp -n bkc-podlabel-ns pod02:/test2.txt ./test2.txt; exit 0;
- script:
content: kubectl cp -n bkc-podlabel-ns pod04:/test4.txt ./test4.txt; exit 0;
- name: step-05
try:
- script:
content: rm -rf ./test1.txt
- script:
content: rm -rf ./test2.txt
- script:
content: rm -rf ./test3.txt
- script:
content: rm -rf ./test4.txt
4 changes: 4 additions & 0 deletions other/block-kubectl-cp-by-pod-label/.chainsaw-test/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: bkc-podlabel-ns
63 changes: 63 additions & 0 deletions other/block-kubectl-cp-by-pod-label/.chainsaw-test/pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: v1
kind: Pod
metadata:
name: pod01
namespace: bkc-podlabel-ns
spec:
containers:
- name: busybox
image: busybox:1.35
command: ["/bin/sh", "-c"]
args:
- touch /test1.txt
- sleep 300
---
apiVersion: v1
kind: Pod
metadata:
labels:
foo: bar
name: pod02
namespace: bkc-podlabel-ns
spec:
containers:
- name: busybox
image: busybox:1.35
command: [ "/bin/sh", "-c" ]
args:
- touch /test2.txt
- sleep 300
---
apiVersion: v1
kind: Pod
metadata:
labels:
foo: bar
cp: "false"
name: pod03
namespace: bkc-podlabel-ns
spec:
containers:
- name: busybox
image: busybox:1.35
command: [ "/bin/sh", "-c" ]
args:
- touch /test3.txt
- sleep 300
---
apiVersion: v1
kind: Pod
metadata:
labels:
cp: "true"
foo: bar
name: pod04
namespace: bkc-podlabel-ns
spec:
containers:
- name: busybox
image: busybox:1.35
command: [ "/bin/sh", "-c" ]
args:
- touch /test4.txt
- sleep 300
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-kubectl-cp-by-pod-label
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

0 comments on commit d37184c

Please sign in to comment.