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 all 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
28 changes: 28 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,28 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
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: resource.yaml
- assert:
file: patchresource.yaml
- error:
resource:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: within-ns
labels:
kubernetes.io/metadata.name: "within-ns"
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
66 changes: 66 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/patchresource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-1
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
spec:
containers:
- name: good-app-deploy
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-3
namespace: within-ns
labels:
owner: "any-corp"
env: dev
spec:
replicas: 1
selector:
matchLabels:
app: my-app03
template:
metadata:
labels:
app: my-app03
spec:
containers:
- name: my-app03-deploy
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-4
namespace: within-ns
labels:
owner: "any-corp"
env: dev
spec:
replicas: 1
selector:
matchLabels:
app: my-app04
template:
metadata:
labels:
app: my-app04
spec:
containers:
- name: my-app04-deploy
image: busybox:1.35
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
60 changes: 60 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-1
namespace: within-ns
labels:
app: good-app
spec:
replicas: 1
selector:
matchLabels:
app: good-app
template:
metadata:
labels:
app: good-app
spec:
containers:
- name: good-app-deploy
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-3
namespace: within-ns
labels:
owner: "dev-team"
spec:
replicas: 1
selector:
matchLabels:
app: my-app03
template:
metadata:
labels:
app: my-app03
spec:
containers:
- name: my-app03-deploy
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-4
namespace: within-ns
spec:
replicas: 1
selector:
matchLabels:
app: my-app04
template:
metadata:
labels:
app: my-app04
spec:
containers:
- name: my-app04-deploy
image: busybox:1.35
Loading