Skip to content

Commit 369ab3d

Browse files
committed
Support bandwidth
1 parent 5400267 commit 369ab3d

File tree

13 files changed

+158
-35
lines changed

13 files changed

+158
-35
lines changed

cni/k8s-sriov/k8s_sriov.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
t020 "github.com/containernetworking/cni/pkg/types/020"
3131
"github.com/containernetworking/cni/pkg/version"
3232
"github.com/containernetworking/plugins/pkg/ns"
33+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
3334
"github.com/vishvananda/netlink"
3435
glog "k8s.io/klog"
3536
galaxyIpam "tkestack.io/galaxy/cni/ipam"
@@ -114,8 +115,12 @@ func cmdDel(args *skel.CmdArgs) error {
114115
return galaxyIpam.Release(conf.IPAM.Type, args)
115116
}
116117

118+
func cmdCheck(args *skel.CmdArgs) error {
119+
return nil
120+
}
121+
117122
func main() {
118-
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
123+
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.Legacy, bv.BuildString("k8s-sriov"))
119124
}
120125

121126
// code from https://raw.githubusercontent.com/Intel-Corp/sriov-cni/master/sriov/sriov.go

cni/k8s-vlan/k8s_vlan.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/containernetworking/cni/pkg/types"
2626
t020 "github.com/containernetworking/cni/pkg/types/020"
2727
"github.com/containernetworking/cni/pkg/version"
28+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
2829
"tkestack.io/galaxy/cni/ipam"
2930
"tkestack.io/galaxy/pkg/network/vlan"
3031
"tkestack.io/galaxy/pkg/utils"
@@ -190,7 +191,11 @@ func cmdDel(args *skel.CmdArgs) error {
190191
return ipam.Release(conf.IPAM.Type, args)
191192
}
192193

194+
func cmdCheck(args *skel.CmdArgs) error {
195+
return nil
196+
}
197+
193198
func main() {
194199
d = &vlan.VlanDriver{}
195-
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
200+
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.Legacy, bv.BuildString("k8s-vlan"))
196201
}

cni/sdn/sdn.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import (
2727
"strings"
2828

2929
"github.com/containernetworking/cni/pkg/skel"
30-
t020 "github.com/containernetworking/cni/pkg/types/020"
30+
current "github.com/containernetworking/cni/pkg/types/current"
3131
"github.com/containernetworking/cni/pkg/version"
32+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
3233
galaxyapi "tkestack.io/galaxy/pkg/api/galaxy"
3334
"tkestack.io/galaxy/pkg/api/galaxy/private"
3435
)
@@ -94,13 +95,13 @@ func (p *cniPlugin) doCNI(url string, req *galaxyapi.CNIRequest) ([]byte, error)
9495

9596
// Send the ADD command environment and config to the CNI server, returning
9697
// the IPAM result to the caller
97-
func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) (*t020.Result, error) {
98+
func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) (*current.Result, error) {
9899
body, err := p.doCNI("http://dummy/cni", newCNIRequest(args))
99100
if err != nil {
100101
return nil, err
101102
}
102103

103-
result := &t020.Result{}
104+
result := &current.Result{}
104105
if err := json.Unmarshal(body, result); err != nil {
105106
return nil, fmt.Errorf("failed to unmarshal response '%s': %v", string(body), err)
106107
}
@@ -124,7 +125,11 @@ func (p *cniPlugin) CmdDel(args *skel.CmdArgs) error {
124125
return err
125126
}
126127

128+
func (p *cniPlugin) cmdCheck(args *skel.CmdArgs) error {
129+
return nil
130+
}
131+
127132
func main() {
128133
p := NewCNIPlugin(private.GalaxySocketPath)
129-
skel.PluginMain(p.skelCmdAdd, p.CmdDel, version.Legacy)
134+
skel.PluginMain(p.skelCmdAdd, p.cmdCheck, p.CmdDel, version.All, bv.BuildString("galaxy-sdn"))
130135
}

cni/tke-route-eni/cni.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ import (
2727
"github.com/containernetworking/cni/pkg/skel"
2828
"github.com/containernetworking/cni/pkg/types"
2929
t020 "github.com/containernetworking/cni/pkg/types/020"
30-
"github.com/containernetworking/cni/pkg/types/current"
30+
current "github.com/containernetworking/cni/pkg/types/current"
3131
cniSpecVersion "github.com/containernetworking/cni/pkg/version"
3232
"github.com/containernetworking/plugins/pkg/ip"
3333
"github.com/containernetworking/plugins/pkg/ns"
34+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
3435
"github.com/vishvananda/netlink"
3536

3637
galaxyIpam "tkestack.io/galaxy/cni/ipam"
@@ -221,6 +222,10 @@ func cmdDel(args *skel.CmdArgs) error {
221222
return err
222223
}
223224

225+
func cmdCheck(args *skel.CmdArgs) error {
226+
return nil
227+
}
228+
224229
func main() {
225-
skel.PluginMain(cmdAdd, cmdDel, cniSpecVersion.All)
230+
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, cniSpecVersion.All, bv.BuildString("tke-route-eni"))
226231
}

cni/underlay/veth/veth.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/containernetworking/cni/pkg/types"
1111
t020 "github.com/containernetworking/cni/pkg/types/020"
1212
"github.com/containernetworking/cni/pkg/version"
13+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
1314
"github.com/vishvananda/netlink"
1415
"tkestack.io/galaxy/cni/ipam"
1516
"tkestack.io/galaxy/pkg/network"
@@ -25,7 +26,7 @@ func init() {
2526
}
2627

2728
func main() {
28-
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
29+
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("underlay-veth"))
2930
}
3031

3132
func cmdDel(args *skel.CmdArgs) error {
@@ -35,6 +36,10 @@ func cmdDel(args *skel.CmdArgs) error {
3536
return nil
3637
}
3738

39+
func cmdCheck(args *skel.CmdArgs) error {
40+
return nil
41+
}
42+
3843
func cmdAdd(args *skel.CmdArgs) error {
3944
conf := vlan.NetConf{}
4045
if err := json.Unmarshal(args.StdinData, &conf); err != nil {

cni/veth/veth.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/containernetworking/cni/pkg/version"
3030
"github.com/containernetworking/plugins/pkg/ipam"
3131
"github.com/containernetworking/plugins/pkg/ns"
32+
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
3233
"github.com/vishvananda/netlink"
3334
"tkestack.io/galaxy/pkg/utils"
3435
)
@@ -221,6 +222,10 @@ func cmdDel(args *skel.CmdArgs) error {
221222
return nil
222223
}
223224

225+
func cmdCheck(args *skel.CmdArgs) error {
226+
return nil
227+
}
228+
224229
func main() {
225-
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
230+
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("veth"))
226231
}

e2e/cni-request/request_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cni_request_test
1818

1919
import (
2020
"bytes"
21+
"encoding/json"
2122
"fmt"
2223
"io/ioutil"
2324
"net"
@@ -32,6 +33,8 @@ import (
3233
"tkestack.io/galaxy/pkg/api/galaxy/private"
3334
"tkestack.io/galaxy/pkg/galaxy"
3435

36+
t020 "github.com/containernetworking/cni/pkg/types/020"
37+
current "github.com/containernetworking/cni/pkg/types/current"
3538
. "github.com/onsi/ginkgo"
3639
. "github.com/onsi/gomega"
3740
glog "k8s.io/klog"
@@ -93,7 +96,7 @@ FLANNEL_IPMASQ=true`
9396
Expect(err).NotTo(HaveOccurred())
9497
jsonFile = jsonConfigFile.Name()
9598
Expect(jsonConfigFile.Close()).NotTo(HaveOccurred())
96-
err = ioutil.WriteFile(jsonFile, []byte(`{"NetworkConf":[{"type":"galaxy-flannel", "delegate":{"type":"galaxy-bridge","isDefaultGateway":true,"forceAddress":true},"subnetFile":"/run/flannel/subnet.env"}], "DefaultNetworks": ["galaxy-flannel"]}`), 0644)
99+
err = ioutil.WriteFile(jsonFile, []byte(`{"NetworkConf":[{"type":"galaxy-flannel", "delegate":{"type":"galaxy-bridge","isDefaultGateway":true,"forceAddress":true},"subnetFile":"/run/flannel/subnet.env","cniVersion": "0.3.1"}], "DefaultNetworks": ["galaxy-flannel"]}`), 0644)
97100
Expect(err).NotTo(HaveOccurred())
98101

99102
g := galaxy.NewGalaxy()
@@ -130,7 +133,7 @@ var _ = Describe("cni add request", func() {
130133
content := call(cniutil.COMMAND_ADD)
131134
// the result ip may change, check other things.
132135
Expect(strings.HasPrefix(content, `{"cniVersion":"0.2.0","ip4":{"ip":"172.16.59.`)).Should(BeTrue())
133-
Expect(strings.HasSuffix(content, `/24","gateway":"172.16.59.1","routes":[{"dst":"172.16.0.0/13","gw":"172.16.59.1"},{"dst":"0.0.0.0/0","gw":"172.16.59.1"}]},"dns":{}}`)).
136+
Expect(strings.HasSuffix(content, `/24","gateway":"172.16.59.1","routes":[{"dst":"172.16.0.0/13"},{"dst":"0.0.0.0/0","gw":"172.16.59.1"}]},"dns":{}}`)).
134137
Should(BeTrue())
135138
})
136139
It("cni delete request", func() {
@@ -154,5 +157,15 @@ func call(method string) string {
154157
Expect(err).NotTo(HaveOccurred())
155158
content, err := ioutil.ReadAll(resp.Body)
156159
Expect(err).NotTo(HaveOccurred())
157-
return string(content)
160+
if len(content) == 0 {
161+
return ""
162+
}
163+
resultCurrent := &current.Result{}
164+
err = json.Unmarshal(content, resultCurrent)
165+
Expect(err).NotTo(HaveOccurred())
166+
result020, err := resultCurrent.GetAsVersion(t020.ImplementedSpecVersion)
167+
Expect(err).NotTo(HaveOccurred())
168+
bytes, err := json.Marshal(result020)
169+
Expect(err).NotTo(HaveOccurred())
170+
return string(bytes)
158171
}

e2e/helper/util.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,28 @@
1717
package helper
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"net"
2223
"os"
2324
"os/exec"
2425
"path"
2526
"path/filepath"
2627
"strings"
28+
"time"
2729

2830
"github.com/containernetworking/cni/pkg/invoke"
2931
"github.com/containernetworking/cni/pkg/types"
32+
"github.com/containernetworking/cni/pkg/version"
3033
"github.com/google/uuid"
3134
glog "k8s.io/klog"
3235
)
3336

37+
const (
38+
// CNITimeoutSec is set to be slightly less than 240sec/4mins, which is the default remote runtime request timeout.
39+
CNITimeoutSec = 220
40+
)
41+
3442
var (
3543
packageName = "tkestack.io/galaxy"
3644
CNI_IFNAME = "eth0"
@@ -50,11 +58,16 @@ func fillDefaultArgs(root string, args *invoke.Args) *invoke.Args {
5058
//ip netns add ctn
5159
// CNI_ARGS="IP=192.168.33.3" CNI_COMMAND="ADD" CNI_CONTAINERID=ctn1 CNI_NETNS=/var/run/netns/ctn CNI_IFNAME=eth0 CNI_PATH=`pwd`/bin galaxy-vlan < /etc/cni/net.d/10-mynet.conf
5260
func ExecCNIWithResult(cniName string, netConfStdin []byte, args *invoke.Args) (types.Result, error) {
61+
cniTimeoutCtx, cancelFunc := context.WithTimeout(context.Background(), CNITimeoutSec*time.Second)
62+
defer cancelFunc()
5363
root := ProjectDir()
5464
pluginPath := path.Join(root, "bin", cniName)
5565
cniArgs := fillDefaultArgs(root, args)
5666
glog.V(4).Infof("echo %s | %s %s", compressJson(string(netConfStdin)), strings.Join(cniArgs.AsEnv()[:6], " "), pluginPath)
57-
return invoke.ExecPluginWithResult(pluginPath, netConfStdin, cniArgs)
67+
return invoke.ExecPluginWithResult(cniTimeoutCtx, pluginPath, netConfStdin, cniArgs, &invoke.DefaultExec{
68+
RawExec: &invoke.RawExec{Stderr: os.Stderr},
69+
PluginDecoder: version.PluginDecoder{},
70+
})
5871
}
5972

6073
func compressJson(str string) string {
@@ -65,8 +78,13 @@ func compressJson(str string) string {
6578
}
6679

6780
func ExecCNI(cniName string, netConfStdin []byte, args *invoke.Args) error {
81+
cniTimeoutCtx, cancelFunc := context.WithTimeout(context.Background(), CNITimeoutSec*time.Second)
82+
defer cancelFunc()
6883
root := ProjectDir()
69-
return invoke.ExecPluginWithoutResult(path.Join(root, "bin", cniName), netConfStdin, fillDefaultArgs(root, args))
84+
return invoke.ExecPluginWithoutResult(cniTimeoutCtx, path.Join(root, "bin", cniName), netConfStdin, fillDefaultArgs(root, args), &invoke.DefaultExec{
85+
RawExec: &invoke.RawExec{Stderr: os.Stderr},
86+
PluginDecoder: version.PluginDecoder{},
87+
})
7088
}
7189

7290
func NewContainerId() string {
@@ -127,7 +145,7 @@ func SetupDummyDev(ifName, cidr string) error {
127145
}
128146

129147
func SetupVlanDev(ifName, parent, cidr string, vlanID int) error {
130-
if out, err := Command("ip", "link", "add", "link",parent, "name", ifName, "type", "vlan", "id", fmt.Sprintf("%d", vlanID)).CombinedOutput(); err != nil {
148+
if out, err := Command("ip", "link", "add", "link", parent, "name", ifName, "type", "vlan", "id", fmt.Sprintf("%d", vlanID)).CombinedOutput(); err != nil {
131149
if !strings.HasPrefix(string(out), "RTNETLINK answers: File exists") {
132150
return fmt.Errorf("failed to add link %s: %v, %s", ifName, err, string(out))
133151
}

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ go 1.14
44

55
require (
66
github.com/Microsoft/go-winio v0.4.15 // indirect
7-
github.com/containernetworking/cni v0.6.0
8-
github.com/containernetworking/plugins v0.6.0
9-
github.com/coreos/go-iptables v0.4.3 // indirect
7+
github.com/containernetworking/cni v0.8.0
8+
github.com/containernetworking/plugins v0.8.7
109
github.com/dbdd4us/qcloudapi-sdk-go v0.0.0-20190530123522-c8d9381de48c
1110
github.com/docker/distribution v2.7.1+incompatible // indirect
1211
github.com/docker/engine-api v0.4.0

0 commit comments

Comments
 (0)