Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #4795

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

wip #4795

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions go-controller/pkg/kubevirt/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import (
"fmt"
"net"
"net/netip"

"github.com/mdlayher/ndp"
"golang.org/x/net/ipv6"

corev1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
utilnet "k8s.io/utils/net"

kubevirtv1 "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -258,3 +264,65 @@
// VM is ready to receive traffic
return targetNode == pod.Spec.NodeName || targetReadyTimestamp != "", nil
}

func FlushInvalidLayer2Gateways(watchFactory *factory.WatchFactory, pod *corev1.Pod, netInfo util.NetInfo, ifaceName string) error {
nodes, err := watchFactory.GetNodes()
if err != nil {
return err
}
for _, node := range nodes {
if node.Name == pod.Spec.NodeName {
continue
}
lrpAddress, err := util.ParseNodeGatewayRouterJoinNetwork(node, netInfo.GetNetworkName())
if err != nil {
return err
}
if lrpAddress.IPv6 == "" {
continue
}
podAnnotation, err := util.UnmarshalPodAnnotation(pod.Annotations, netInfo.GetNADs()[0])
if err != nil {
return err
}
//TODO: Support ipv6 single stack (mac is generated with ipv6)
// LRP's mac is calcualted from the join subnet IPv4
raSrcMAC := util.IPAddrToHWAddr(net.ParseIP(lrpAddress.IPv4))
raSrcIP := util.HWAddrToIPv6LLA(raSrcMAC)
raDstMAC := podAnnotation.MAC
raDstIP := util.HWAddrToIPv6LLA(raDstMAC)
raDstAddr, ok := netip.AddrFromSlice(raDstIP)
if !ok {
fmt.Errorf("bad RA destination ip: %s", raDstIP.String())

Check failure on line 296 in go-controller/pkg/kubevirt/router.go

View workflow job for this annotation

GitHub Actions / Lint

unusedresult: result of fmt.Errorf call not used (govet)
}
flushGatewayRA := ndp.RouterAdvertisement{
RouterLifetime: 0,
ReachableTime: 0,
RetransmitTimer: 0,
Options: []ndp.Option{
&ndp.LinkLayerAddress{
Direction: ndp.Source,
Addr: raSrcMAC,
},
&ndp.LinkLayerAddress{
Direction: ndp.Target,
Addr: raDstMAC,
},
},
}
iface, err := net.InterfaceByName(ifaceName)
if err != nil {
return err
}
klog.Infof("DELETEME, Sending RA to flush gateway %s", raSrcIP.String())
c, _, err := ndp.Listen(iface, ndp.LinkLocal)
if err != nil {
return err
}
defer c.Close()
if err := c.WriteTo(&flushGatewayRA, &ipv6.ControlMessage{Src: raSrcIP, Dst: raDstIP}, raDstAddr); err != nil {
return err
}
}
return nil
}
27 changes: 27 additions & 0 deletions go-controller/pkg/ovn/secondary_layer2_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/factory"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/generator/udn"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kubevirt"
libovsdbops "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/ops"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/metrics"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
Expand Down Expand Up @@ -178,6 +179,19 @@ func (h *secondaryLayer2NetworkControllerEventHandler) UpdateResource(oldObj, ne
} else {
return h.oc.addUpdateRemoteNodeEvent(newNode)
}
case factory.PodType:
if err := h.oc.UpdateSecondaryNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache); err != nil {
return err
}
newPod, ok := newObj.(*corev1.Pod)
if !ok {
return fmt.Errorf("could not cast %T object to Pod", newObj)
}
oldPod, ok := oldObj.(*kapi.Pod)
if !ok {
return fmt.Errorf("could not cast oldObj of type %T to *kapi.Pod", oldObj)
}
return h.oc.updatePod(newPod, oldPod)
default:
return h.oc.UpdateSecondaryNetworkResourceCommon(h.objType, oldObj, newObj, inRetryCache)
}
Expand Down Expand Up @@ -712,3 +726,16 @@ func (oc *SecondaryLayer2NetworkController) StartServiceController(wg *sync.Wait
}()
return nil
}

func (oc *SecondaryLayer2NetworkController) updatePod(oldPod, newPod *corev1.Pod) error {
if oc.IsPrimaryNetwork() && kubevirt.IsPodOwnedByVirtualMachine(newPod) && oc.isPodScheduledinLocalZone(newPod) {
networkID, err := oc.getNetworkID()
if err != nil {
return err
}
if err := kubevirt.FlushInvalidLayer2Gateways(oc.watchFactory, newPod, oc.NetInfo, util.GetNetworkScopedK8sMgmtHostIntfName(uint(networkID))); err != nil {
return err
}
}
return nil
}
4 changes: 4 additions & 0 deletions go-controller/vendor/golang.org/x/sys/unix/syscall_linux.go

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

3 changes: 3 additions & 0 deletions go-controller/vendor/golang.org/x/sys/unix/syscall_unix.go

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

Loading