Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support specifying routes when providing IPAM for other CNI plugins #3904

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

zhangzujian
Copy link
Member

@zhangzujian zhangzujian commented Apr 11, 2024

Pull Request

What type of this PR

  • Feature

With this patch, routes can be specified via network attachment definition:

apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan
  namespace: default
spec:
  config: |
    {
      "cniVersion": "0.3.1",
      "type": "macvlan",
      "master": "eth0",
      "mode": "bridge",
      "ipam": {
        "type": "kube-ovn",
        "server_socket": "/run/openvswitch/kube-ovn-daemon.sock",
        "provider": "macvlan.default",
        "routes": [
          {
            "dst": "192.168.0.0/16",
            "gw": "99.99.1.1"
          },
          {
            "gw": "99.99.1.254"
          }
        ]
      }
    }

Or via pod annotations:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: macvlan
  namespace: default
spec:
  selector:
    matchLabels:
      app: macvlan
  template:
    metadata:
      labels:
        app: macvlan
      annotations:
        k8s.v1.cni.cncf.io/networks: default/macvlan
        macvlan.default.kubernetes.io/routes: |
          [{
            "dst": "192.169.1.0/24",
            "gw": "99.99.1.99"
          }]
    spec:
      containers:
      - name: pod
        image: kubeovn/kube-ovn:v1.13.0
        command:
        - sh
        - -c
        - sleep 10000

Result:

root@macvlan-n4flx:/# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: net1@if62: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 82:ac:4d:0b:b5:da brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 99.99.1.6/24 brd 99.99.1.255 scope global net1
       valid_lft forever preferred_lft forever
    inet6 fe80::80ac:4dff:fe0b:b5da/64 scope link
       valid_lft forever preferred_lft forever
53: eth0@if54: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP group default
    link/ether 00:00:00:d6:17:c2 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.16.0.20/16 brd 10.16.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fd00:10:16::14/112 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::200:ff:fed6:17c2/64 scope link
       valid_lft forever preferred_lft forever
root@macvlan-n4flx:/# ip route show
default via 99.99.1.254 dev net1
10.16.0.0/16 dev eth0 proto kernel scope link src 10.16.0.20
99.99.1.0/24 dev net1 proto kernel scope link src 99.99.1.6
192.168.0.0/24 via 99.99.1.1 dev net1
192.169.1.0/24 via 99.99.1.99 dev net1

@zhangzujian zhangzujian added the feature New network feature label Apr 11, 2024
Signed-off-by: zhangzujian <[email protected]>
Signed-off-by: zhangzujian <[email protected]>
Signed-off-by: zhangzujian <[email protected]>
@zhangzujian zhangzujian marked this pull request as ready for review April 11, 2024 08:04
@zhangzujian zhangzujian merged commit 85ac741 into kubeovn:master Apr 11, 2024
63 checks passed
@zhangzujian zhangzujian deleted the cni-ipam-routes branch April 11, 2024 09:12
zhangzujian added a commit to zhangzujian/kube-ovn that referenced this pull request Apr 11, 2024
bobz965 pushed a commit that referenced this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New network feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants