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 9 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
20 changes: 20 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,20 @@
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
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
91 changes: 91 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/patchresource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
---
#Deployment with `kubernetes.io/metadata.name` label
siddhikhapare marked this conversation as resolved.
Show resolved Hide resolved
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-2
namespace: within-ns
labels:
owner: "any-corp"
env: dev
siddhikhapare marked this conversation as resolved.
Show resolved Hide resolved
spec:
replicas: 1
selector:
matchLabels:
app: my-app02
template:
metadata:
labels:
app: my-app02
spec:
containers:
- name: my-app02-deploy
image: busybox:1.35
---
#Deployment with only `owner` label
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
---
#Deployment with no labels
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
85 changes: 85 additions & 0 deletions other/copy-namespace-labels/.chainsaw-test/resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#Deployment with Owner Label and additional labels
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
---
#Deployment with `kubernetes.io/metadata.name` label
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-2
namespace: within-ns
labels:
kubernetes.io/metadata.name: "my-deployment-2"
siddhikhapare marked this conversation as resolved.
Show resolved Hide resolved
spec:
replicas: 1
selector:
matchLabels:
app: my-app02
template:
metadata:
labels:
app: my-app02
spec:
containers:
- name: my-app02-deploy
image: busybox:1.35
---
#Deployment with only `owner` label
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-3
namespace: within-ns
labels:
owner: "any-corp"
siddhikhapare marked this conversation as resolved.
Show resolved Hide resolved
spec:
replicas: 1
selector:
matchLabels:
app: my-app03
template:
metadata:
labels:
app: my-app03
spec:
containers:
- name: my-app03-deploy
image: busybox:1.35
---
#Deployment with no labels
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