Skip to content

Commit b57d051

Browse files
committed
Restructure examples folder and add Instructions and diagrams for Example 3
1 parent 9993954 commit b57d051

19 files changed

+133
-406
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example 1: Simple
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example 3: Multi Cluster
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
![Figure 1: Starting Point](exhaustion-1-starting-point.drawio.svg)
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+
![Figure 2: Parent Prefix Exhausted](exhaustion-2-prefix-exhausted.drawio.svg)
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+
![Figure 3: Parent Prefix Exhaustion fixed](exhaustion-3-after-fix.drawio.svg)
70+
71+
### Example 3b: Restoration
72+
73+
![Figure 4: Restoration](restore.drawio.svg)
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.

docs/examples/example3-advanced-features/exhaustion-1-starting-point.drawio.svg

+4
Loading

docs/examples/example3-advanced-features/exhaustion-2-prefix-exhausted.drawio.svg

+4
Loading

docs/examples/example3-advanced-features/exhaustion-3-after-fix.drawio.svg

+4
Loading
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: advanced
6+
---
27
apiVersion: netbox.dev/v1
38
kind: PrefixClaim
49
metadata:
5-
labels:
6-
app.kubernetes.io/name: netbox-operator
7-
app.kubernetes.io/managed-by: kustomize
810
name: prefixclaim-exhaustion-sample-1
9-
namespace: restore
11+
namespace: advanced
1012
spec:
1113
tenant: "MY_TENANT"
1214
preserveInNetbox: true
1315
parentPrefixSelector:
14-
environment: dev
16+
environment: prod
17+
family: IPv4
1518
prefixLength: "/25"
1619
---
1720
apiVersion: netbox.dev/v1
1821
kind: PrefixClaim
1922
metadata:
20-
labels:
21-
app.kubernetes.io/name: netbox-operator
22-
app.kubernetes.io/managed-by: kustomize
2323
name: prefixclaim-exhaustion-sample-2
24-
namespace: restore
24+
namespace: advanced
2525
spec:
2626
tenant: "MY_TENANT"
2727
preserveInNetbox: true
2828
parentPrefixSelector:
29-
environment: dev
29+
environment: prod
30+
family: IPv4
3031
prefixLength: "/25"
3132
---
3233
apiVersion: netbox.dev/v1
3334
kind: PrefixClaim
3435
metadata:
35-
labels:
36-
app.kubernetes.io/name: netbox-operator
37-
app.kubernetes.io/managed-by: kustomize
3836
name: prefixclaim-exhaustion-sample-3
39-
namespace: restore
37+
namespace: advanced
4038
spec:
4139
tenant: "MY_TENANT"
4240
preserveInNetbox: true
4341
parentPrefixSelector:
44-
environment: dev
42+
environment: prod
43+
family: IPv4
4544
prefixLength: "/25"

docs/examples/example3-advanced-features/restore.drawio.svg

+4
Loading

0 commit comments

Comments
 (0)