Skip to content

Commit 8f4afd7

Browse files
committed
feat: add netbird network configuration script to automate the networks, resources, routings, and policies reconciliation
Signed-off-by: Sidharth Jawale <sidharth@obmondo.com>
1 parent 533fccc commit 8f4afd7

8 files changed

Lines changed: 1004 additions & 0 deletions

File tree

argocd-helm-charts/netbird/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,39 @@ Forwarding rules: 0
188188
Peers count: 1/2 Connected
189189
```
190190

191+
192+
## Network and Policy Automation
193+
194+
This tool synchronizes your network, resource, and policy configuration with the NetBird Management API.
195+
196+
### Build the binary
197+
To compile the configuration management tool:
198+
```bash
199+
cd argocd-helm-charts/netbird/config/
200+
go build -o netbird-config .
201+
```
202+
203+
### Setup and Execution
204+
205+
1. Copy the example configuration to your cluster's `kubeaid-config` directory:
206+
```bash
207+
cp argocd-helm-charts/netbird/config/config.yaml.example k8s/<cluster-name>/netbird-configs/config.yaml
208+
```
209+
2. Populate `k8s/<cluster-name>/netbird-configs/config.yaml` with your required networks, resources, and policies.
210+
211+
3. Run the tool by passing the path to your cluster-specific configuration file:
212+
```bash
213+
export NETBIRD_MGMT_URL="https://vpn.example.com"
214+
export NETBIRD_API_TOKEN="nbp_your_token_here"
215+
./netbird-config --config k8s/<cluster-name>/netbird/config.yaml
216+
```
217+
218+
### Idempotency
219+
- The script treats the provided configuration as the "Desired State."
220+
- It checks existing Networks, Resources, Routers, and Policies by name.
221+
- It will **Create** if missing, **Update** if the attributes (address, groups, etc.) differ, and do nothing if the state already matches the config.
222+
- Renaming a network/resource in the `config.yaml` will result in the creation of a *new* object, leaving the old one as is (it does not automatically delete).
223+
191224
### Troubleshooting
192225

193226
#### GET /api/users status 401
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
networks:
2+
- name: "examplenetwork-location"
3+
resources:
4+
- name: "exampleresource-location-uniqueidentifier"
5+
address: "172.17.0.0/24"
6+
groups: ["Access-Group-Name"]
7+
routing_peers:
8+
groups: ["Routing-Peer-Group-Name"]
9+
10+
policies:
11+
- source:
12+
groups: ["Source-Group-Name"]
13+
destination:
14+
groups: ["Destination-Group-Name"]
15+
protocol: "TCP"
16+
ports:
17+
- "80"
18+
- "443"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package core
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
// GenerateNetworkDescription generates the description based on hyphen separators.
9+
func GenerateNetworkDescription(name string) string {
10+
parts := strings.Split(name, "-")
11+
if len(parts) < 2 {
12+
return fmt.Sprintf("Network %s", name)
13+
}
14+
return fmt.Sprintf("Network %s located in %s", parts[0], parts[1])
15+
}
16+
17+
// GenerateResourceDescription generates the description based on hyphens and other metadata.
18+
func GenerateResourceDescription(name, groupsStr, address string) string {
19+
parts := strings.Split(name, "-")
20+
21+
// 1. Identify the location
22+
location := ""
23+
if len(parts) >= 2 {
24+
location = " located in " + parts[1]
25+
}
26+
27+
// 2. Determine base name
28+
baseName := parts[0]
29+
if len(parts) == 3 {
30+
baseName = parts[0] + "-" + parts[2]
31+
}
32+
33+
// 3. Format with the location variable
34+
return fmt.Sprintf("Resource %s%s part of %s pointing to %s", baseName, location, groupsStr, address)
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module github.com/obmondo/kubeaid/argocd-helm-charts/netbird/config
2+
3+
go 1.26.5
4+
5+
require (
6+
github.com/netbirdio/netbird v0.74.1
7+
github.com/spf13/pflag v1.0.10
8+
github.com/spf13/viper v1.21.0
9+
gopkg.in/yaml.v3 v3.0.1
10+
)
11+
12+
require (
13+
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
14+
github.com/fsnotify/fsnotify v1.9.0 // indirect
15+
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
16+
github.com/google/uuid v1.6.0 // indirect
17+
github.com/oapi-codegen/runtime v1.1.2 // indirect
18+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
19+
github.com/sagikazarmark/locafero v0.11.0 // indirect
20+
github.com/sirupsen/logrus v1.9.4 // indirect
21+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
22+
github.com/spf13/afero v1.15.0 // indirect
23+
github.com/spf13/cast v1.10.0 // indirect
24+
github.com/subosito/gotenv v1.6.0 // indirect
25+
go.yaml.in/yaml/v3 v3.0.4 // indirect
26+
golang.org/x/sys v0.44.0 // indirect
27+
golang.org/x/text v0.36.0 // indirect
28+
)
29+
30+
replace (
31+
github.com/dexidp/dex => github.com/netbirdio/dex v0.244.1-0.20260512110716-8d70ad8647c1
32+
github.com/dexidp/dex/api/v2 => github.com/netbirdio/dex/api/v2 v2.0.0-20260512110716-8d70ad8647c1
33+
)

argocd-helm-charts/netbird/config/go.sum

Lines changed: 438 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)