Skip to content

Commit fdfba5f

Browse files
committed
release: v0.1.2
Add the option to choose the name of interface vlan will be created from, based on node name.
1 parent 1e81cd0 commit fdfba5f

File tree

11 files changed

+86
-21
lines changed

11 files changed

+86
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION ?= 0.1.1
1+
VERSION ?= 0.1.2
22
DOCKERHUB_USER ?= plan9better
33
LOCAL_REGISTRY ?= 192.168.10.201:5000
44

api/v1/vlanman.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ type VlanNetworkSpec struct {
2828
VlanID int `json:"vlanId"`
2929
ExcludedNodes []string `json:"excludedNodes,omitempty"`
3030
Pools []VlanNetworkPool `json:"pools"`
31+
Mappings []IPMapping `json:"mappings"`
32+
}
33+
34+
type IPMapping struct {
35+
NodeName string `json:"nodeName"`
36+
Interface string `json:"interfaceName"`
3137
}
3238

3339
type VlanNetworkPool struct {

cmd/interface/main.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
ip "github.com/vishvananda/netlink"
1111
)
1212

13-
func findDefaultInterface() (*ip.Link, error) {
13+
func findDefaultInterface() (ip.Link, error) {
1414
_, dflt, err := net.ParseCIDR("0.0.0.0/0")
1515
if err != nil {
1616
return nil, fmt.Errorf("Error parsing CIDR: %s", err.Error())
@@ -29,7 +29,7 @@ func findDefaultInterface() (*ip.Link, error) {
2929
}
3030
for _, r := range routes {
3131
if r.Dst.String() == dflt.String() {
32-
return &l, nil
32+
return l, nil
3333
}
3434
}
3535
}
@@ -53,16 +53,30 @@ func main() {
5353
log.Error("Couldn't parse PID to int", "PID", envPID, "error", err)
5454
os.Exit(1)
5555
}
56+
var dflt ip.Link
5657

57-
dflt, err := findDefaultInterface()
58-
if err != nil {
59-
log.Error("Couldn't find default interface", "error", err)
60-
os.Exit(1)
58+
name := os.Getenv("INTERFACE")
59+
if name == "" {
60+
log.Info("Interface env var not set, finding by route")
61+
dflt, err = findDefaultInterface()
62+
if err != nil {
63+
log.Error("Couldn't find default interface and env var is empty", "msg", err)
64+
os.Exit(1)
65+
}
66+
} else {
67+
log.Info("Interface env var set, finding by name")
68+
dflt, err = ip.LinkByName(name)
69+
if err != nil {
70+
log.Error("Couldn't find interface from env var by name", "name", name, "msg", err)
71+
os.Exit(1)
72+
}
6173
}
74+
log.Info("Found interface", "name", dflt.Attrs().Name)
6275

6376
attrs := ip.NewLinkAttrs()
6477
attrs.Name = "vlan" + envID
65-
attrs.ParentIndex = (*dflt).Attrs().Index
78+
log.Info("Setting parent index", "to", dflt.Attrs().Index, "from", dflt.Attrs().Name)
79+
attrs.ParentIndex = dflt.Attrs().Index
6680
vlan := ip.Vlan{
6781
LinkAttrs: attrs,
6882
VlanId: int(ID),

helm/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ appVersion: 1.16.0
33
description: VLAN network manager
44
name: vlanman
55
type: application
6-
version: 0.1.1
6+
version: 0.1.2
77
annotations:
88
artifacthub.io/category: "networking"
99
artifacthub.io/crds: |

helm/templates/vlanman-crd.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ spec:
2121
spec:
2222
type: object
2323
properties:
24+
mappings:
25+
type: array
26+
items:
27+
type: object
28+
properties:
29+
nodeName:
30+
type: string
31+
interfaceName:
32+
type: string
2433
pools:
2534
type: array
2635
items:
@@ -56,6 +65,7 @@ spec:
5665
- remoteSubnet
5766
- localSubnet
5867
- vlanId
68+
- pools
5969
status:
6070
type: object
6171
properties:

helm/values.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ global:
1111
controller:
1212
podTimeoutSeconds: 60
1313
replicaCount: 1
14-
image: "plan9better/vlanman:0.1.1"
14+
image: "plan9better/vlanman:0.1.2"
1515
pullPolicy: IfNotPresent
1616
podSecurityContext:
1717
runAsNonRoot: true
@@ -27,13 +27,13 @@ controller:
2727
tolerations: []
2828
affinity: {}
2929
manager:
30-
image: "plan9better/vlan-manager:0.1.1"
30+
image: "plan9better/vlan-manager:0.1.2"
3131
pullPolicy: "IfNotPresent"
3232
worker:
33-
image: "plan9better/vlan-worker:0.1.1"
33+
image: "plan9better/vlan-worker:0.1.2"
3434
pullPolicy: "IfNotPresent"
3535
interface:
36-
image: "plan9better/vlan-interface:0.1.1"
36+
image: "plan9better/vlan-interface:0.1.2"
3737
pullPolicy: "IfNotPresent"
3838
jobTTLSeconds: 300 # negative values mean never
3939
# Webhook configuration

helm/vlanman-0.1.2.tgz

19.6 KB
Binary file not shown.

index.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,28 @@ entries:
1414
- https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack
1515
apiVersion: v2
1616
appVersion: 1.16.0
17-
created: "2025-07-28T15:24:59.993177+02:00"
17+
created: "2025-07-29T12:39:58.079528+02:00"
18+
description: VLAN network manager
19+
digest: 6b2d634c0f489d991dac538bfc2bd56b3c99fe1778556c810fcb0cf4b6336de0
20+
name: vlanman
21+
type: application
22+
urls:
23+
- https://github.com/dialohq/vlanman/releases/download/v0.1.2/vlanman-0.1.2.tgz
24+
version: 0.1.2
25+
- annotations:
26+
artifacthub.io/category: networking
27+
artifacthub.io/crds: |
28+
- kind: VlanNetwork
29+
version: v1
30+
name: vlannetwork
31+
description: Defines the VLAN connection
32+
artifacthub.io/license: MIT
33+
artifacthub.io/recommendations: |
34+
- https://artifacthub.io/packages/helm/cert-manager/cert-manager
35+
- https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack
36+
apiVersion: v2
37+
appVersion: 1.16.0
38+
created: "2025-07-29T12:39:58.078733+02:00"
1839
description: VLAN network manager
1940
digest: ab1060ee1c74386328a1913148b305e245a4dcbeea28cc8fb1cf4945f00c330d
2041
name: vlanman
@@ -35,12 +56,12 @@ entries:
3556
- https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack
3657
apiVersion: v2
3758
appVersion: 1.16.0
38-
created: "2025-07-28T15:24:59.992727+02:00"
59+
created: "2025-07-29T12:39:58.078283+02:00"
3960
description: VLAN network manager
4061
digest: 0bf004ba2202856151915191f652966b1850352072d0af9a83fddf53e96aaa57
4162
name: vlanman
4263
type: application
4364
urls:
4465
- https://github.com/dialohq/vlanman/releases/download/v0.1.0/vlanman-0.1.0.tgz
4566
version: 0.1.0
46-
generated: "2025-07-28T15:24:59.991244+02:00"
67+
generated: "2025-07-29T12:39:58.077272+02:00"

internal/controller/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (a *CreateManagerAction) Do(ctx context.Context, r *VlanmanReconciler) erro
242242
}
243243
}
244244

245-
job := interfaceFromDaemon(pod, PID.PID, int(a.Manager.VlanID), r.Env.TTL, r.Env.InterfacePodImage, a.Manager.OwnerNetworkName, r.Env.InterfacePodPullPolicy)
245+
job := interfaceFromDaemon(pod, PID.PID, int(a.Manager.VlanID), r.Env.TTL, r.Env.InterfacePodImage, a.Manager.OwnerNetworkName, r.Env.InterfacePodPullPolicy, a.Manager.Mappings)
246246
err = r.Client.Create(ctx, &job)
247247
if err != nil {
248248
if apierrors.IsAlreadyExists(err) {

internal/controller/interface.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import (
1111
)
1212

1313
type InterfacePod struct {
14-
ID int
15-
PID int
16-
Node string
14+
ID int
15+
PID int
16+
Node string
17+
InterfaceName string
1718
}
1819

19-
func interfaceFromDaemon(p corev1.Pod, pid, id int, ttl *int32, image, networkName, pullPolicy string) batchv1.Job {
20+
func interfaceFromDaemon(p corev1.Pod, pid, id int, ttl *int32, image, networkName, pullPolicy string, mappings []vlanmanv1.IPMapping) batchv1.Job {
21+
intrface := ""
22+
for _, m := range mappings {
23+
if m.NodeName == p.Spec.NodeName {
24+
intrface = m.Interface
25+
break
26+
}
27+
}
2028
var tgp int64 = 1
2129
return batchv1.Job{
2230
ObjectMeta: metav1.ObjectMeta{
@@ -47,6 +55,10 @@ func interfaceFromDaemon(p corev1.Pod, pid, id int, ttl *int32, image, networkNa
4755
Name: "ID",
4856
Value: strconv.FormatInt(int64(id), 10),
4957
},
58+
{
59+
Name: "INTERFACE",
60+
Value: intrface,
61+
},
5062
},
5163
SecurityContext: &corev1.SecurityContext{
5264
Capabilities: &corev1.Capabilities{

0 commit comments

Comments
 (0)