From 8ea3955bfedade5cd08e36fba87e3635bbe26af4 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 14:05:51 +0200 Subject: [PATCH 1/8] Add e2e test for new code --- .../chainsaw-test.yaml | 48 +++++++++++++++++++ .../netbox_v1_prefix_3-wrong-length.yaml | 16 +++++++ .../netbox_v1_prefixclaim_3.yaml | 15 ++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefix_3-wrong-length.yaml create mode 100644 tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefixclaim_3.yaml 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 103b9ac5..d6069774 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 @@ -10,6 +10,27 @@ spec: try: - apply: file: netbox_v1_prefixclaim_1.yaml + - name: Apply Prerequisite Prefix for testing mismatched length + try: + - apply: + file: netbox_v1_prefix_3-wrong-length.yaml + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefix-restore-3-prefix-with-wrong-length + spec: + comments: your comments + customFields: + netboxOperatorRestorationHash: 1309280893365bfd94710d148379a6f501a46afe + description: some description + prefix: 2.0.3.224/27 + site: MY_SITE + tenant: MY_TENANT + status: + (conditions[?type == 'Ready']): + - status: 'True' - name: Check CR 1 spec and status try: - assert: @@ -129,6 +150,33 @@ spec: tenant: MY_TENANT customFields: netboxOperatorRestorationHash: 00b8772de73cdac083b0732d5bb85ab4f0caa16c + - name: Apply CR 3 + try: + - apply: + file: netbox_v1_prefixclaim_3.yaml + - name: Check CR 3 spec and status + try: + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: PrefixClaim + metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: prefixclaim-ipv4-parentprefix-restore-3 + spec: + tenant: "MY_TENANT" + site: "MY_SITE" + description: "some description" + comments: "your comments" + preserveInNetbox: false + parentPrefix: "2.0.3.0/24" + prefixLength: "/28" + status: + (conditions[?type == 'Ready']): + - observedGeneration: 2 + status: 'False' - name: Set preserveInNetbox to false description: Set preserveInNetbox to false to clean up the NetBox test instance try: diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefix_3-wrong-length.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefix_3-wrong-length.yaml new file mode 100644 index 00000000..47f0c164 --- /dev/null +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefix_3-wrong-length.yaml @@ -0,0 +1,16 @@ +apiVersion: netbox.dev/v1 +kind: Prefix +metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: prefixclaim-ipv4-parentprefix-restore-3-prefix-with-wrong-length +spec: + comments: your comments + customFields: + netboxOperatorRestorationHash: 1309280893365bfd94710d148379a6f501a46afe + description: some description + preserveInNetbox: false + site: MY_SITE + tenant: MY_TENANT + prefix: "2.0.3.224/27" # this is the prefix that we expect to mismatch during restore diff --git a/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefixclaim_3.yaml b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefixclaim_3.yaml new file mode 100644 index 00000000..6324fa8b --- /dev/null +++ b/tests/e2e/Prefix/IPv4/prefixclaim-ipv4-parentprefix-restore/netbox_v1_prefixclaim_3.yaml @@ -0,0 +1,15 @@ +apiVersion: netbox.dev/v1 +kind: PrefixClaim +metadata: + labels: + app.kubernetes.io/name: netbox-operator + app.kubernetes.io/managed-by: kustomize + name: prefixclaim-ipv4-parentprefix-restore-3 +spec: + tenant: "MY_TENANT" + site: "MY_SITE" + description: "some description" + comments: "your comments" + preserveInNetbox: false + parentPrefix: "2.0.3.0/24" + prefixLength: "/28" From 63f0a42ad2887274819c16e4111c532dde54ce4e Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 15:07:06 +0200 Subject: [PATCH 2/8] Add e2e test for new code --- .../chainsaw-test.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 d6069774..4dd75a18 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 @@ -174,9 +174,12 @@ spec: parentPrefix: "2.0.3.0/24" prefixLength: "/28" status: - (conditions[?type == 'Ready']): - - observedGeneration: 2 + (conditions[?type == 'PrefixAssigned']): + - reason: PrefixCRNotCreated + message: 'Failed to assign prefix, prefix CR creation skipped: incorrect number of restoration results, number of results: 0' status: 'False' + (conditions[?type == 'Ready']): + - status: 'False' - name: Set preserveInNetbox to false description: Set preserveInNetbox to false to clean up the NetBox test instance try: From dfad6184a9ff9465d940669cac4538c96bbbb070 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 15:20:48 +0200 Subject: [PATCH 3/8] Implement filter for exact prefix length --- api/v1/prefixclaim_types.go | 8 +++++++ internal/controller/prefixclaim_controller.go | 4 ++-- pkg/netbox/api/prefix_claim.go | 23 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/api/v1/prefixclaim_types.go b/api/v1/prefixclaim_types.go index 24f14516..e671a780 100644 --- a/api/v1/prefixclaim_types.go +++ b/api/v1/prefixclaim_types.go @@ -17,6 +17,9 @@ limitations under the License. package v1 import ( + "strconv" + "strings" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -136,6 +139,11 @@ func (p *PrefixClaim) Conditions() *[]metav1.Condition { return &p.Status.Conditions } +func (r *PrefixClaim) GetPrefixLengthAsInt() int { + length, _ := strconv.Atoi(strings.ReplaceAll(r.Spec.PrefixLength, "/", "")) + return length +} + //+kubebuilder:object:root=true // PrefixClaimList contains a list of PrefixClaim diff --git a/internal/controller/prefixclaim_controller.go b/internal/controller/prefixclaim_controller.go index 1695a98f..b395f6c9 100644 --- a/internal/controller/prefixclaim_controller.go +++ b/internal/controller/prefixclaim_controller.go @@ -104,7 +104,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // since the parent prefix is not part of the restoration hash computation // we can quickly check to see if the prefix with the restoration hash is matched in NetBox h := generatePrefixRestorationHash(o) - canBeRestored, err := r.NetboxClient.RestoreExistingPrefixByHash(h) + canBeRestored, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.GetPrefixLengthAsInt()) if err != nil { if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionParentPrefixSelectedFalse, corev1.EventTypeWarning, fmt.Errorf("failed to look up prefix by hash: %w", err)); errReport != nil { return ctrl.Result{}, errReport @@ -239,7 +239,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // 5. try to reclaim Prefix using restorationHash h := generatePrefixRestorationHash(o) - prefixModel, err := r.NetboxClient.RestoreExistingPrefixByHash(h) + prefixModel, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.GetPrefixLengthAsInt()) if err != nil { if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixAssignedFalse, corev1.EventTypeWarning, err); errReport != nil { return ctrl.Result{}, errReport diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index 3eb7254a..b50fb331 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -36,7 +36,7 @@ var ( ErrNoPrefixMatchsSizeCriteria = errors.New("no available prefix matches size criteria") ) -func (r *NetboxClient) RestoreExistingPrefixByHash(hash string) (*models.Prefix, error) { +func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, mask_length int) (*models.Prefix, error) { customPrefixSearch := newQueryFilterOperation(nil, []CustomFieldEntry{ { key: config.GetOperatorConfig().NetboxRestorationHashFieldName, @@ -53,17 +53,28 @@ func (r *NetboxClient) RestoreExistingPrefixByHash(hash string) (*models.Prefix, return nil, nil } + // Filter for exact prefix length + prefixesWithExactPrefixLength := make([]*models.Prefix, 0) + for _, prefix := range list.Payload.Results { + our, _ := strconv.Atoi(strings.Split(*prefix.Prefix, "/")[1]) + if our == mask_length { + prefixesWithExactPrefixLength = append(prefixesWithExactPrefixLength, &models.Prefix{ + Prefix: *prefix.Prefix, + }) + } + } + // We should not have more than 1 result... - if len(list.Payload.Results) != 1 { - return nil, fmt.Errorf("incorrect number of restoration results, number of results: %v", len(list.Payload.Results)) + if len(prefixesWithExactPrefixLength) != 1 { + return nil, fmt.Errorf("incorrect number of restoration results, number of results: %v", len(prefixesWithExactPrefixLength)) } - res := list.Payload.Results[0] - if res.Prefix == nil { + res := prefixesWithExactPrefixLength[0] + if res.Prefix == "" { return nil, errors.New("prefix in netbox is nil") } return &models.Prefix{ - Prefix: *res.Prefix, + Prefix: res.Prefix, }, nil } From 77ba80375b6bc0a845a3a960b89ac75fafe3b567 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 15:29:27 +0200 Subject: [PATCH 4/8] Fix go lint --- api/v1/prefixclaim_types.go | 4 ++-- pkg/netbox/api/prefix_claim.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/v1/prefixclaim_types.go b/api/v1/prefixclaim_types.go index e671a780..91d26278 100644 --- a/api/v1/prefixclaim_types.go +++ b/api/v1/prefixclaim_types.go @@ -139,8 +139,8 @@ func (p *PrefixClaim) Conditions() *[]metav1.Condition { return &p.Status.Conditions } -func (r *PrefixClaim) GetPrefixLengthAsInt() int { - length, _ := strconv.Atoi(strings.ReplaceAll(r.Spec.PrefixLength, "/", "")) +func (p *PrefixClaim) GetPrefixLengthAsInt() int { + length, _ := strconv.Atoi(strings.ReplaceAll(p.Spec.PrefixLength, "/", "")) return length } diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index b50fb331..8bdbb272 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -36,7 +36,7 @@ var ( ErrNoPrefixMatchsSizeCriteria = errors.New("no available prefix matches size criteria") ) -func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, mask_length int) (*models.Prefix, error) { +func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, maskLength int) (*models.Prefix, error) { customPrefixSearch := newQueryFilterOperation(nil, []CustomFieldEntry{ { key: config.GetOperatorConfig().NetboxRestorationHashFieldName, @@ -57,7 +57,7 @@ func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, mask_length int) prefixesWithExactPrefixLength := make([]*models.Prefix, 0) for _, prefix := range list.Payload.Results { our, _ := strconv.Atoi(strings.Split(*prefix.Prefix, "/")[1]) - if our == mask_length { + if our == maskLength { prefixesWithExactPrefixLength = append(prefixesWithExactPrefixLength, &models.Prefix{ Prefix: *prefix.Prefix, }) From 68d64bedec9c08d90fbd4c66900100e2f666e13c Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 15:46:07 +0200 Subject: [PATCH 5/8] Move Apply Prerequisite further down to avoid race condition --- .../chainsaw-test.yaml | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 4dd75a18..2555e25c 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 @@ -10,27 +10,6 @@ spec: try: - apply: file: netbox_v1_prefixclaim_1.yaml - - name: Apply Prerequisite Prefix for testing mismatched length - try: - - apply: - file: netbox_v1_prefix_3-wrong-length.yaml - - assert: - resource: - apiVersion: netbox.dev/v1 - kind: Prefix - metadata: - name: prefixclaim-ipv4-parentprefix-restore-3-prefix-with-wrong-length - spec: - comments: your comments - customFields: - netboxOperatorRestorationHash: 1309280893365bfd94710d148379a6f501a46afe - description: some description - prefix: 2.0.3.224/27 - site: MY_SITE - tenant: MY_TENANT - status: - (conditions[?type == 'Ready']): - - status: 'True' - name: Check CR 1 spec and status try: - assert: @@ -150,11 +129,32 @@ spec: tenant: MY_TENANT customFields: netboxOperatorRestorationHash: 00b8772de73cdac083b0732d5bb85ab4f0caa16c + - name: Apply Prerequisite Prefix for CR 3 + try: + - apply: + file: netbox_v1_prefix_3-wrong-length.yaml + - assert: + resource: + apiVersion: netbox.dev/v1 + kind: Prefix + metadata: + name: prefixclaim-ipv4-parentprefix-restore-3-prefix-with-wrong-length + spec: + comments: your comments + customFields: + netboxOperatorRestorationHash: 1309280893365bfd94710d148379a6f501a46afe + description: some description + prefix: 2.0.3.224/27 + site: MY_SITE + tenant: MY_TENANT + status: + (conditions[?type == 'Ready']): + - status: 'True' - name: Apply CR 3 try: - apply: file: netbox_v1_prefixclaim_3.yaml - - name: Check CR 3 spec and status + - name: Check CR 3 spec and status, verify mismatched length doesn't assign wrong prefix try: - assert: resource: From ef3ff6e161df01698092afdf089631336f0e3a81 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 16:15:25 +0200 Subject: [PATCH 6/8] Fix names --- pkg/netbox/api/prefix_claim.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index 8bdbb272..2aabbd8d 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -36,7 +36,7 @@ var ( ErrNoPrefixMatchsSizeCriteria = errors.New("no available prefix matches size criteria") ) -func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, maskLength int) (*models.Prefix, error) { +func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, requestedMaskLength int) (*models.Prefix, error) { customPrefixSearch := newQueryFilterOperation(nil, []CustomFieldEntry{ { key: config.GetOperatorConfig().NetboxRestorationHashFieldName, @@ -56,8 +56,8 @@ func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, maskLength int) // Filter for exact prefix length prefixesWithExactPrefixLength := make([]*models.Prefix, 0) for _, prefix := range list.Payload.Results { - our, _ := strconv.Atoi(strings.Split(*prefix.Prefix, "/")[1]) - if our == maskLength { + prefixMaskLength, _ := strconv.Atoi(strings.Split(*prefix.Prefix, "/")[1]) + if prefixMaskLength == requestedMaskLength { prefixesWithExactPrefixLength = append(prefixesWithExactPrefixLength, &models.Prefix{ Prefix: *prefix.Prefix, }) From acd722ceeb78b540d8ebd12dba6aa79a5faa88ab Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 16:40:00 +0200 Subject: [PATCH 7/8] Switch from int comparison to string comparison --- api/v1/prefixclaim_types.go | 8 -------- internal/controller/prefixclaim_controller.go | 4 ++-- pkg/netbox/api/prefix_claim.go | 5 ++--- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/api/v1/prefixclaim_types.go b/api/v1/prefixclaim_types.go index 91d26278..24f14516 100644 --- a/api/v1/prefixclaim_types.go +++ b/api/v1/prefixclaim_types.go @@ -17,9 +17,6 @@ limitations under the License. package v1 import ( - "strconv" - "strings" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -139,11 +136,6 @@ func (p *PrefixClaim) Conditions() *[]metav1.Condition { return &p.Status.Conditions } -func (p *PrefixClaim) GetPrefixLengthAsInt() int { - length, _ := strconv.Atoi(strings.ReplaceAll(p.Spec.PrefixLength, "/", "")) - return length -} - //+kubebuilder:object:root=true // PrefixClaimList contains a list of PrefixClaim diff --git a/internal/controller/prefixclaim_controller.go b/internal/controller/prefixclaim_controller.go index b395f6c9..b4200407 100644 --- a/internal/controller/prefixclaim_controller.go +++ b/internal/controller/prefixclaim_controller.go @@ -104,7 +104,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // since the parent prefix is not part of the restoration hash computation // we can quickly check to see if the prefix with the restoration hash is matched in NetBox h := generatePrefixRestorationHash(o) - canBeRestored, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.GetPrefixLengthAsInt()) + canBeRestored, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.Spec.PrefixLength) if err != nil { if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionParentPrefixSelectedFalse, corev1.EventTypeWarning, fmt.Errorf("failed to look up prefix by hash: %w", err)); errReport != nil { return ctrl.Result{}, errReport @@ -239,7 +239,7 @@ func (r *PrefixClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) // 5. try to reclaim Prefix using restorationHash h := generatePrefixRestorationHash(o) - prefixModel, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.GetPrefixLengthAsInt()) + prefixModel, err := r.NetboxClient.RestoreExistingPrefixByHash(h, o.Spec.PrefixLength) if err != nil { if errReport := r.EventStatusRecorder.Report(ctx, o, netboxv1.ConditionPrefixAssignedFalse, corev1.EventTypeWarning, err); errReport != nil { return ctrl.Result{}, errReport diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index 2aabbd8d..ea21ccc0 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -36,7 +36,7 @@ var ( ErrNoPrefixMatchsSizeCriteria = errors.New("no available prefix matches size criteria") ) -func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, requestedMaskLength int) (*models.Prefix, error) { +func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, requestedPrefixLength string) (*models.Prefix, error) { customPrefixSearch := newQueryFilterOperation(nil, []CustomFieldEntry{ { key: config.GetOperatorConfig().NetboxRestorationHashFieldName, @@ -56,8 +56,7 @@ func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, requestedMaskLen // Filter for exact prefix length prefixesWithExactPrefixLength := make([]*models.Prefix, 0) for _, prefix := range list.Payload.Results { - prefixMaskLength, _ := strconv.Atoi(strings.Split(*prefix.Prefix, "/")[1]) - if prefixMaskLength == requestedMaskLength { + if strings.Contains(*prefix.Prefix, requestedPrefixLength) { prefixesWithExactPrefixLength = append(prefixesWithExactPrefixLength, &models.Prefix{ Prefix: *prefix.Prefix, }) From 8baf7171f65409d60b5f8762bc72c9973b0c77d8 Mon Sep 17 00:00:00 2001 From: Joel Studler Date: Wed, 16 Jul 2025 17:39:14 +0200 Subject: [PATCH 8/8] Update error message to be more specific --- pkg/netbox/api/prefix_claim.go | 8 +++++--- .../chainsaw-test.yaml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/netbox/api/prefix_claim.go b/pkg/netbox/api/prefix_claim.go index ea21ccc0..59178ce4 100644 --- a/pkg/netbox/api/prefix_claim.go +++ b/pkg/netbox/api/prefix_claim.go @@ -64,12 +64,14 @@ func (r *NetboxClient) RestoreExistingPrefixByHash(hash string, requestedPrefixL } // We should not have more than 1 result... - if len(prefixesWithExactPrefixLength) != 1 { - return nil, fmt.Errorf("incorrect number of restoration results, number of results: %v", len(prefixesWithExactPrefixLength)) + if len(prefixesWithExactPrefixLength) > 1 { + return nil, fmt.Errorf("too many restoration results found in NetBox for hash %s and prefix length %s, number of results: %v", hash, requestedPrefixLength, len(prefixesWithExactPrefixLength)) + } else if len(prefixesWithExactPrefixLength) == 0 { + return nil, fmt.Errorf("no prefix found in NetBox with restoration hash %s and prefix length %s", hash, requestedPrefixLength) } res := prefixesWithExactPrefixLength[0] if res.Prefix == "" { - return nil, errors.New("prefix in netbox is nil") + return nil, errors.New("prefix in netbox is empty") } return &models.Prefix{ 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 2555e25c..ece8693f 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 @@ -176,7 +176,7 @@ spec: status: (conditions[?type == 'PrefixAssigned']): - reason: PrefixCRNotCreated - message: 'Failed to assign prefix, prefix CR creation skipped: incorrect number of restoration results, number of results: 0' + message: 'Failed to assign prefix, prefix CR creation skipped: no prefix found in NetBox with restoration hash 1309280893365bfd94710d148379a6f501a46afe and prefix length /28' status: 'False' (conditions[?type == 'Ready']): - status: 'False'