Skip to content

Commit

Permalink
add ovs internal-port for pod network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 26, 2021
1 parent f748c74 commit 3473401
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon

if strings.HasSuffix(podRequest.Provider, util.OvnProvider) && subnet != "" {
klog.Infof("create container interface %s mac %s, ip %s, cidr %s, gw %s", ifName, macAddr, ipAddr, cidr, gw)
if nicType == util.VethType {
err = csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, ipAddr, gw, ingress, egress, vlanID, podRequest.DeviceID, nicType)
} else {
if nicType == util.InternalType {
err = csh.configureNicWithInternalPort(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, ipAddr, gw, ingress, egress, vlanID, podRequest.DeviceID, nicType)
} else {
err = csh.configureNic(podRequest.PodName, podRequest.PodNamespace, podRequest.Provider, podRequest.NetNs, podRequest.ContainerID, ifName, macAddr, ipAddr, gw, ingress, egress, vlanID, podRequest.DeviceID, nicType)
}
if err != nil {
errMsg := fmt.Errorf("configure nic failed %v", err)
Expand Down
32 changes: 17 additions & 15 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID, deviceID, ifName, nicType string) error {
var nicName string
hostNicName, containerNicName := generateNicName(containerID, ifName)
if nicType == util.VethType {
nicName = hostNicName
} else {

if nicType == util.InternalType {
nicName = containerNicName
} else {
nicName = hostNicName
}

// Remove ovs port
Expand Down Expand Up @@ -150,7 +151,8 @@ func configureContainerNic(nicName, ifName string, ipAddr, gateway string, macAd
}

return ns.WithNetNSPath(netns.Path(), func(_ ns.NetNS) error {
if nicType == util.VethType {

if nicType != util.InternalType {
if err = netlink.LinkSetName(containerLink, ifName); err != nil {
return err
}
Expand All @@ -171,18 +173,18 @@ func configureContainerNic(nicName, ifName string, ipAddr, gateway string, macAd
}
}

if nicType == util.VethType {
if err = configureNic(ifName, ipAddr, macAddr, mtu); err != nil {
if nicType == util.InternalType {
if err = configureNic(nicName, ipAddr, macAddr, mtu); err != nil {
return err
}
} else {
if err = configureNic(nicName, ipAddr, macAddr, mtu); err != nil {
if err = addAdditonalNic(ifName); err != nil {
return err
}
if err = addStaticEth0Nic(); err != nil {
if err = configureAdditonalNic(ifName, ipAddr); err != nil {
return err
}
if err = configureAdditonalNic("eth0", ipAddr); err != nil {
} else {
if err = configureNic(ifName, ipAddr, macAddr, mtu); err != nil {
return err
}
}
Expand Down Expand Up @@ -717,7 +719,7 @@ func (csh cniServerHandler) configureNicWithInternalPort(podName, podNamespace,
return fmt.Errorf("failed to parse mac %s %v", macAddr, err)
}

if err = ovs.SetInterfaceBandwidth(fmt.Sprintf("%s.%s", podName, podNamespace), ingress, egress); err != nil {
if err = ovs.SetInterfaceBandwidth(podName, podNamespace, ifaceID, ingress, egress); err != nil {
return err
}

Expand Down Expand Up @@ -781,19 +783,19 @@ func configureAdditonalNic(link, ip string) error {
return nil
}

func addStaticEth0Nic() error {
func addAdditonalNic(ifName string) error {
dummy := &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Name: "eth0",
Name: ifName,
},
}

if err := netlink.LinkAdd(dummy); err != nil {
if err := netlink.LinkDel(dummy); err != nil {
klog.Errorf("failed to delete eth0 %v", err)
klog.Errorf("failed to delete static iface %v, err %v", ifName, err)
return err
}
return fmt.Errorf("failed to crate static eth0 for %v", err)
return fmt.Errorf("failed to crate static iface %v, err %v", ifName, err)
}
return nil
}
8 changes: 6 additions & 2 deletions test/e2e/kubectl-ko/ko.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"

"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/kubeovn/kube-ovn/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -64,8 +65,11 @@ var _ = Describe("[kubectl-ko]", func() {
pods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{LabelSelector: " app=kube-ovn-pinger"})
Expect(err).NotTo(HaveOccurred())
pod := pods.Items[0]
output, err := exec.Command("kubectl", "ko", "tcpdump", fmt.Sprintf("kube-system/%s", pod.Name), "-c", "1").CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
nicType := pod.Annotations[util.PodNicAnnotation]
if nicType != util.InternalType {
output, err := exec.Command("kubectl", "ko", "tcpdump", fmt.Sprintf("kube-system/%s", pod.Name), "-c", "1").CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
}
})

It("trace", func() {
Expand Down

0 comments on commit 3473401

Please sign in to comment.