Skip to content

Commit

Permalink
Merge pull request kosmos-io#331 from wangyizhi1/release-0.2.0
Browse files Browse the repository at this point in the history
cherry-pick bug fixs to release-0.2.0
  • Loading branch information
kosmos-robot authored Dec 19, 2023
2 parents ac00d7e + 5de5438 commit 36cf8fb
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 83 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/bep/debounce v1.2.1
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.14
github.com/coreos/go-iptables v0.6.0
github.com/coreos/go-iptables v0.7.1-0.20231102141700-50d824baaa46
github.com/docker/docker v24.0.6+incompatible
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/go-logr/logr v1.2.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-iptables v0.6.0 h1:is9qnZMPYjLd8LYqmm/qlE+wwEgJIkTYdhV3rfZo4jk=
github.com/coreos/go-iptables v0.6.0/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
github.com/coreos/go-iptables v0.7.1-0.20231102141700-50d824baaa46 h1:AVVvARdGRuTtYO/DetrN9Z1G0kMbrqV7KLOH/J4byiM=
github.com/coreos/go-iptables v0.7.1-0.20231102141700-50d824baaa46/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down
86 changes: 21 additions & 65 deletions pkg/clusterlink/network/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
)

type IfaceInfo struct {
MTU int
name string
// index int
ip string
ip6 string
MTU int
name string
index int
ip string
ip6 string
}

func getIfaceIPByName(name string) (*IfaceInfo, error) {
Expand All @@ -35,6 +35,7 @@ func getIfaceIPByName(name string) (*IfaceInfo, error) {

devIface.MTU = iface.Attrs().MTU
devIface.name = iface.Attrs().Name
devIface.index = iface.Attrs().Index

addrListV4, err := getFristScopeIPInLink(iface, name, netlink.FAMILY_V4)
if err == nil {
Expand All @@ -52,7 +53,7 @@ func getIfaceIPByName(name string) (*IfaceInfo, error) {
return devIface, nil
}

func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int, vxlanPort int, hardwareAddr net.HardwareAddr, rIface *IfaceInfo, deviceIP string) error {
func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int, vxlanPort int, hardwareAddr net.HardwareAddr, rIface *IfaceInfo, deviceIP string, vtepDevIndex int) error {
// srcAddr := rIface.ip

klog.Infof("name %v ------------------------- %v", name, deviceIP)
Expand All @@ -63,10 +64,11 @@ func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int,
Flags: net.FlagUp,
HardwareAddr: hardwareAddr,
},
SrcAddr: net.ParseIP(deviceIP),
VxlanId: vxlanId,
Port: vxlanPort,
Learning: false,
SrcAddr: net.ParseIP(deviceIP),
VxlanId: vxlanId,
Port: vxlanPort,
Learning: false,
VtepDevIndex: vtepDevIndex,
}

err := netlink.LinkAdd(iface)
Expand Down Expand Up @@ -101,30 +103,6 @@ func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int,
return nil
}

func CIDRIPGenerator(ipcidr string, internalIP string) (*net.IP, error) {
cidrip, ipNet, err := net.ParseCIDR(ipcidr)
if err != nil {
return nil, fmt.Errorf("CIDRIPGenerator err: %v", err)
}

nodeIP := net.ParseIP(internalIP)

ret := net.ParseIP("0.0.0.0")
for i := range ipNet.Mask {
ret[len(ret)-i-1] = ^byte(ipNet.Mask[len(ipNet.Mask)-i-1])
}

for i := range nodeIP {
ret[i] = byte(ret[i]) & byte(nodeIP[i])
}

for i := range cidrip {
ret[i] = byte(ret[i]) | byte(cidrip[i])
}

return &ret, nil
}

// load device info from environment
func loadDevices() ([]clusterlinkv1alpha1.Device, error) {
ret := []clusterlinkv1alpha1.Device{}
Expand Down Expand Up @@ -179,39 +157,16 @@ func loadDevices() ([]clusterlinkv1alpha1.Device, error) {
continue
}

addrListAll, err := netlink.AddrList(nil, d.family)

if err != nil {
return nil, err
}

interfaceIndex := -1
vxlanIPAddr := vxlanNet.IP.String()

for _, r := range addrListAll {
if r.LinkIndex != vxlanIface.Attrs().Index {
if ip, err := CIDRIPGenerator(d.cidr, r.IP.String()); err == nil {
if ip.String() == vxlanIPAddr {
interfaceIndex = r.LinkIndex
break
}
}
}
}

interfaceIndex := vxlan.VtepDevIndex
bindDev := ""

if interfaceIndex == -1 {
klog.Warningf("can not find the phys_dev for vxlan, name: %s", d.name)
defaultIface, err := netlink.LinkByIndex(interfaceIndex)
if err != nil {
klog.Errorf("When we get device by linkinx, get error : %v", err)
ret = append(ret, createNoneDevice())
continue
} else {
defaultIface, err := netlink.LinkByIndex(interfaceIndex)
if err != nil {
klog.Errorf("When we get device by linkinx, get error : %v", err)
ret = append(ret, createNoneDevice())
continue
} else {
bindDev = defaultIface.Attrs().Name
}
bindDev = defaultIface.Attrs().Name
}

ret = append(ret, clusterlinkv1alpha1.Device{
Expand Down Expand Up @@ -262,8 +217,9 @@ func addDevice(d clusterlinkv1alpha1.Device) error {
deviceIP = currentIfaceInfo.ip6
family = netlink.FAMILY_V6
}
vtepDevIndex := currentIfaceInfo.index

if err = createNewVxlanIface(d.Name, addrIPvWithMask, id, port, hardwareAddr, currentIfaceInfo, deviceIP); err != nil {
if err = createNewVxlanIface(d.Name, addrIPvWithMask, id, port, hardwareAddr, currentIfaceInfo, deviceIP, vtepDevIndex); err != nil {
klog.Errorf("ipv4 err: %v", err)
return err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/clusterlink/network/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ limitations under the License.
package iptables

import (
"os"

"github.com/coreos/go-iptables/iptables"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -60,7 +62,8 @@ func New(proto iptables.Protocol) (Interface, error) {
return NewFunc()
}

ipt, err := iptables.New(iptables.IPFamily(proto), iptables.Timeout(5))
// IPTABLES_PATH: the path decision the model of iptable, /sbin/xtables-nft-multi => nf_tables
ipt, err := iptables.New(iptables.IPFamily(proto), iptables.Timeout(5), iptables.Path(os.Getenv("IPTABLES_PATH")))
if err != nil {
return nil, errors.Wrap(err, "error creating IP tables")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ func (r *RootPodReconciler) SetupWithManager(mgr manager.Manager) error {
return false
}

/**
p := obj.(*corev1.Pod)

// skip daemonset
Expand All @@ -249,11 +248,13 @@ func (r *RootPodReconciler) SetupWithManager(mgr manager.Manager) error {
return true
}
}
if !p.DeletionTimestamp.IsZero() {
return true
}
return false
}
}
}
*/
return true
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/clustertree/cluster-manager/utils/rootcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetAddress(ctx context.Context, rootClient kubernetes.Interface, originAddr
}

prefixAddress := []corev1.NodeAddress{
{Type: preferredAddressType, Address: os.Getenv("KNODE_POD_IP")},
{Type: preferredAddressType, Address: os.Getenv("LEAF_NODE_IP")},
}

address, err := SortAddress(ctx, rootClient, originAddress)
Expand Down
85 changes: 75 additions & 10 deletions vendor/github.com/coreos/go-iptables/iptables/iptables.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ github.com/containerd/ttrpc
# github.com/containerd/typeurl v1.0.2
## explicit; go 1.13
github.com/containerd/typeurl
# github.com/coreos/go-iptables v0.6.0
# github.com/coreos/go-iptables v0.7.1-0.20231102141700-50d824baaa46
## explicit; go 1.16
github.com/coreos/go-iptables/iptables
# github.com/coreos/go-semver v0.3.1
Expand Down

0 comments on commit 36cf8fb

Please sign in to comment.