Skip to content

Commit

Permalink
Release cce-network-v1/1.8.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gola committed Feb 9, 2024
1 parent 5280872 commit 5ab79ad
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 69 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each funct
COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile

# versions
VERSION := v1.8.8
VERSION := v1.8.9
FELIX_VERSION := v3.5.8
K8S_VERSION := 1.18.9

Expand All @@ -41,7 +41,7 @@ EXTRALDFLAGS += -X $(GO_PACKAGE)/pkg/version.Version=$(VERSION)
# pro or dev
PROFILES := dev
IMAGE_TAG := registry.baidubce.com/cce-plugin-$(PROFILES)/cce-cni
PUSH_CNI_IMAGE_FLAGS = --load --push
PUSH_CNI_IMAGE_FLAGS = --push

# make, make all
all: prepare compile
Expand Down Expand Up @@ -72,13 +72,15 @@ cni_target := eni-ipam ipvlan macvlan bandwidth ptp sysctl unnumbered-ptp crossv
$(cni_target): fmt outdir
@echo "===> Building cni $@ <==="
$(GOBUILD) $(GOLDFLAGS) $(GOGCFLAGS) -o $(HOMEDIR)/$@ $(HOMEDIR)/cni/$@
strip $(HOMEDIR)/$@
mv $(HOMEDIR)/$@ $(OUTDIR)/cni-bin/

# Compile all container network programs
exec_target := cce-ipam cni-node-agent ip-masq-agent
$(exec_target): fmt outdir
@echo "===> Building cni $@ <==="
$(GOBUILD) $(GOLDFLAGS) $(GOGCFLAGS) -ldflags '$(EXTRALDFLAGS)' -o $(HOMEDIR)/$@ $(HOMEDIR)/cmd/$@
strip $(HOMEDIR)/$@
mv $(HOMEDIR)/$@ $(OUTDIR)

#make compile
Expand Down
4 changes: 2 additions & 2 deletions build/images/cce-cni/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.baidubce.com/cce-plugin-pro/cce-cni-base:v1.0.0
FROM registry.baidubce.com/cce-plugin-pro/cce-cni-base:v1.0.0-slim

LABEL maintainer="Chen Yaqi<[email protected]>"

Expand All @@ -25,4 +25,4 @@ COPY output/ip-masq-agent /bin/cce-ip-masq-agent

COPY build/images/cce-cni/entrypoint.sh /entrypoint.sh

CMD ["/bin/bash", "/entrypoint.sh"]
CMD ["/bin/sh", "/entrypoint.sh"]
11 changes: 7 additions & 4 deletions build/images/cni-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM cce-cni-debian-iptables:v1.0.0
FROM alpine:3.18

LABEL maintainer="Chen Yaqi<[email protected]>"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk --no-cache add curl

# ensure cni bin from https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-${arch}-v1.0.1.tgz
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
curl -L -k --retry 5 https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-${arch}-v1.0.1.tgz | tar -xz -C / ./loopback ./host-local ./portmap ./bridge

# install entrypoint.sh and uninstall-cni.sh
COPY build/images/cce-cni/entrypoint.sh /entrypoint.sh
COPY build/images/cce-cni/uninstall-cni.sh /uninstall-cni.sh
COPY entrypoint.sh /entrypoint.sh
COPY uninstall-cni.sh /uninstall-cni.sh

CMD ["/bin/bash", "/entrypoint.sh"]
CMD ["/bin/sh", "/entrypoint.sh"]
2 changes: 1 addition & 1 deletion build/images/cni-base/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
set -u -e

CNI_BINARY_DIR=/opt/cni/bin/
Expand Down
64 changes: 52 additions & 12 deletions cni/eri/eri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,46 @@ import (

var (
stdinData = `
{
"cniVersion":"0.3.1",
"name":"cce-cni",
"type":"eri",
"ipam":{
"endpoint":"172.25.66.38:80"
}
}`
{
"cniVersion":"0.3.1",
"name":"cce-cni",
"type":"eri",
"ipam":{
"endpoint":"172.25.66.38:80"
},
"prevResult": {
"ips": [
{
"address": "10.1.0.5/16",
"gateway": "10.1.0.1",
"interface": 2
}
],
"routes": [
{
"dst": "0.0.0.0/0"
}
],
"interfaces": [
{
"name": "cni0",
"mac": "00:11:22:33:44:55"
},
{
"name": "veth3243",
"mac": "55:44:33:22:11:11"
},
{
"name": "eth0",
"mac": "00:11:22:33:44:66",
"sandbox": "/var/run/netns/blue"
}
],
"dns": {
"nameservers": [ "10.1.0.1" ]
}
}
}`
envArgs = `IgnoreUnknown=1;K8S_POD_NAMESPACE=default;K8S_POD_NAME=busybox;K8S_POD_INFRA_CONTAINER_ID=xxxxx`
)

Expand Down Expand Up @@ -100,7 +132,7 @@ func setupEnv(ctrl *gomock.Controller) (

func Test_cmdDel(t *testing.T) {
t.Log("test cmd del")

SetUPK8SClientEnv()
type fields struct {
ctrl *gomock.Controller
nlink netlinkwrapper.Interface
Expand Down Expand Up @@ -203,15 +235,23 @@ func Test_cmdDel(t *testing.T) {
StdinData: []byte(stdinData),
},
},
wantErr: true,
wantErr: false,
},
{
name: "异常流程2",
fields: func() fields {
ctrl := gomock.NewController(t)
nlink, ns, ipam, ip, types, netutil, rpc, grpc, sysctl := setupEnv(ctrl)

allocReply := rpcdef.ReleaseIPReply{
IsSuccess: true,
ErrMsg: "",
}
cniBackendClient := mockcbclient.NewMockCNIBackendClient(ctrl)
ns.EXPECT().WithNetNSPath(gomock.Any(), gomock.Any()).Return(errors.New("nspath error for cmd del unit testrelease"))
grpc.EXPECT().DialContext(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
rpc.EXPECT().NewCNIBackendClient(gomock.Any()).Return(cniBackendClient)
cniBackendClient.EXPECT().ReleaseIP(gomock.Any(), gomock.Any()).Return(&allocReply, errors.New("release ip error"))

return fields{
ctrl: ctrl,
Expand All @@ -236,7 +276,7 @@ func Test_cmdDel(t *testing.T) {
StdinData: []byte(stdinData),
},
},
wantErr: true,
wantErr: false,
},
{
name: "异常流程3",
Expand Down Expand Up @@ -277,7 +317,7 @@ func Test_cmdDel(t *testing.T) {
StdinData: []byte(stdinData),
},
},
wantErr: true,
wantErr: false,
},
}
for _, tt := range tests {
Expand Down
107 changes: 73 additions & 34 deletions cni/rdma/rdma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,8 @@ import (
"context"
"errors"
"net"
"os"
"path/filepath"
"testing"

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types/current"
"github.com/golang/mock/gomock"
"github.com/vishvananda/netlink"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
k8sfake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
"k8s.io/utils/exec"
utilexec "k8s.io/utils/exec"
fakeexec "k8s.io/utils/exec/testing"

"github.com/baidubce/baiducloud-cce-cni-driver/pkg/cni"
rpcdef "github.com/baidubce/baiducloud-cce-cni-driver/pkg/rpc"
mockcbclient "github.com/baidubce/baiducloud-cce-cni-driver/pkg/rpc/testing"
log "github.com/baidubce/baiducloud-cce-cni-driver/pkg/util/logger"
Expand All @@ -60,18 +43,63 @@ import (
mockrpc "github.com/baidubce/baiducloud-cce-cni-driver/pkg/wrapper/rpc/testing"
sysctlwrapper "github.com/baidubce/baiducloud-cce-cni-driver/pkg/wrapper/sysctl"
mocksysctl "github.com/baidubce/baiducloud-cce-cni-driver/pkg/wrapper/sysctl/testing"
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types/current"
"github.com/golang/mock/gomock"
"github.com/vishvananda/netlink"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
k8sfake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
"k8s.io/utils/exec"
utilexec "k8s.io/utils/exec"
fakeexec "k8s.io/utils/exec/testing"
)

var (
stdinData = `
{
"cniVersion":"0.3.1",
"name":"cce-cni",
"type":"rdma",
"ipam":{
"endpoint":"172.25.66.38:80"
}
}`
{
"cniVersion":"0.3.1",
"name":"cce-cni",
"type":"rdma",
"ipam":{
"endpoint":"172.25.66.38:80"
},
"prevResult": {
"ips": [
{
"address": "10.1.0.5/16",
"gateway": "10.1.0.1",
"interface": 2
}
],
"routes": [
{
"dst": "0.0.0.0/0"
}
],
"interfaces": [
{
"name": "cni0",
"mac": "00:11:22:33:44:55"
},
{
"name": "veth3243",
"mac": "55:44:33:22:11:11"
},
{
"name": "eth0",
"mac": "00:11:22:33:44:66",
"sandbox": "/var/run/netns/blue"
}
],
"dns": {
"nameservers": [ "10.1.0.1" ]
}
}
}`
envArgs = `IgnoreUnknown=1;K8S_POD_NAMESPACE=default;K8S_POD_NAME=busybox;K8S_POD_INFRA_CONTAINER_ID=xxxxx`
)

Expand Down Expand Up @@ -100,7 +128,7 @@ func setupEnv(ctrl *gomock.Controller) (

func Test_cmdDel(t *testing.T) {
t.Log("test cmd del")

SetUPK8SClientEnv()
type fields struct {
ctrl *gomock.Controller
nlink netlinkwrapper.Interface
Expand Down Expand Up @@ -203,15 +231,23 @@ func Test_cmdDel(t *testing.T) {
StdinData: []byte(stdinData),
},
},
wantErr: true,
wantErr: false,
},
{
name: "异常流程2",
fields: func() fields {
ctrl := gomock.NewController(t)
nlink, ns, ipam, ip, types, netutil, rpc, grpc, sysctl := setupEnv(ctrl)

allocReply := rpcdef.ReleaseIPReply{
IsSuccess: true,
ErrMsg: "",
}
cniBackendClient := mockcbclient.NewMockCNIBackendClient(ctrl)
ns.EXPECT().WithNetNSPath(gomock.Any(), gomock.Any()).Return(errors.New("nspath error for cmd del unit testrelease"))
grpc.EXPECT().DialContext(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
rpc.EXPECT().NewCNIBackendClient(gomock.Any()).Return(cniBackendClient)
cniBackendClient.EXPECT().ReleaseIP(gomock.Any(), gomock.Any()).Return(&allocReply, nil)

return fields{
ctrl: ctrl,
Expand All @@ -236,7 +272,7 @@ func Test_cmdDel(t *testing.T) {
StdinData: []byte(stdinData),
},
},
wantErr: true,
wantErr: false,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -559,9 +595,11 @@ func Test_rdmaPlugin_setupMacvlanNetworkInfo(t *testing.T) {
fakeCmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeAction{
func() ([]byte, []byte, error) { return []byte("ens11"), nil, nil },
func() ([]byte, []byte, error) { return []byte("ens12"), nil, nil },
},
RunScript: []fakeexec.FakeAction{
func() ([]byte, []byte, error) { return nil, nil, nil },
func() ([]byte, []byte, error) { return nil, nil, nil },
},
}
fakeExec := getFakeExecTemplate(&fakeCmd)
Expand All @@ -582,8 +620,8 @@ func Test_rdmaPlugin_setupMacvlanNetworkInfo(t *testing.T) {
nlink.EXPECT().LinkByName(gomock.Any()).Return(&netlink.Device{LinkAttrs: netlink.LinkAttrs{Name: "ens11"}}, nil).AnyTimes()
nlink.EXPECT().LinkSetUp(gomock.Any()).Return(nil)
nlink.EXPECT().AddrAdd(gomock.Any(), gomock.Any()).Return(nil)
nlink.EXPECT().RuleDel(gomock.Any()).Return(nil)
nlink.EXPECT().RuleAdd(gomock.Any()).Return(nil)
nlink.EXPECT().RuleDel(gomock.Any()).Return(nil).AnyTimes()
nlink.EXPECT().RuleAdd(gomock.Any()).Return(nil).AnyTimes()
netutil.EXPECT().InterfaceByName(gomock.Any()).Return(&net.Interface{}, nil)
netutil.EXPECT().GratuitousArpOverIface(gomock.Any(), gomock.Any()).Return(nil)

Expand Down Expand Up @@ -704,7 +742,7 @@ func Test_rdmaPlugin_setupMacvlanNetworkInfo(t *testing.T) {

grpc.EXPECT().DialContext(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()
rpc.EXPECT().NewCNIBackendClient(gomock.Any()).Return(cniBackendClient).AnyTimes()
cniBackendClient.EXPECT().AllocateIP(gomock.Any(), gomock.Any()).Return(&allocReply, errors.New("allocate ip error"))
cniBackendClient.EXPECT().AllocateIP(gomock.Any(), gomock.Any()).Return(&allocReply, errors.New("allocate ip error")).AnyTimes()
nlink.EXPECT().LinkByName(gomock.Any()).Return(&netlink.Device{LinkAttrs: netlink.LinkAttrs{Name: "ens11"}}, nil).AnyTimes()
nlink.EXPECT().LinkSetUp(gomock.Any()).Return(nil)

Expand Down Expand Up @@ -745,9 +783,11 @@ func Test_rdmaPlugin_setupMacvlanNetworkInfo(t *testing.T) {
fakeCmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeAction{
func() ([]byte, []byte, error) { return []byte("ens11"), nil, nil },
func() ([]byte, []byte, error) { return []byte("ens12"), nil, nil },
},
RunScript: []fakeexec.FakeAction{
func() ([]byte, []byte, error) { return nil, nil, nil },
func() ([]byte, []byte, error) { return nil, nil, nil },
},
}
fakeExec := getFakeExecTemplate(&fakeCmd)
Expand All @@ -773,8 +813,8 @@ func Test_rdmaPlugin_setupMacvlanNetworkInfo(t *testing.T) {
nlink.EXPECT().LinkByName(gomock.Any()).Return(&netlink.Device{LinkAttrs: netlink.LinkAttrs{Name: "ens11"}}, nil).AnyTimes()
nlink.EXPECT().LinkSetUp(gomock.Any()).Return(nil)
nlink.EXPECT().AddrAdd(gomock.Any(), gomock.Any()).Return(nil)
nlink.EXPECT().RuleDel(gomock.Any()).Return(nil)
nlink.EXPECT().RuleAdd(gomock.Any()).Return(nil)
nlink.EXPECT().RuleDel(gomock.Any()).Return(nil).AnyTimes()
nlink.EXPECT().RuleAdd(gomock.Any()).Return(nil).AnyTimes()
netutil.EXPECT().InterfaceByName(gomock.Any()).Return(&net.Interface{}, errors.New("get interface by name error"))
//netutil.EXPECT().GratuitousArpOverIface(gomock.Any(), gomock.Any()).Return(nil)

Expand Down Expand Up @@ -1182,7 +1222,6 @@ func Test_cmdCheck(t *testing.T) {

func TestNewRdmaPlugin(t *testing.T) {
t.Log("test cmd rdma plugin")
cni.InitFlags(filepath.Join(os.TempDir(), "rdma.log"))
p := newRdmaPlugin()
if p == nil {
t.Error("newRdmaPlugin returns nil")
Expand Down
Loading

0 comments on commit 5ab79ad

Please sign in to comment.