Skip to content

Commit 996e5ba

Browse files
committed
add cleanup step to all e2e test cases
1 parent 4f883d8 commit 996e5ba

File tree

19 files changed

+143
-16
lines changed

19 files changed

+143
-16
lines changed

internal/controller/prefixclaim_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request)
156156
// fetch available prefixes from netbox
157157
parentPrefixCandidates, err := r.NetboxClient.GetAvailablePrefixesByParentPrefixSelector(&prefixClaim.Spec)
158158
if err != nil || len(parentPrefixCandidates) == 0 {
159-
r.EventStatusRecorder.Recorder().Event(prefixClaim, corev1.EventTypeWarning, netboxv1.ConditionPrefixAssignedFalse.Reason, err.Error())
159+
r.EventStatusRecorder.Recorder().Event(prefixClaim, corev1.EventTypeWarning, netboxv1.ConditionPrefixAssignedFalse.Reason, netboxv1.ConditionPrefixAssignedFalse.Message+": "+err.Error())
160160
if err := r.EventStatusRecorder.Report(ctx, prefixClaim, netboxv1.ConditionPrefixAssignedFalse, corev1.EventTypeWarning, err); err != nil {
161161
return ctrl.Result{}, err
162162
}

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-invalid-parentprefixselector/chainsaw-test.yaml

+12-4
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,27 @@ spec:
3434
environment: "nilenv"
3535
poolName: "nilpool"
3636
status:
37-
(conditions[?type == 'ParentPrefixSelected']):
37+
(conditions[?type == 'PrefixAssigned']):
3838
- status: 'False'
3939
- assert:
4040
resource:
4141
apiVersion: v1
42-
count: 1
4342
kind: Event
4443
type: Warning
45-
reason: ParentPrefixNotSelected
44+
reason: PrefixCRNotCreated
4645
source:
4746
component: prefix-claim-controller
48-
message: "The parent prefix was not able to be selected: no parent prefix can be obtained with the query conditions set in ParentPrefixSelector, err = failed to fetch tenant 'niltenant': not found, number of candidates = 0"
47+
message: "Failed to assign prefix, prefix CR creation skipped: failed to fetch tenant 'niltenant': not found"
4948
involvedObject:
5049
apiVersion: netbox.dev/v1
5150
kind: PrefixClaim
5251
name: prefixclaim-ipv4-invalid-parentprefixselector
52+
- name: Cleanup events
53+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
54+
cleanup:
55+
- script:
56+
env:
57+
- name: NAMESPACE
58+
value: ($namespace)
59+
content: |
60+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-invalid-parentprefixselector -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-apply-update/chainsaw-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ spec:
7979
prefix: 2.0.2.0/28
8080
site: MY_SITE
8181
tenant: MY_TENANT
82+
- name: Cleanup events
83+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
84+
cleanup:
85+
- script:
86+
env:
87+
- name: NAMESPACE
88+
value: ($namespace)
89+
content: |
90+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-apply-update -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/chainsaw-test.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,13 @@ spec:
130130
tenant: MY_TENANT
131131
customFields:
132132
netboxOperatorRestorationHash: 00b8772de73cdac083b0732d5bb85ab4f0caa16c
133+
- name: Cleanup events
134+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
135+
cleanup:
136+
- script:
137+
env:
138+
- name: NAMESPACE
139+
value: ($namespace)
140+
content: |
141+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-restore-1 -n $NAMESPACE
142+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefix-restore-2 -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield/chainsaw-test.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ spec:
4848
- assert:
4949
resource:
5050
apiVersion: v1
51-
count: 1
5251
kind: Event
5352
type: Warning
5453
reason: PrefixCRNotCreated
@@ -59,3 +58,12 @@ spec:
5958
apiVersion: netbox.dev/v1
6059
kind: PrefixClaim
6160
name: prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield
61+
- name: Cleanup events
62+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
63+
cleanup:
64+
- script:
65+
env:
66+
- name: NAMESPACE
67+
value: ($namespace)
68+
content: |
69+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-nonexisingcustomfield -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector-restore/chainsaw-test.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ spec:
102102
- name: Apply CR 1 for the second time again
103103
try:
104104
- apply:
105-
file: netbox_v1_prefixclaim_1.yaml
105+
file: netbox_v1_prefixclaim_1.yaml
106106
- name: Check CR 1 spec and status and make sure it is restored
107107
try:
108108
- assert:
@@ -143,3 +143,13 @@ spec:
143143
tenant: MY_TENANT_2
144144
customFields:
145145
netboxOperatorRestorationHash: 8a5e15cd391ec02a7a2b2e316bc163f4fe46ef0b
146+
- name: Cleanup events
147+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
148+
cleanup:
149+
- script:
150+
env:
151+
- name: NAMESPACE
152+
value: ($namespace)
153+
content: |
154+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-restore-1 -n $NAMESPACE
155+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-restore-2 -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefixselector/chainsaw-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ spec:
5050
tenant: MY_TENANT_2
5151
customFields:
5252
netboxOperatorRestorationHash: 46116345cc81820fdb412dc83e7147d4b1dc1afa
53+
- name: Cleanup events
54+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
55+
cleanup:
56+
- script:
57+
env:
58+
- name: NAMESPACE
59+
value: ($namespace)
60+
content: |
61+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-parentprefixselector-apply -n $NAMESPACE

tests/e2e/Prefix/IPv4/prefixclaim-ipv4-prefixexhausted/chainsaw-test.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ spec:
8888
- assert:
8989
resource:
9090
apiVersion: v1
91-
count: 1
9291
kind: Event
9392
type: Warning
9493
reason: PrefixCRNotCreated
@@ -99,3 +98,14 @@ spec:
9998
apiVersion: netbox.dev/v1
10099
kind: PrefixClaim
101100
name: prefixclaim-ipv4-prefixexhausted-3
101+
- name: Cleanup events
102+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
103+
cleanup:
104+
- script:
105+
env:
106+
- name: NAMESPACE
107+
value: ($namespace)
108+
content: |
109+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-1 -n $NAMESPACE
110+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-2 -n $NAMESPACE
111+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv4-prefixexhausted-3 -n $NAMESPACE

tests/e2e/Prefix/IPv6/prefixclaim-ipv6-apply-update/chainsaw-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ spec:
8686
prefix: 2::/124
8787
preserveInNetbox: true
8888
tenant: MY_TENANT_2
89+
- name: Cleanup events
90+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
91+
cleanup:
92+
- script:
93+
env:
94+
- name: NAMESPACE
95+
value: ($namespace)
96+
content: |
97+
kubectl delete events --field-selector involvedObject.name=prefixclaim-ipv6-apply-update -n $NAMESPACE

tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-apply-update/chainsaw-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,12 @@ spec:
107107
status:
108108
(conditions[?type == 'Ready']):
109109
- status: 'True'
110+
- name: Cleanup events
111+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
112+
cleanup:
113+
- script:
114+
env:
115+
- name: NAMESPACE
116+
value: ($namespace)
117+
content: |
118+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-apply-update -n $NAMESPACE

tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-prefixexhausted/chainsaw-test.yaml

+12-2
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ spec:
123123
- assert:
124124
resource:
125125
apiVersion: v1
126-
count: 1
127126
kind: Event
128127
type: Warning
129128
reason: IPAddressCRNotCreated
130129
source:
131130
component: ip-address-claim-controller
132-
message: "Failed to assign prefix, prefix CR creation skipped: parent prefix exhausted"
131+
message: "Failed to fetch new IP from NetBox: parent prefix exhausted"
133132
involvedObject:
134133
apiVersion: netbox.dev/v1
135134
kind: IpAddressClaim
136135
name: ipaddressclaim-ipv4-prefixexhausted-3
136+
- name: Cleanup events
137+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
138+
cleanup:
139+
- script:
140+
env:
141+
- name: NAMESPACE
142+
value: ($namespace)
143+
content: |
144+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-1 -n $NAMESPACE
145+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-2 -n $NAMESPACE
146+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-prefixexhausted-3 -n $NAMESPACE

tests/e2e/ipaddress/ipv4/ipaddressclaim-ipv4-restore/chainsaw-test.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,13 @@ spec:
155155
status:
156156
(conditions[?type == 'Ready']):
157157
- status: 'True'
158+
- name: Cleanup events
159+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
160+
cleanup:
161+
- script:
162+
env:
163+
- name: NAMESPACE
164+
value: ($namespace)
165+
content: |
166+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-restore-1 -n $NAMESPACE
167+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv4-restore-2 -n $NAMESPACE

tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-apply-update/chainsaw-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,12 @@ spec:
107107
status:
108108
(conditions[?type == 'Ready']):
109109
- status: 'True'
110+
- name: Cleanup events
111+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
112+
cleanup:
113+
- script:
114+
env:
115+
- name: NAMESPACE
116+
value: ($namespace)
117+
content: |
118+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-apply-update -n $NAMESPACE

tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-prefixexhausted/chainsaw-test.yaml

+12-2
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,24 @@ spec:
123123
- assert:
124124
resource:
125125
apiVersion: v1
126-
count: 1
127126
kind: Event
128127
type: Warning
129128
reason: IPAddressCRNotCreated
130129
source:
131130
component: ip-address-claim-controller
132-
message: "Failed to assign prefix, prefix CR creation skipped: parent prefix exhausted"
131+
message: "Failed to fetch new IP from NetBox: parent prefix exhausted"
133132
involvedObject:
134133
apiVersion: netbox.dev/v1
135134
kind: IpAddressClaim
136135
name: ipaddressclaim-ipv6-prefixexhausted-3
136+
- name: Cleanup events
137+
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)
138+
cleanup:
139+
- script:
140+
env:
141+
- name: NAMESPACE
142+
value: ($namespace)
143+
content: |
144+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-1 -n $NAMESPACE
145+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-2 -n $NAMESPACE
146+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-prefixexhausted-3 -n $NAMESPACE

tests/e2e/ipaddress/ipv6/ipaddressclaim-ipv6-restore/chainsaw-test.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,13 @@ spec:
155155
status:
156156
(conditions[?type == 'Ready']):
157157
- status: 'True'
158+
- name: Cleanup events
159+
description: Events cleanup required to fix issues with failing tests that assert the wrong Error resource
160+
cleanup:
161+
- script:
162+
env:
163+
- name: NAMESPACE
164+
value: ($namespace)
165+
content: |
166+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-restore-1 -n $NAMESPACE
167+
kubectl delete events --field-selector involvedObject.name=ipaddressclaim-ipv6-restore-2 -n $NAMESPACE

tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-parentprefix/chainsaw-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ spec:
2424
- assert:
2525
resource:
2626
apiVersion: v1
27-
count: 1
2827
kind: Event
2928
type: Warning
3029
reason: IPRangeCRNotCreated

tests/e2e/iprange/ipv4/iprangeclaim-ipv4-invalid-tenant/chainsaw-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ spec:
3030
- assert:
3131
resource:
3232
apiVersion: v1
33-
count: 1
3433
kind: Event
3534
type: Warning
3635
reason: IPRangeCRNotCreated

tests/e2e/iprange/ipv4/iprangeclaim-ipv4-prefixexhausted/chainsaw-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ spec:
132132
- assert:
133133
resource:
134134
apiVersion: v1
135-
count: 1
136135
kind: Event
137136
type: Warning
138137
reason: IPRangeCRNotCreated

tests/e2e/iprange/ipv6/iprangeclaim-ipv6-prefixexhausted/chainsaw-test.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ spec:
133133
- assert:
134134
resource:
135135
apiVersion: v1
136-
count: 1
137136
kind: Event
138137
type: Warning
139138
reason: IPRangeCRNotCreated

0 commit comments

Comments
 (0)