Skip to content

Commit

Permalink
Added test for copy-ns-labels policy (#967)
Browse files Browse the repository at this point in the history
* Added test for copy-ns-labels policy

Signed-off-by: siddhikhapare <[email protected]>

* files fixed

Signed-off-by: siddhikhapare <[email protected]>

* error fixed

Signed-off-by: siddhikhapare <[email protected]>

* issue resolved

Signed-off-by: siddhikhapare <[email protected]>

* resource removed

Signed-off-by: siddhikhapare <[email protected]>

* chainsaw-test file fixed

Signed-off-by: siddhikhapare <[email protected]>

* container image name changed

Signed-off-by: siddhikhapare <[email protected]>

* files added

Signed-off-by: siddhikhapare <[email protected]>

* files deleted

Signed-off-by: siddhikhapare <[email protected]>

* test for label added

Signed-off-by: siddhikhapare <[email protected]>

* test file modified

Signed-off-by: siddhikhapare <[email protected]>

* Errors fixed

Signed-off-by: siddhikhapare <[email protected]>

* fixing lint error

Signed-off-by: siddhikhapare <[email protected]>

* fixing test error

Signed-off-by: siddhikhapare <[email protected]>

---------

Signed-off-by: siddhikhapare <[email protected]>
  • Loading branch information
siddhikhapare authored May 28, 2024
1 parent f8d0175 commit a664743
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
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

0 comments on commit a664743

Please sign in to comment.