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

Added test for copy-ns-labels policy #967

Merged
merged 17 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
47 changes: 47 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/baddeployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#Outside Namespace, deployment with owner label and kubernetes.io/metadata.name label
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-with-ouside-ns
namespace: without-ns
labels:
app: my-app
tier: frontend
spec:
replicas: 1
selector:
matchLabels:
app: my-app
tier: frontend
template:
metadata:
labels:
app: my-app
tier: frontend
owner: "any-corp"
kubernetes.io/metadata.name: "pod-with-owner-and-metadata-name"
spec:
containers:
- name: bad-deploy-outside-ns
image: nginx:1.25
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bad-deployment
namespace: within-ns
labels:
app: bad-app
spec:
replicas: 1
selector:
matchLabels:
app: bad-app
template:
metadata:
labels:
app: bad-app
spec:
containers:
- name: bad-app-deploy
image: nginx:1.25
24 changes: 24 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: copy-namespace-labels
spec:
steps:
- name: step-01
try:
- apply:
file: ns.yaml
- apply:
file: ../copy-namespace-labels.yaml
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: gooddeployment.yaml
- apply:
expect:
- check:
($error != null): true
file: baddeployment.yaml
25 changes: 25 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/gooddeployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#Within Namespace, with Owner Label and additional labels
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-with-ns
namespace: within-ns
labels:
app: good-app
owner: "any-corp"
env: dev
spec:
replicas: 1
selector:
matchLabels:
app: good-app
template:
metadata:
labels:
app: good-app
env: dev
owner: "any-corp"
spec:
containers:
- name: good-app-deploy
image: nginx:1.25
7 changes: 7 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: within-ns
labels:
owner: "any-corp"
env: dev
6 changes: 6 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/policy-ready.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: copy-namespace-labels
status:
ready: true
Loading