Skip to content

Commit 711daca

Browse files
authored
refactor(vmi-router): Use IP from our VirtualMachine (#69)
* refactor(vmi-router): Use IP from our VirtualMachine - Use status.ipaddress instead of extracting ip from huge status in Kubevirt VM. - Add environment variable CILIUM_ROUTE_TABLE_ID for route table id. - Refactor: proper use of controller-runtime. - Deps: drop kubevirt.io/client, update netlink, cilium, controller-runtime, k8 dependencies. - Fix: add aliases for netlink methods to develop with comfort in non-linux OSes. - Add golang 21 base image. Signed-off-by: Ivan Mikheykin <[email protected]>
1 parent b826ee1 commit 711daca

File tree

14 files changed

+993
-1596
lines changed

14 files changed

+993
-1596
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
image: {{ $.ImageName }}
3+
from: docker.io/golang:1.21.8-bookworm@sha256:ac14cc827536ef1a124cd2f7a03178c3335c1db8ad3807e7fdd57f74096abfa0

images/vmi-router/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## vmi-router
2+
3+
> **NOTE:** Not an accurate name, should be 'cilium-route-updater'.
4+
5+
This controller watches for VirtualMachines in virtualization.deckhouse.io group and updates routes in table 1490 to route traffic between VMs via Cilium agents.
6+
7+
It should be run as a DaemonSet with the `hostNetwork: true` to be able to modify route tables on cluster Nodes.
8+
9+
### Configuration
10+
11+
#### Log verbosity
12+
13+
Set VERBOSITY environment variable or -v flag.
14+
15+
#### Route table ID
16+
17+
Hardcoded as integer `1490`.
18+
19+
#### CIDRs
20+
21+
Use --cidr flags to specify CIDRs to limit managed IPs. Controller will update routes for VMs which IPs belong to specified CIDRs.
22+
23+
Example:
24+
25+
```
26+
vmi-router --cidr 10.2.0.0/24 --cidr 10.2.1.0/24 --cidr 10.2.2.0/24
27+
```
28+
29+
Controller will update route for VM with IP 10.2.1.32, but will ignore VM with IP 10.2.4.5.
30+
31+
#### Dry run mode
32+
33+
Use --dry-run flag to enable non destructive mode. The controller will not actually delete or replace rules and routes, only log these actions.
34+
35+
#### Metrics and healthz addresses
36+
37+
Controller can't predict used ports when starting in host network mode. So, be default, metrics and healthz are started on random free ports. Use flags to specify these addresses:
38+
39+
`--metrics-bind-address` - set port for /metrics endpoint, e.g. `--metrics-bind-address=:9250`
40+
`--health-probe-bind-address` - set port for /healthz endpoint, e.g. `--health-probe-bind-address=:9321`
41+

images/vmi-router/controllers/suite_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/envtest"
2929
logf "sigs.k8s.io/controller-runtime/pkg/log"
3030
"sigs.k8s.io/controller-runtime/pkg/log/zap"
31-
//+kubebuilder:scaffold:imports
3231
)
3332

3433
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
@@ -48,8 +47,8 @@ var _ = BeforeSuite(func() {
4847

4948
By("bootstrapping test environment")
5049
testEnv = &envtest.Environment{
51-
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
52-
ErrorIfCRDPathMissing: false,
50+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "crds")},
51+
ErrorIfCRDPathMissing: true,
5352
}
5453

5554
var err error
@@ -58,13 +57,10 @@ var _ = BeforeSuite(func() {
5857
Expect(err).NotTo(HaveOccurred())
5958
Expect(cfg).NotTo(BeNil())
6059

61-
//+kubebuilder:scaffold:scheme
62-
6360
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
6461
Expect(err).NotTo(HaveOccurred())
6562
Expect(k8sClient).NotTo(BeNil())
66-
67-
}, 60)
63+
})
6864

6965
var _ = AfterSuite(func() {
7066
By("tearing down the test environment")

0 commit comments

Comments
 (0)