Skip to content

Commit

Permalink
windows support for CNI
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Mar 31, 2022
1 parent f2baa2f commit 902315e
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 63 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Windows Binaries

on:
pull_request:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'
push:
branches:
- master
- release-*
paths-ignore:
- 'docs/**'
- '**.md'

jobs:
build:
name: Build Windows x86
runs-on: windows-2019
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17.8
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Go Build Cache
uses: actions/cache@v2
with:
path: /home/runner/.cache/go-build
key: ${{ runner.os }}-go-x86-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-x86-build-
- name: Go Mod Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: |
go mod tidy
go install github.com/securego/gosec/cmd/gosec@latest
make lint-windows
make build-go-windows
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.idea/*
.vscode/*
.DS_Store
dist/images/kube-ovn
dist/images/kube-ovn-cmd
dist/images/kube-ovn.exe
test/e2e/ovnnb_db.*
test/e2e/ovnsb_db.*
kube-ovn.yaml
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ build-go:
go mod tidy
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd

.PHONY: build-go-windows
build-go-windows:
go mod tidy
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn.exe -ldflags $(GOLDFLAGS) -v ./cmd/windows/cni

.PHONY: build-go-arm
build-go-arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -buildmode=pie -o $(CURDIR)/dist/images/kube-ovn-cmd -ldflags $(GOLDFLAGS) -v ./cmd
Expand Down Expand Up @@ -359,6 +364,13 @@ lint:
@GOOS=linux go vet ./...
@GOOS=linux gosec -exclude=G204,G601 ./...

.PHONY: lint-windows
lint-windows:
@GOOS=windows go vet ./cmd/windows/...
@GOOS=windows gosec -exclude=G204,G601 ./pkg/util
@GOOS=windows gosec -exclude=G204,G601 ./pkg/request
@GOOS=windows gosec -exclude=G204,G601 ./cmd/cni

.PHONY: scan
scan:
trivy image --light --exit-code=1 --severity=HIGH --ignore-unfixed $(REGISTRY)/kube-ovn:$(RELEASE_TAG)
Expand Down
20 changes: 5 additions & 15 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func cmdAdd(args *skel.CmdArgs) error {
IfName: args.IfName,
Provider: netConf.Provider,
Routes: netConf.Routes,
DNS: netConf.DNS,
DeviceID: netConf.DeviceID,
VfDriver: netConf.VfDriver,
VhostUserSocketVolumeName: netConf.VhostUserSocketVolumeName,
Expand All @@ -68,7 +69,10 @@ func cmdAdd(args *skel.CmdArgs) error {
}

func generateCNIResult(cniResponse *request.CniResponse) current.Result {
result := current.Result{CNIVersion: current.ImplementedSpecVersion}
result := current.Result{
CNIVersion: current.ImplementedSpecVersion,
DNS: cniResponse.DNS,
}
_, mask, _ := net.ParseCIDR(cniResponse.CIDR)
podIface := current.Interface{
Name: cniResponse.PodNicName,
Expand Down Expand Up @@ -148,20 +152,6 @@ type ipamConf struct {
Provider string `json:"provider"`
}

type netConf struct {
types.NetConf
ServerSocket string `json:"server_socket"`
Provider string `json:"provider"`
Routes []request.Route `json:"routes"`
IPAM *ipamConf `json:"ipam"`
// PciAddrs in case of using sriov
DeviceID string `json:"deviceID"`
VfDriver string `json:"vf_driver"`
// for dpdk
VhostUserSocketVolumeName string `json:"vhost_user_socket_volume_name"`
VhostUserSocketName string `json:"vhost_user_socket_name"`
}

func loadNetConf(bytes []byte) (*netConf, string, error) {
n := &netConf{}
if err := json.Unmarshal(bytes, n); err != nil {
Expand Down
24 changes: 24 additions & 0 deletions cmd/cni/netconf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !windows
// +build !windows

package cni

import (
"github.com/containernetworking/cni/pkg/types"

"github.com/kubeovn/kube-ovn/pkg/request"
)

type netConf struct {
types.NetConf
ServerSocket string `json:"server_socket"`
Provider string `json:"provider"`
Routes []request.Route `json:"routes"`
IPAM *ipamConf `json:"ipam"`
// PciAddrs in case of using sriov
DeviceID string `json:"deviceID"`
VfDriver string `json:"vf_driver"`
// for dpdk
VhostUserSocketVolumeName string `json:"vhost_user_socket_volume_name"`
VhostUserSocketName string `json:"vhost_user_socket_name"`
}
21 changes: 21 additions & 0 deletions cmd/cni/netconf_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cni

import (
"github.com/containernetworking/plugins/pkg/hns"

"github.com/kubeovn/kube-ovn/pkg/request"
)

type netConf struct {
hns.NetConf
ServerSocket string `json:"server_socket"`
Provider string `json:"provider"`
Routes []request.Route `json:"routes"`
IPAM *ipamConf `json:"ipam"`
// PciAddrs in case of using sriov
DeviceID string `json:"deviceID"`
VfDriver string `json:"vf_driver"`
// for dpdk
VhostUserSocketVolumeName string `json:"vhost_user_socket_volume_name"`
VhostUserSocketName string `json:"vhost_user_socket_name"`
}
7 changes: 7 additions & 0 deletions cmd/windows/cni/main_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/kubeovn/kube-ovn/cmd/cni"

func main() {
cni.CmdMain()
}
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.17

require (
github.com/Mellanox/sriovnet v1.0.3
github.com/Microsoft/go-winio v0.5.2
github.com/alauda/felix v3.6.6-0.20201207121355-187332daf314+incompatible
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08
github.com/containernetworking/cni v1.0.1
Expand All @@ -25,7 +26,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/vishvananda/netlink v1.1.1-0.20211101163509-b10eb8fe5cf6
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f
google.golang.org/grpc v1.40.0
gopkg.in/k8snetworkplumbingwg/multus-cni.v3 v3.7.2
k8s.io/api v0.23.1
Expand All @@ -39,9 +40,12 @@ require (
)

require (
github.com/Microsoft/hcsshim v0.8.22 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/containerd/cgroups v1.0.1 // indirect
github.com/coreos/prometheus-operator v0.38.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
Expand Down Expand Up @@ -101,6 +105,7 @@ require (
github.com/stretchr/objx v0.3.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX
github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.4.17-0.20210324224401-5516f17a5958/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.4.17/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
github.com/Microsoft/hcsshim v0.8.7-0.20190325164909-8abdbb8205e4/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
github.com/Microsoft/hcsshim v0.8.7/go.mod h1:OHd7sQqRFrYd3RmSgbgji+ctCwkbq2wbEYNSzOYtcBQ=
Expand All @@ -114,6 +116,7 @@ github.com/Microsoft/hcsshim v0.8.14/go.mod h1:NtVKoYxQuTLx6gEq0L96c9Ju4JbRJ4nY2
github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn69iY6URG00=
github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600=
github.com/Microsoft/hcsshim v0.8.20/go.mod h1:+w2gRZ5ReXQhFOrvSQeNfhrYB/dg3oDwTOcER2fw4I4=
github.com/Microsoft/hcsshim v0.8.22 h1:CulZ3GW8sNJExknToo+RWD+U+6ZM5kkNfuxywSDPd08=
github.com/Microsoft/hcsshim v0.8.22/go.mod h1:91uVCVzvX2QD16sMCenoxxXo6L1wJnLMX2PSufFMtF0=
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
Expand Down Expand Up @@ -188,6 +191,7 @@ github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQ
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d/go.mod h1:IyUJYN1gvWjtLF5ZuygmxbnsAyP3aJS6cHzIuZY50B0=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
Expand Down Expand Up @@ -249,6 +253,7 @@ github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59/go.mod h1:pA0z1
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
github.com/containerd/cgroups v1.0.1 h1:iJnMvco9XGvKUvNQkv88bE4uJXxRQH18efbKo9w5vHQ=
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
Expand Down Expand Up @@ -1311,6 +1316,7 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E=
Expand Down Expand Up @@ -1638,8 +1644,8 @@ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
Expand Down
21 changes: 21 additions & 0 deletions pkg/request/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !windows
// +build !windows

package request

import (
"context"
"net"
"net/http"

"github.com/parnurzeal/gorequest"
)

// NewCniServerClient return a new cniserver client
func NewCniServerClient(socketAddress string) CniServerClient {
request := gorequest.New()
request.Transport = &http.Transport{DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", socketAddress)
}}
return CniServerClient{request}
}
19 changes: 19 additions & 0 deletions pkg/request/client_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package request

import (
"context"
"net"
"net/http"

"github.com/Microsoft/go-winio"
"github.com/parnurzeal/gorequest"
)

// NewCniServerClient return a new cniserver client
func NewCniServerClient(pipePath string) CniServerClient {
request := gorequest.New()
request.Transport = &http.Transport{DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
return winio.DialPipeContext(ctx, pipePath)
}}
return CniServerClient{request}
}
49 changes: 20 additions & 29 deletions pkg/request/cniserver.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package request

import (
"context"
"fmt"
"net"
"net/http"

"github.com/containernetworking/cni/pkg/types"
"github.com/parnurzeal/gorequest"
)

Expand All @@ -22,15 +20,16 @@ type Route struct {

// CniRequest is the cniserver request format
type CniRequest struct {
CniType string `json:"cni_type"`
PodName string `json:"pod_name"`
PodNamespace string `json:"pod_namespace"`
ContainerID string `json:"container_id"`
NetNs string `json:"net_ns"`
IfName string `json:"if_name"`
Provider string `json:"provider"`
Routes []Route `json:"routes"`
VfDriver string `json:"vf_driver"`
CniType string `json:"cni_type"`
PodName string `json:"pod_name"`
PodNamespace string `json:"pod_namespace"`
ContainerID string `json:"container_id"`
NetNs string `json:"net_ns"`
IfName string `json:"if_name"`
Provider string `json:"provider"`
Routes []Route `json:"routes"`
DNS types.DNS `json:"dns"`
VfDriver string `json:"vf_driver"`
// PciAddrs in case of using sriov
DeviceID string `json:"deviceID"`
// dpdk
Expand All @@ -41,23 +40,15 @@ type CniRequest struct {

// CniResponse is the cniserver response format
type CniResponse struct {
Protocol string `json:"protocol"`
IpAddress string `json:"address"`
MacAddress string `json:"mac_address"`
CIDR string `json:"cidr"`
Gateway string `json:"gateway"`
Mtu int `json:"mtu"`
PodNicName string `json:"nicname"`
Err string `json:"error"`
}

// NewCniServerClient return a new cniserver client
func NewCniServerClient(socketAddress string) CniServerClient {
request := gorequest.New()
request.Transport = &http.Transport{DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", socketAddress)
}}
return CniServerClient{request}
Protocol string `json:"protocol"`
IpAddress string `json:"address"`
MacAddress string `json:"mac_address"`
CIDR string `json:"cidr"`
Gateway string `json:"gateway"`
Mtu int `json:"mtu"`
PodNicName string `json:"nicname"`
DNS types.DNS `json:"dns"`
Err string `json:"error"`
}

// Add pod request
Expand Down
Loading

0 comments on commit 902315e

Please sign in to comment.