Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
- run: make test
- run: sudo make test
- run: make lint

2 changes: 1 addition & 1 deletion examples/demo_gke_multinetwork/resourceclaim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ metadata:
spec:
containers:
- name: ctr1
image: registry.k8s.io/e2e-test-images/agnhost:2.39
image: registry.k8s.io/e2e-test-images/agnhost:2.54
resourceClaims:
- name: dranet-network
resourceClaimName: dranet-network
2 changes: 1 addition & 1 deletion examples/demo_gke_multinetwork/resourceclaimtemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
resourceClaimTemplateName: phy-interfaces-template
containers:
- name: agnhost
image: registry.k8s.io/e2e-test-images/agnhost:2.39
image: registry.k8s.io/e2e-test-images/agnhost:2.54
args:
- netexec
- --http-port=80
Expand Down
2 changes: 1 addition & 1 deletion examples/resourceclaim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
spec:
containers:
- name: ctr1
image: registry.k8s.io/e2e-test-images/agnhost:2.39
image: registry.k8s.io/e2e-test-images/agnhost:2.54
resourceClaims:
- name: dummy1
resourceClaimName: dummy-interface-static-ip
Expand Down
57 changes: 57 additions & 0 deletions examples/resourceclaim_advanced.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: resource.k8s.io/v1beta1
kind: ResourceClaim
metadata:
name: dummy-interface-advanced
spec:
devices:
requests:
- name: req-dummy-advanced
deviceClassName: dra.net
selectors:
- cel:
expression: device.attributes["dra.net"].ifName == "dummy3"
config:
- opaque:
driver: dra.net
parameters:
interface:
name: "dranet0"
addresses:
- "169.254.169.14/24"
mtu: 4321
hardwareAddr: "00:11:22:33:44:55"
ethtool:
features:
tcp-segmentation-offload: false
generic-receive-offload: false
large-receive-offload: false
---
apiVersion: v1
kind: Pod
metadata:
name: pod-advanced-cfg
labels:
app: pod
spec:
containers:
- name: ctr1
image: registry.k8s.io/e2e-test-images/agnhost:2.54
# Keep the container running
command: ["sleep", "infinity"]
resourceClaims:
- name: dummy1
resourceClaimName: dummy-interface-advanced
59 changes: 59 additions & 0 deletions examples/resourceclaim_bigtcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: resource.k8s.io/v1beta1
kind: ResourceClaim
metadata:
name: dummy-interface-bigtcp
spec:
devices:
requests:
- name: req-dummy-bigtcp
deviceClassName: dra.net
selectors:
- cel:
expression: device.attributes["dra.net"].ifName == "dummy4"
config:
- opaque:
driver: dra.net
parameters:
interface:
name: "dranet1" # Name of the interface inside the pod
addresses:
- "192.168.200.1/24"
mtu: 8896
gsoMaxSize: 65536
groMaxSize: 65536
gsoIPv4MaxSize: 65536
groIPv4MaxSize: 65536
ethtool:
features:
tcp-segmentation-offload: true
generic-receive-offload: true
large-receive-offload: false
---
apiVersion: v1
kind: Pod
metadata:
name: pod-bigtcp-test
labels:
app: bigtcp
spec:
containers:
- name: agnhost-bigtcp
image: registry.k8s.io/e2e-test-images/agnhost:2.54
command: ["sleep", "infinity"]
resourceClaims:
- name: bigtcp-net
resourceClaimName: dummy-interface-bigtcp
2 changes: 1 addition & 1 deletion examples/resourceclaim_route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ metadata:
spec:
containers:
- name: ctr1
image: registry.k8s.io/e2e-test-images/agnhost:2.39
image: registry.k8s.io/e2e-test-images/agnhost:2.54
resourceClaims:
- name: dummy1
resourceClaimName: dummy-interface-static-ip-route
2 changes: 1 addition & 1 deletion examples/resourceclaimtemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
resourceClaimTemplateName: phy-interfaces-template
containers:
- name: agnhost
image: registry.k8s.io/e2e-test-images/agnhost:2.39
image: registry.k8s.io/e2e-test-images/agnhost:2.54
args:
- netexec
- --http-port=80
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ require (
github.com/google/cel-go v0.25.0
github.com/google/go-cmp v0.7.0
github.com/insomniacslk/dhcp v0.0.0-20250417080101-5f8cf70e8c5f
github.com/mdlayher/genetlink v1.3.2
github.com/mdlayher/netlink v1.7.2
github.com/prometheus/client_golang v1.22.0
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw=
github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o=
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
Expand Down
73 changes: 62 additions & 11 deletions pkg/apis/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,75 @@ limitations under the License.

package apis

// NetworkConfig represents the desired state of all network interfaces and their associated routes.
// NetworkConfig represents the desired state of all network interfaces and their associated routes,
// along with ethtool and sysctl configurations to be applied within the Pod's network namespace.
type NetworkConfig struct {
Interface InterfaceConfig `json:"interface"` // Changed to a slice to support multiple interfaces
Routes []RouteConfig `json:"routes"`
// Interface defines core properties of the network interface.
// Settings here are typically managed by `ip link` commands.
Interface InterfaceConfig `json:"interface"`

// Routes defines static routes to be configured for this interface.
Routes []RouteConfig `json:"routes,omitempty"`

// Ethtool defines hardware offload features and other settings managed by `ethtool`.
Ethtool *EthtoolConfig `json:"ethtool,omitempty"`
}

// InterfaceConfig represents the configuration for a single network interface.
// These are fundamental properties, often managed using `ip link` commands.
type InterfaceConfig struct {
Name string `json:"name,omitempty"` // Logical name of the interface (e.g., "eth0", "enp0s3")
Addresses []string `json:"addresses,omitempty"` // IP addresses and their CIDR masks
MTU int32 `json:"mtu,omitempty"` // Maximum Transmission Unit, optional
HardwareAddr string `json:"hardwareAddr,omitempty"` // Read-only: Current hardware address (might be useful for GET)
// Name is the desired logical name of the interface inside the Pod (e.g., "net0", "eth_app").
// If not specified, DraNet may use or derive a name from the original interface.
Name string `json:"name,omitempty"`

// Addresses is a list of IP addresses in CIDR format (e.g., "192.168.1.10/24")
// to be assigned to the interface.
Addresses []string `json:"addresses,omitempty"`

// MTU is the Maximum Transmission Unit for the interface.
MTU *int32 `json:"mtu,omitempty"`

// HardwareAddr is the MAC address of the interface.
HardwareAddr *string `json:"hardwareAddr,omitempty"`

// GSOMaxSize sets the maximum Generic Segmentation Offload size for IPv6.
// Managed by `ip link set <dev> gso_max_size <val>`. For enabling Big TCP.
GSOMaxSize *int32 `json:"gsoMaxSize,omitempty"`

// GROMaxSize sets the maximum Generic Receive Offload size for IPv6.
// Managed by `ip link set <dev> gro_max_size <val>`. For enabling Big TCP.
GROMaxSize *int32 `json:"groMaxSize,omitempty"`

// GSOv4MaxSize sets the maximum Generic Segmentation Offload size.
// Managed by `ip link set <dev> gso_ipv4_max_size <val>`. For enabling Big TCP.
GSOIPv4MaxSize *int32 `json:"gsoIPv4MaxSize,omitempty"`

// GROv4MaxSize sets the maximum Generic Receive Offload size.
// Managed by `ip link set <dev> gro_ipv4_max_size <val>`. For enabling Big TCP.
GROIPv4MaxSize *int32 `json:"groIPv4MaxSize,omitempty"`
}

// RouteConfig represents a network route configuration.
type RouteConfig struct {
Destination string `json:"destination,omitempty"` // e.g., "0.0.0.0/0" for default, "10.0.0.0/8"
Gateway string `json:"gateway,omitempty"` // The "gateway" address, e.g., "192.168.1.1"
Source string `json:"source,omitempty"` // Optional source address for policy routing
Scope uint8 `json:"scope,omitempty"` // Optional scope of the route, only Link (253) or Universe (0) allowed
// Destination is the target network in CIDR format (e.g., "0.0.0.0/0", "10.0.0.0/8").
Destination string `json:"destination,omitempty"`
// Gateway is the IP address of the gateway for this route.
Gateway string `json:"gateway,omitempty"`
// Source is an optional source IP address for policy routing.
Source string `json:"source,omitempty"`
// Scope is the scope of the route (e.g., link, host, global).
// Refers to Linux route scopes (e.g., 0 for RT_SCOPE_UNIVERSE, 253 for RT_SCOPE_LINK).
Scope uint8 `json:"scope,omitempty"`
}

// EthtoolConfig defines ethtool-based optimizations for a network interface.
// These settings correspond to features typically toggled using `ethtool -K <dev> <feature> on|off`.
type EthtoolConfig struct {
// Features is a map of ethtool feature names to their desired state (true for on, false for off).
// Example: {"tcp-segmentation-offload": true, "rx-checksum": true}
Features map[string]bool `json:"features,omitempty"`

// PrivateFlags is a map of device-specific private flag names to their desired state.
// Example: {"my-custom-flag": true}
PrivateFlags map[string]bool `json:"privateFlags,omitempty"`
}
Loading
Loading