netbox-community / netbox-operator

[INCUBATING] A Kubernetes operator to manage NetBox resources directly through Kubernetes.
Apache License 2.0
46 stars 3 forks source link

Under some circumstances the parent prefix will be computed but it's already exhausted #131

Closed henrybear327 closed 1 week ago

henrybear327 commented 2 weeks ago

Bug report criteria

What happened?

Under some circumstances, the parent prefix will be computed but already exhausted. Even if you add more prefixes, the system will not recover and compute/choose a new parent prefix.

See https://github.com/netbox-community/netbox-operator/pull/90#issuecomment-2475877803

What did you expect to happen?

If the selected parent prefix is already exhausted, the system should recover and compute/choose a new parent prefix.

How can we reproduce it (as minimally and precisely as possible)?

It's a bit of a race condition.

You need to apply a PrefixClaim, and on NetBox you reserve all Prefixes available within the potential candidates, and hopefully this can be done before PrefixClaim starts claiming the first available prefix.

Netbox operator version

Latest on main (the issue was discovered on https://github.com/netbox-community/netbox-operator/pull/90 before merging)

Netbox operator configuration (command line flags or environment variables)

No response

Relevant log output

Name:         prefixclaim-customfields-sample-09
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  netbox.dev/v1
Kind:         PrefixClaim
Metadata:
  Creation Timestamp:  2024-11-12T14:26:55Z
  Generation:          1
  Resource Version:    4212
  UID:                 a3b68d89-6c66-4d63-8b39-c95dd9c326b5
Spec:
  Parent Prefix Selector:
    Environment:       PostProduction
    Pool Name:         Pool 254
  Prefix Length:       /30
  Preserve In Netbox:  false
  Tenant:              Dunder-Mifflin, Inc.
Status:
  Conditions:
    Last Transition Time:  2024-11-12T14:27:11Z
    Message:               The parent prefix was computed successfully. parentPrefix is computed: 1.254.0.0/27
    Reason:                ParentPrefixComputed
    Status:                True
    Type:                  ParentPrefixComputed
    Last Transition Time:  2024-11-12T14:28:13Z
    Message:               Failed to fetch new Prefix from NetBox. parent prefix exhausted
    Reason:                PrefixCRNotCreated
    Status:                False
    Type:                  PrefixAssigned
  Parent Prefix:           1.254.0.0/27
Events:
  Type     Reason                    Age    From                     Message
  ----     ------                    ----   ----                     -------
  Normal   ParentPrefixComputed      4m41s  prefix-claim-controller  The parent prefix was computed successfully. parentPrefix is computed: 1.254.0.0/27
  Warning  PrefixCRNotCreated        3m39s  prefix-claim-controller  Failed to fetch new Prefix from NetBox. parent prefix exhausted
  Warning  FailedToLockParentPrefix  2m     prefix-claim-controller  failed to lock parent prefix 1.254.0.0/27

Anything else we need to know?

Maybe we could fix this by removing .status.parentPrefix if we come to the condition that has the message "parent prefix exhausted"

henrybear327 commented 1 week ago

Fixed in https://github.com/netbox-community/netbox-operator/pull/90