From bd70229ac33a8f74ee9ee7a079fe5eff669a0f01 Mon Sep 17 00:00:00 2001 From: bruelea <166021996+bruelea@users.noreply.github.com> Date: Fri, 6 Jun 2025 09:27:17 +0200 Subject: [PATCH 1/3] add clean up to first test --- .../chainsaw-test.yaml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml index 91a1631e..7ad64e9d 100644 --- a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml @@ -155,6 +155,27 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: IpAddressClaim + metadata: + name: ipaddressclaim-ipv4-restore-1 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: IpAddressClaim + metadata: + name: ipaddressclaim-ipv4-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: From 507c0ad04318bc0e3ad5133e43249bbad1414af6 Mon Sep 17 00:00:00 2001 From: bruelea <166021996+bruelea@users.noreply.github.com> Date: Fri, 6 Jun 2025 10:40:47 +0200 Subject: [PATCH 2/3] add clean up to all tests --- .../chainsaw-test.yaml | 39 +++++++++++++++++++ .../chainsaw-test.yaml | 21 ++++++++++ .../chainsaw-test.yaml | 21 ++++++++++ .../chainsaw-test.yaml | 21 ++++++++++ .../chainsaw-test.yaml | 2 +- .../chainsaw-test.yaml | 21 ++++++++++ .../chainsaw-test.yaml | 21 ++++++++++ .../chainsaw-test.yaml | 21 ++++++++++ 8 files changed, 166 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml index ff77b4d7..34ee5f9d 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml @@ -130,6 +130,45 @@ spec: tenant: MY_TENANT customFields: netboxOperatorRestorationHash: 00b8772de73cdac083b0732d5bb85ab4f0caa16c + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefix-restore-1 + spec: + preserveInNetbox: false + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefix-restore-2 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefix-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefix-restore-2 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml index ed66186a..6c160360 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml @@ -143,6 +143,27 @@ spec: tenant: MY_TENANT_2 customFields: netboxOperatorRestorationHash: 8a5e15cd391ec02a7a2b2e316bc163f4fe46ef0b + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefixselector-restore-1 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefixselector-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml index cec6420b..73100ce9 100644 --- a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml @@ -50,6 +50,27 @@ spec: tenant: MY_TENANT_2 customFields: netboxOperatorRestorationHash: 46116345cc81820fdb412dc83e7147d4b1dc1afa + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv4-parentprefixselector-apply + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefixselector-apply + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: diff --git a/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml b/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml index 51b91fe1..5e4a441a 100644 --- a/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml +++ b/tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml @@ -86,6 +86,27 @@ spec: prefix: 2::/124 preserveInNetbox: true tenant: MY_TENANT_2 + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + name: prefixclaim-ipv6-apply-update + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv6-apply-update + status: + (conditions[?type == 'Ready']): + - observedGeneration: 3 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: diff --git a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml index 7ad64e9d..f6884b73 100644 --- a/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml @@ -169,7 +169,7 @@ spec: - assert: resource: apiVersion: netbox.dev/v1 - kind: IpAddressClaim + kind: IpAddress metadata: name: ipaddressclaim-ipv4-restore-1 status: diff --git a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml index 6aae130b..314b6800 100644 --- a/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml +++ b/tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml @@ -155,6 +155,27 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: IpAddressClaim + metadata: + name: ipaddressclaim-ipv6-restore-1 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: IpAddress + metadata: + name: ipaddressclaim-ipv6-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource cleanup: diff --git a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml index 22338434..981d700f 100644 --- a/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv4/iprangeclaim-ipv4-restore/chainsaw-test.yaml @@ -172,6 +172,27 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: IpRangeClaim + metadata: + name: iprangeclaim-ipv4-restore-1 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: IpRange + metadata: + name: iprangeclaim-ipv4-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events and leases description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: diff --git a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml index 957148bb..abe22d39 100644 --- a/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml +++ b/tests/e2e/iprange/ipv6/iprangeclaim-ipv6-restore/chainsaw-test.yaml @@ -172,6 +172,27 @@ spec: status: (conditions[?type == 'Ready']): - status: 'True' + - name: Set preserveInNetbox to false + description: Set preserveInNetbox to false to clean up the NetBox test instance + try: + - patch: + resource: + apiVersion: netbox.dev/v1 + kind: IpRangeClaim + metadata: + name: iprangeclaim-ipv6-restore-1 + spec: + preserveInNetbox: false + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: IpRange + metadata: + name: iprangeclaim-ipv6-restore-1 + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'True' - name: Cleanup events and leases description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource and lease cleanup for preventing delays when using the same prefixes (e.g. with "invalid" tests) cleanup: From a064db196fb8308ba6ba7ad44832a5fc9b45cf62 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Thu, 19 Jun 2025 10:47:37 +0200 Subject: [PATCH 3/3] Add a few notes on how to work with tests --- tests/e2e/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 8cd54ca4..1459beb5 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -3,7 +3,9 @@ # How to run the test locally? - [Install](https://kyverno.github.io/chainsaw/latest/quick-start/install/) `chainsaw`: `go install github.com/kyverno/chainsaw@latest` -- Execute `make test-e2e` +- Execute `make test-e2e` or `chainsaw test --namespace e2e` with specific flags (see Makefile) +- Use `--test-dir` flag if you want to execute a specific test. +- Use `--skip-delete` flag in case you want to skip the deletion of the Kubernetes resources (e.g. for debugging). Note that this results in leftovers and you might need to clean up things. # How to add a new test locally?