Skip to content

Commit

Permalink
refactor(vmi-router): Use IP from our VirtualMachine (#69)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
diafour authored Apr 26, 2024
1 parent b826ee1 commit 711daca
Show file tree
Hide file tree
Showing 14 changed files with 993 additions and 1,596 deletions.
3 changes: 3 additions & 0 deletions images/base-golang-21-bookworm/werf.inc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
image: {{ $.ImageName }}
from: docker.io/golang:1.21.8-bookworm@sha256:ac14cc827536ef1a124cd2f7a03178c3335c1db8ad3807e7fdd57f74096abfa0
41 changes: 41 additions & 0 deletions images/vmi-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## vmi-router

> **NOTE:** Not an accurate name, should be 'cilium-route-updater'.
This controller watches for VirtualMachines in virtualization.deckhouse.io group and updates routes in table 1490 to route traffic between VMs via Cilium agents.

It should be run as a DaemonSet with the `hostNetwork: true` to be able to modify route tables on cluster Nodes.

### Configuration

#### Log verbosity

Set VERBOSITY environment variable or -v flag.

#### Route table ID

Hardcoded as integer `1490`.

#### CIDRs

Use --cidr flags to specify CIDRs to limit managed IPs. Controller will update routes for VMs which IPs belong to specified CIDRs.

Example:

```
vmi-router --cidr 10.2.0.0/24 --cidr 10.2.1.0/24 --cidr 10.2.2.0/24
```

Controller will update route for VM with IP 10.2.1.32, but will ignore VM with IP 10.2.4.5.

#### Dry run mode

Use --dry-run flag to enable non destructive mode. The controller will not actually delete or replace rules and routes, only log these actions.

#### Metrics and healthz addresses

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:

`--metrics-bind-address` - set port for /metrics endpoint, e.g. `--metrics-bind-address=:9250`
`--health-probe-bind-address` - set port for /healthz endpoint, e.g. `--health-probe-bind-address=:9321`

10 changes: 3 additions & 7 deletions images/vmi-router/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
)

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

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: false,
CRDDirectoryPaths: []string{filepath.Join("..", "..", "crds")},
ErrorIfCRDPathMissing: true,
}

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

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

}, 60)
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
Expand Down
Loading

0 comments on commit 711daca

Please sign in to comment.