|
| 1 | +# Example 3: Advanced Features |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This demo showcases the two following cases: |
| 6 | + |
| 7 | +- Example 3a: Automatic Reconcilation in case of Prefix Exhaustion. When a Prefix is exhausted and this is fixed in the NetBox backend, NetBox Operator will automatically reconcile this. |
| 8 | +- Example 3b: Restoration of Prefixes |
| 9 | + |
| 10 | +## Instructions |
| 11 | + |
| 12 | +### Example 3a: Prefix Exhaustion and Reconciliation |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +Create a /24 Prefix (e.g. 1.122.0.0/24) with Custom Field Environment set to "prod" in NetBox UI. |
| 17 | + |
| 18 | +Apply Resource and show PrefixClaims: |
| 19 | + |
| 20 | +```bash |
| 21 | +kubectl --context kind-london apply -f netbox_v1_prefixclaim.yaml |
| 22 | +kubectl --context kind-london -n advanced get prefixclaims,prefixes |
| 23 | +``` |
| 24 | + |
| 25 | +Note that only 2 out of the 3 PrefixClaims will become Ready. This is because the /24 Prefix is exhausted already after two Prefixes. This will look similar to this (note the order is non-deterministic): |
| 26 | + |
| 27 | +```bash |
| 28 | +NAME PREFIX PREFIXASSIGNED READY AGE |
| 29 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True True 2m2s |
| 30 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True True 2m2s |
| 31 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-3 False 2m2s |
| 32 | + |
| 33 | +NAME PREFIX READY ID URL AGE |
| 34 | +prefix.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True 148 http://172.18.1.2/ipam/prefixes/148 2m2s |
| 35 | +prefix.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True 149 http://172.18.1.2/ipam/prefixes/149 2m2s |
| 36 | +``` |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +Create another /24 Prefix (e.g. 1.100.0.0/24) with Custom Field Environment set to "prod" in NetBox UI. |
| 42 | + |
| 43 | +Wait for the PrefixClaim to be reconciled again or trigger reconciliation by e.g. adding an annotation: |
| 44 | + |
| 45 | +```bash |
| 46 | +kubectl --context kind-london -n advanced annotate prefixclaim prefixclaim-exhaustion-sample-3 reconcile="$(date)" --overwrite |
| 47 | +``` |
| 48 | + |
| 49 | +Confirm that the third Prefix is now also assigned: |
| 50 | + |
| 51 | +```bash |
| 52 | +kubectl --context kind-london -n advanced get prefixclaims,prefixes |
| 53 | +``` |
| 54 | + |
| 55 | +Which should look as follows: |
| 56 | + |
| 57 | +```bash |
| 58 | +NAME PREFIX PREFIXASSIGNED READY AGE |
| 59 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True True 4s |
| 60 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True True 4s |
| 61 | +prefixclaim.netbox.dev/prefixclaim-exhaustion-sample-3 1.100.0.0/25 True True 4s |
| 62 | + |
| 63 | +NAME PREFIX READY ID URL AGE |
| 64 | +prefix.netbox.dev/prefixclaim-exhaustion-sample-1 1.122.0.0/25 True 148 http://172.18.1.2/ipam/prefixes/148 4s |
| 65 | +prefix.netbox.dev/prefixclaim-exhaustion-sample-2 1.122.0.128/25 True 149 http://172.18.1.2/ipam/prefixes/149 4s |
| 66 | +prefix.netbox.dev/prefixclaim-exhaustion-sample-3 1.100.0.0/25 True 151 http://172.18.1.2/ipam/prefixes/151 3s``` |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +### Example 3b: Restoration |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +Since we set `.spec.preserveInNetbox` to `true`, we can delete and restore the resources. To delete all reasources, delete the entire namespace: |
| 76 | + |
| 77 | +```bash |
| 78 | +kubectl --context kind-london delete ns advanced |
| 79 | +``` |
| 80 | + |
| 81 | +Make sure the resources are gone in Kubernetes: |
| 82 | + |
| 83 | +```bash |
| 84 | +kubectl --context kind-london -n advanced get prefixclaims |
| 85 | +``` |
| 86 | + |
| 87 | +Verify in the NetBox UI that the Prefixes still exist. |
| 88 | + |
| 89 | +Now apply the manifests again and verify they become ready. |
| 90 | + |
| 91 | +```bash |
| 92 | +kubectl --context kind-london apply -f netbox_v1_prefixclaim.yaml |
| 93 | +kubectl --context kind-london -n advanced wait --for=condition=Ready prefixclaims --all |
| 94 | +kubectl --context kind-london -n advanced get prefixclaims |
| 95 | +``` |
| 96 | + |
| 97 | +Note that the assigned Prefixes are the same as before. You can also play around with this by just restoring single prefixes. If you're curious about how this is done, make sure to read [the "Restoration from NetBox" section in the main README.md](https://github.com/netbox-community/netbox-operator/tree/main?tab=readme-ov-file#restoration-from-netbox) and to check out the code. Also have a look at the "Netbox Restoration Hash" custom field in NetBox. |
0 commit comments